Compare commits

..
Author SHA1 Message Date
Niels Lohmann 402af742c0 Fix the VS2015 build of unit-json_view_edit_values.cpp
MSVC 2015 treats two function templates that differ only in a decltype
return type as a redefinition (C2995), which breaks all three Visual
Studio 2015 jobs on AppVeyor. Overload on the view's mode in the
parameter type instead; template argument deduction ignores the
read-only-to-editable conversion, so each view still selects the
overload of its own mode.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-10-27 18:01:12 +01:00
2 changed files with 10 additions and 9 deletions

No files matched your search

+8 -4
View File
@@ -54,14 +54,18 @@ int accepts_any(nlohmann::basic_json_view<BasicJsonType, Mode> /*unused*/)
return Mode == nlohmann::view_mode::editable ? 3 : 4;
}
template<typename View>
auto overload(View v) -> decltype(accepts_editable(v))
// overloads that differ only in the mode; deduction ignores the conversion from
// read-only to editable views, so each view picks the overload of its own mode
// (two templates that differ only in a decltype return type are a redefinition
// for MSVC 2015)
template<typename BasicJsonType>
int overload(nlohmann::basic_json_view<BasicJsonType, nlohmann::view_mode::editable> v)
{
return accepts_editable(v);
}
template<typename View>
auto overload(View v) -> decltype(accepts_read_only(v))
template<typename BasicJsonType>
int overload(nlohmann::basic_json_view<BasicJsonType, nlohmann::view_mode::read_only> v)
{
return accepts_read_only(v);
}
+2 -5
View File
@@ -1504,16 +1504,13 @@ TEST_CASE("regression tests 1")
// a copied fifo_map restarts its timestamps, so a new key "k" gets
// the timestamp of "x": the lookup does not find "k", but emplace()
// finds "x" and inserts nothing; the pointer then continues with the
// member of "x", as basic_json::operator[] does. The object_t is
// copied explicitly: copying the my_json would build the object
// member by member (with fresh timestamps) when built with
// JSON_NO_THREAD_LOCAL.
// member of "x", as basic_json::operator[] does
const my_json orig = my_json::parse(R"({"x":1})");
const std::array<const char*, 3> pointers = {{"/k/0", "/k/a/b", "/k/-"}};
for (const char* pointer : pointers)
{
CAPTURE(pointer)
my_json j(orig.get_ref<const my_json::object_t&>());
my_json j = orig;
CHECK_THROWS_AS(j[my_json::json_pointer(pointer)], my_json::out_of_range&);
CHECK(j.dump() == R"({"x":1})");
}