From 8247a217bb9366c97ef0f31294cc7844537bcf50 Mon Sep 17 00:00:00 2001 From: Alexander Karzhenkov Date: Sat, 19 Dec 2020 17:23:58 +0500 Subject: [PATCH 1/5] Disrupt all C++17 tests to check if they are executed --- test/src/unit-conversions.cpp | 4 ++++ test/src/unit-items.cpp | 1 + test/src/unit-regression2.cpp | 1 + 3 files changed, 6 insertions(+) diff --git a/test/src/unit-conversions.cpp b/test/src/unit-conversions.cpp index c71e230d9..202619c4f 100644 --- a/test/src/unit-conversions.cpp +++ b/test/src/unit-conversions.cpp @@ -465,6 +465,7 @@ TEST_CASE("value conversion") #if defined(JSON_HAS_CPP_17) SECTION("std::string_view") { + static_assert(false); std::string_view s = j.get(); CHECK(json(s) == j); } @@ -514,6 +515,7 @@ TEST_CASE("value conversion") #if defined(JSON_HAS_CPP_17) SECTION("exception in case of a non-string type using string_view") { + static_assert(false); CHECK_THROWS_AS(json(json::value_t::null).get(), json::type_error&); CHECK_THROWS_AS(json(json::value_t::object).get(), json::type_error&); CHECK_THROWS_AS(json(json::value_t::array).get(), json::type_error&); @@ -561,6 +563,7 @@ TEST_CASE("value conversion") #if defined(JSON_HAS_CPP_17) SECTION("std::string_view") { + static_assert(false); std::string s = "previous value"; std::string_view sv = s; j.get_to(sv); @@ -617,6 +620,7 @@ TEST_CASE("value conversion") #if defined(JSON_HAS_CPP_17) SECTION("std::string_view") { + static_assert(false); std::string_view s = j.get(); CHECK(json(s) == j); } diff --git a/test/src/unit-items.cpp b/test/src/unit-items.cpp index 10621ce7e..9094c1a39 100644 --- a/test/src/unit-items.cpp +++ b/test/src/unit-items.cpp @@ -886,6 +886,7 @@ TEST_CASE("items()") #ifdef JSON_HAS_CPP_17 SECTION("structured bindings") { + static_assert(false); json j = { {"A", 1}, {"B", 2} }; std::map m; diff --git a/test/src/unit-regression2.cpp b/test/src/unit-regression2.cpp index ca50cdd41..18a78b092 100644 --- a/test/src/unit-regression2.cpp +++ b/test/src/unit-regression2.cpp @@ -250,6 +250,7 @@ TEST_CASE("regression tests 2") #ifdef JSON_HAS_CPP_17 SECTION("issue #1292 - Serializing std::variant causes stack overflow") { + static_assert(false); static_assert( !std::is_constructible>::value, ""); } From aae0e4959e973252d290ff3445dcf04bc9ea9303 Mon Sep 17 00:00:00 2001 From: Alexander Karzhenkov Date: Sun, 20 Dec 2020 10:18:41 +0500 Subject: [PATCH 2/5] Fix travis configuration to enable C++17 tests --- .travis.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index aef17a142..003d6a156 100644 --- a/.travis.yml +++ b/.travis.yml @@ -210,7 +210,7 @@ matrix: compiler: gcc env: - COMPILER=g++-9 - - CXXFLAGS=-std=c++2a + - CXX_STANDARD=17 addons: apt: sources: ['ubuntu-toolchain-r-test'] @@ -294,7 +294,7 @@ matrix: compiler: clang env: - COMPILER=clang++-7 - - CXXFLAGS=-std=c++1z + - CXX_STANDARD=17 addons: apt: sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-7'] @@ -321,6 +321,9 @@ script: # by default, use implicit conversions - if [[ "${IMPLICIT_CONVERSIONS}" == "" ]]; then export IMPLICIT_CONVERSIONS=ON; fi + # append CXX_STANDARD to CMAKE_OPTIONS if required + - CMAKE_OPTIONS+=${CXX_STANDARD:+ -DCMAKE_CXX_STANDARD=$CXX_STANDARD -DCMAKE_CXX_STANDARD_REQUIRED=ON} + # compile and execute unit tests - mkdir -p build && cd build - cmake .. ${CMAKE_OPTIONS} -DJSON_MultipleHeaders=${MULTIPLE_HEADERS} -DJSON_ImplicitConversions=${IMPLICIT_CONVERSIONS} -DJSON_BuildTests=On -GNinja && cmake --build . --config Release From 39b8d6bd335f1427d670b8368ac631758ee51664 Mon Sep 17 00:00:00 2001 From: Alexander Karzhenkov Date: Sun, 20 Dec 2020 12:43:35 +0500 Subject: [PATCH 3/5] Restore intentionally disrupted C++17 tests --- test/src/unit-conversions.cpp | 4 ---- test/src/unit-items.cpp | 1 - test/src/unit-regression2.cpp | 1 - 3 files changed, 6 deletions(-) diff --git a/test/src/unit-conversions.cpp b/test/src/unit-conversions.cpp index 202619c4f..c71e230d9 100644 --- a/test/src/unit-conversions.cpp +++ b/test/src/unit-conversions.cpp @@ -465,7 +465,6 @@ TEST_CASE("value conversion") #if defined(JSON_HAS_CPP_17) SECTION("std::string_view") { - static_assert(false); std::string_view s = j.get(); CHECK(json(s) == j); } @@ -515,7 +514,6 @@ TEST_CASE("value conversion") #if defined(JSON_HAS_CPP_17) SECTION("exception in case of a non-string type using string_view") { - static_assert(false); CHECK_THROWS_AS(json(json::value_t::null).get(), json::type_error&); CHECK_THROWS_AS(json(json::value_t::object).get(), json::type_error&); CHECK_THROWS_AS(json(json::value_t::array).get(), json::type_error&); @@ -563,7 +561,6 @@ TEST_CASE("value conversion") #if defined(JSON_HAS_CPP_17) SECTION("std::string_view") { - static_assert(false); std::string s = "previous value"; std::string_view sv = s; j.get_to(sv); @@ -620,7 +617,6 @@ TEST_CASE("value conversion") #if defined(JSON_HAS_CPP_17) SECTION("std::string_view") { - static_assert(false); std::string_view s = j.get(); CHECK(json(s) == j); } diff --git a/test/src/unit-items.cpp b/test/src/unit-items.cpp index 9094c1a39..10621ce7e 100644 --- a/test/src/unit-items.cpp +++ b/test/src/unit-items.cpp @@ -886,7 +886,6 @@ TEST_CASE("items()") #ifdef JSON_HAS_CPP_17 SECTION("structured bindings") { - static_assert(false); json j = { {"A", 1}, {"B", 2} }; std::map m; diff --git a/test/src/unit-regression2.cpp b/test/src/unit-regression2.cpp index 18a78b092..ca50cdd41 100644 --- a/test/src/unit-regression2.cpp +++ b/test/src/unit-regression2.cpp @@ -250,7 +250,6 @@ TEST_CASE("regression tests 2") #ifdef JSON_HAS_CPP_17 SECTION("issue #1292 - Serializing std::variant causes stack overflow") { - static_assert(false); static_assert( !std::is_constructible>::value, ""); } From cd7acc1dc5887aa254191d2103bbb2243f9c67ef Mon Sep 17 00:00:00 2001 From: Alexander Karzhenkov Date: Sun, 20 Dec 2020 19:40:36 +0500 Subject: [PATCH 4/5] Include in "nlohmann/json.hpp" when C++17 is used --- include/nlohmann/json.hpp | 4 ++++ single_include/nlohmann/json.hpp | 4 ++++ test/src/unit-conversions.cpp | 4 ---- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index a726d1adf..8c9bef03d 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -73,6 +73,10 @@ SOFTWARE. #include #include +#if defined(JSON_HAS_CPP_17) + #include +#endif + /*! @brief namespace for Niels Lohmann @see https://github.com/nlohmann diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 88c8fa74d..9e6f6012d 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -16663,6 +16663,10 @@ template , } // namespace nlohmann +#if defined(JSON_HAS_CPP_17) + #include +#endif + /*! @brief namespace for Niels Lohmann @see https://github.com/nlohmann diff --git a/test/src/unit-conversions.cpp b/test/src/unit-conversions.cpp index c71e230d9..16c4f798e 100644 --- a/test/src/unit-conversions.cpp +++ b/test/src/unit-conversions.cpp @@ -48,10 +48,6 @@ using nlohmann::json; #define JSON_HAS_CPP_14 #endif -#if defined(JSON_HAS_CPP_17) - #include -#endif - TEST_CASE("value conversion") { SECTION("get an object (explicit)") From 9493f4beb10da58500d3c8cf8133c38c75e4e7fe Mon Sep 17 00:00:00 2001 From: Alexander Karzhenkov Date: Sun, 20 Dec 2020 23:50:28 +0500 Subject: [PATCH 5/5] Advance gcc library version for clang++-7 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 003d6a156..f48ee1fd6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -298,7 +298,7 @@ matrix: addons: apt: sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-7'] - packages: ['g++-6', 'clang-7', 'ninja-build'] + packages: ['g++-7', 'clang-7', 'ninja-build'] ################ # build script #