diff --git a/appveyor.yml b/appveyor.yml index b04ac24f2..0a7de686d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -66,15 +66,15 @@ before_build: - cmake . -G "%GENERATOR%" -A "%GENERATOR_PLATFORM%" -DCMAKE_CXX_FLAGS="%CXX_FLAGS%" -DCMAKE_IGNORE_PATH="C:/Program Files/Git/usr/bin" -DJSON_BuildTests=On "%CMAKE_OPTIONS%" build_script: - - cmake --build . --config "%configuration%" + - cmake --build . --config "%configuration%" --parallel 2 test_script: - - if "%configuration%"=="Release" ctest -C "%configuration%" -V -j + - if "%configuration%"=="Release" ctest -C "%configuration%" --parallel 2 --output-on-failure # On Debug builds, skip test-unicode_all # as it is extremely slow to run and cause # occasional timeouts on AppVeyor. # More info: https://github.com/nlohmann/json/pull/1570 - - if "%configuration%"=="Debug" ctest --exclude-regex "test-unicode" -C "%configuration%" -V -j + - if "%configuration%"=="Debug" ctest --exclude-regex "test-unicode" -C "%configuration%" --parallel 2 --output-on-failure # only build PRs and commits to develop branch # (see https://help.appveyor.com/discussions/questions/55079-two-builds-per-commit-to-pull-request) diff --git a/doc/mkdocs/docs/features/macros.md b/doc/mkdocs/docs/features/macros.md index 9994c5dcd..dabb29917 100644 --- a/doc/mkdocs/docs/features/macros.md +++ b/doc/mkdocs/docs/features/macros.md @@ -125,6 +125,19 @@ security reasons (e.g., Intel Software Guard Extensions (SGX)). #undef JSON_NO_IO ``` +## `JSON_SKIP_LIBRARY_VERSION_CHECK` + +When defined, the library will not create a compiler warning when a different version of the library was already +included. + +!!! info "Default behavior" + + By default, the macro is not defined. + + ```cpp + #undef JSON_SKIP_LIBRARY_VERSION_CHECK + ``` + ## `JSON_SKIP_UNSUPPORTED_COMPILER_CHECK` When defined, the library will not create a compile error when a known unsupported compiler is detected. This allows to diff --git a/include/nlohmann/detail/conversions/from_json.hpp b/include/nlohmann/detail/conversions/from_json.hpp index fbb176879..207d3e302 100644 --- a/include/nlohmann/detail/conversions/from_json.hpp +++ b/include/nlohmann/detail/conversions/from_json.hpp @@ -464,8 +464,7 @@ void from_json(const BasicJsonType& j, std_fs::path& p) { if (JSON_HEDLEY_UNLIKELY(!j.is_string())) { - // Not tested because of #3377 (related #3070) - JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()), j)); // LCOV_EXCL_LINE + JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()), j)); } p = *j.template get_ptr(); } diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 496007c0d..0c3c39065 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -39,6 +39,14 @@ SOFTWARE. #ifndef INCLUDE_NLOHMANN_JSON_HPP_ #define INCLUDE_NLOHMANN_JSON_HPP_ +#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK + #if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH) + #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 10 || NLOHMANN_JSON_VERSION_PATCH != 5 + #warning "Already included a different version of the library!" + #endif + #endif +#endif + #define NLOHMANN_JSON_VERSION_MAJOR 3 #define NLOHMANN_JSON_VERSION_MINOR 10 #define NLOHMANN_JSON_VERSION_PATCH 5 diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 33a91164c..ed2a9cf2c 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -39,6 +39,14 @@ SOFTWARE. #ifndef INCLUDE_NLOHMANN_JSON_HPP_ #define INCLUDE_NLOHMANN_JSON_HPP_ +#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK + #if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH) + #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 10 || NLOHMANN_JSON_VERSION_PATCH != 5 + #warning "Already included a different version of the library!" + #endif + #endif +#endif + #define NLOHMANN_JSON_VERSION_MAJOR 3 #define NLOHMANN_JSON_VERSION_MINOR 10 #define NLOHMANN_JSON_VERSION_PATCH 5 @@ -4279,8 +4287,7 @@ void from_json(const BasicJsonType& j, std_fs::path& p) { if (JSON_HEDLEY_UNLIKELY(!j.is_string())) { - // Not tested because of #3377 (related #3070) - JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()), j)); // LCOV_EXCL_LINE + JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()), j)); } p = *j.template get_ptr(); } diff --git a/test/src/unit-regression2.cpp b/test/src/unit-regression2.cpp index b8cc5107b..dd2edb4ff 100644 --- a/test/src/unit-regression2.cpp +++ b/test/src/unit-regression2.cpp @@ -748,8 +748,10 @@ TEST_CASE("regression tests 2") const auto j_path = j.get(); CHECK(j_path == text_path); - // Disabled pending resolution of #3377 - // CHECK_THROWS_WITH_AS(nlohmann::detail::std_fs::path(json(1)), "[json.exception.type_error.302] type must be string, but is number", json::type_error); +#ifndef _MSC_VER + // works everywhere but on MSVC + CHECK_THROWS_WITH_AS(nlohmann::detail::std_fs::path(json(1)), "[json.exception.type_error.302] type must be string, but is number", json::type_error); +#endif } #endif diff --git a/third_party/amalgamate/amalgamate.py b/third_party/amalgamate/amalgamate.py index f01b43b76..0aed7c901 100755 --- a/third_party/amalgamate/amalgamate.py +++ b/third_party/amalgamate/amalgamate.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # coding=utf-8 # amalgamate.py - Amalgamate C source and header files.