From 751b93652ff64421670310049e16d40549557d77 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 15 Apr 2024 21:44:33 +0200 Subject: [PATCH] :rotating_light: fix warning --- include/nlohmann/json.hpp | 2 +- tests/src/unit-element_access2.cpp | 4 ++-- tests/src/unit-udt_macro.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index dcfd0a870..ec208f916 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -2048,7 +2048,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec auto it = m_data.m_value.object->find(std::forward(key)); if (it == m_data.m_value.object->end()) { - JSON_THROW(out_of_range::create(403, detail::concat("key '", string_t(std::forward(key)), "' not found"), this)); + JSON_THROW(out_of_range::create(403, "key not found (key is an rvalue and cannot be shown)", this)); } return it->second; } diff --git a/tests/src/unit-element_access2.cpp b/tests/src/unit-element_access2.cpp index 622d51c52..ae6ba955e 100644 --- a/tests/src/unit-element_access2.cpp +++ b/tests/src/unit-element_access2.cpp @@ -70,11 +70,11 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j SECTION("access outside bounds") { CHECK_THROWS_WITH_AS(j.at("foo"), "[json.exception.out_of_range.403] key not found (key is an rvalue and cannot be shown)", typename Json::out_of_range&); - CHECK_THROWS_WITH_AS(j_const.at("foo"), "[json.exception.out_of_range.403] key 'foo' not found", typename Json::out_of_range&); + CHECK_THROWS_WITH_AS(j_const.at("foo"), "[json.exception.out_of_range.403] key not found (key is an rvalue and cannot be shown)", typename Json::out_of_range&); #ifdef JSON_HAS_CPP_17 CHECK_THROWS_WITH_AS(j.at(std::string_view("foo")), "[json.exception.out_of_range.403] key not found (key is an rvalue and cannot be shown)", typename Json::out_of_range&); - CHECK_THROWS_WITH_AS(j_const.at(std::string_view("foo")), "[json.exception.out_of_range.403] key 'foo' not found", typename Json::out_of_range&); + CHECK_THROWS_WITH_AS(j_const.at(std::string_view("foo")), "[json.exception.out_of_range.403] key not found (key is an rvalue and cannot be shown)", typename Json::out_of_range&); #endif } diff --git a/tests/src/unit-udt_macro.cpp b/tests/src/unit-udt_macro.cpp index 04631a4dc..310fe068e 100644 --- a/tests/src/unit-udt_macro.cpp +++ b/tests/src/unit-udt_macro.cpp @@ -341,7 +341,7 @@ TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRU // check exception in case of missing field json j = json(p1); j.erase("age"); - CHECK_THROWS_WITH_AS(j.get(), "[json.exception.out_of_range.403] key 'age' not found", json::out_of_range); + CHECK_THROWS_WITH_AS(j.get(), "[json.exception.out_of_range.403] key not found (key is an rvalue and cannot be shown)", json::out_of_range); } }