From bb2468a52ca9747bf720bbbc33a7ce6bf6e32bfc Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 15 Apr 2024 21:16:40 +0200 Subject: [PATCH] :rotating_light: fix warning --- include/nlohmann/json.hpp | 2 +- single_include/nlohmann/json.hpp | 2 +- tests/src/unit-diagnostics.cpp | 2 +- tests/src/unit-element_access2.cpp | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 8e8f81da4..dcfd0a870 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -2010,7 +2010,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 set_parent(it->second); } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index a3203d8f9..65c9e841a 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -21332,7 +21332,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 set_parent(it->second); } diff --git a/tests/src/unit-diagnostics.cpp b/tests/src/unit-diagnostics.cpp index 0e172b915..483f96e73 100644 --- a/tests/src/unit-diagnostics.cpp +++ b/tests/src/unit-diagnostics.cpp @@ -39,7 +39,7 @@ TEST_CASE("Better diagnostics") { json j; j["object"]["object"] = true; - CHECK_THROWS_WITH_AS(j["object"].at("not_found"), "[json.exception.out_of_range.403] (/object) key 'not_found' not found", json::out_of_range); + CHECK_THROWS_WITH_AS(j["object"].at("not_found"), "[json.exception.out_of_range.403] (/object) key not found (key is an rvalue and cannot be shown)", json::out_of_range); } SECTION("array index out of range") diff --git a/tests/src/unit-element_access2.cpp b/tests/src/unit-element_access2.cpp index 8497fb944..622d51c52 100644 --- a/tests/src/unit-element_access2.cpp +++ b/tests/src/unit-element_access2.cpp @@ -69,11 +69,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 'foo' not found", typename Json::out_of_range&); + 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&); #ifdef JSON_HAS_CPP_17 - CHECK_THROWS_WITH_AS(j.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.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&); #endif }