diff --git a/include/nlohmann/detail/exceptions.hpp b/include/nlohmann/detail/exceptions.hpp index 56451638de..4d61de4022 100644 --- a/include/nlohmann/detail/exceptions.hpp +++ b/include/nlohmann/detail/exceptions.hpp @@ -104,11 +104,12 @@ class exception : public std::exception return ""; } - return concat('(', std::accumulate(tokens.rbegin(), tokens.rend(), std::string{}, - [](const std::string & a, const std::string & b) + auto str = std::accumulate(tokens.rbegin(), tokens.rend(), std::string{}, + [](const std::string & a, const std::string & b) { return concat(a, '/', detail::escape(b)); - }), ") "); + }); + return concat('(', str, ") "); #else static_cast(leaf_element); return ""; diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index f9a7cd3cac..eb4b0a6cbc 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -3840,11 +3840,12 @@ class exception : public std::exception return ""; } - return concat('(', std::accumulate(tokens.rbegin(), tokens.rend(), std::string{}, - [](const std::string & a, const std::string & b) + auto str = std::accumulate(tokens.rbegin(), tokens.rend(), std::string{}, + [](const std::string & a, const std::string & b) { return concat(a, '/', detail::escape(b)); - }), ") "); + }); + return concat('(', str, ") "); #else static_cast(leaf_element); return "";