json_view: return the empty context so clang can elide its copy

clang 22 with -Weverything (ci_test_standards_clang) reports -Wnrvo for
'return context;' in diagnostics(), because the early 'return "";' after
context is declared rules out the named return value optimization. context is
still empty there, so return it instead.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann committed 2026-10-31 23:34:30 +01:00
1 parent 8dd6c6aca1
commit fb6a315746
2 files changed
+4 -2

No files matched your search

+2 -1
View File
@@ -4765,7 +4765,8 @@ std::string diagnostics(const error_site site)
const bool found = edited ? value_path<true>(d, site.value(), tokens) : value_path<false>(d, site.value(), tokens);
if (!found || tokens.empty())
{
return "";
// context is still empty; returning it keeps the copy elided (-Wnrvo)
return context;
}
std::string path;
for (const std::string& token : tokens)