Exclude std::any from implicit conversion (fixes #3428) (#3437)

* Exclude std::any from implicit conversion

Fixes #3428 (MSVC) and silences compiler warning on GCC (-Wconversion).

* Exclude std::any from implicit conversion
This commit is contained in:
Florian Albrechtskirchinger
2022-04-12 14:08:20 +02:00
committed by GitHub
parent 10344907ff
commit 1deeb434c6
3 changed files with 21 additions and 0 deletions

View File

@@ -43,6 +43,7 @@ using ordered_json = nlohmann::ordered_json;
#include <utility>
#ifdef JSON_HAS_CPP_17
#include <any>
#include <variant>
#endif
@@ -860,6 +861,18 @@ TEST_CASE("regression tests 2")
CHECK(obj.name == "class");
}
#endif
#if defined(JSON_HAS_CPP_17) && JSON_USE_IMPLICIT_CONVERSIONS
SECTION("issue #3428 - Error occurred when converting nlohmann::json to std::any")
{
json j;
std::any a1 = j;
std::any&& a2 = j;
CHECK(a1.type() == typeid(j));
CHECK(a2.type() == typeid(j));
}
#endif
}
DOCTEST_CLANG_SUPPRESS_WARNING_POP