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:
2 files changed
+4
-2
No files matched your search
@@ -259,7 +259,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);
|
const bool found = edited ? value_path<true>(d, site.value(), tokens) : value_path<false>(d, site.value(), tokens);
|
||||||
if (!found || tokens.empty())
|
if (!found || tokens.empty())
|
||||||
{
|
{
|
||||||
return "";
|
// context is still empty; returning it keeps the copy elided (-Wnrvo)
|
||||||
|
return context;
|
||||||
}
|
}
|
||||||
std::string path;
|
std::string path;
|
||||||
for (const std::string& token : tokens)
|
for (const std::string& token : tokens)
|
||||||
|
|||||||
Generated
+2
-1
@@ -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);
|
const bool found = edited ? value_path<true>(d, site.value(), tokens) : value_path<false>(d, site.value(), tokens);
|
||||||
if (!found || tokens.empty())
|
if (!found || tokens.empty())
|
||||||
{
|
{
|
||||||
return "";
|
// context is still empty; returning it keeps the copy elided (-Wnrvo)
|
||||||
|
return context;
|
||||||
}
|
}
|
||||||
std::string path;
|
std::string path;
|
||||||
for (const std::string& token : tokens)
|
for (const std::string& token : tokens)
|
||||||
|
|||||||
Reference in new issue
Block a user