-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Open
Labels
c++clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"missed-optimization
Description
#include <string>
std::string f(int maxsize)
{
std::string ret;
for (int i = 0; ; ++i)
{
if (i > maxsize)
return "";
ret += ".";
}
return ret;
}
<source>:12:12: warning: not eliding copy on return [-Wnrvo]
12 | return ret;
| ^
https://godbolt.org/z/fPfEGMh7E
Clearing ret
and returning it addresses the warning but feels a bit awkward.
This also occurs without the loop but such a case can easily be mitigated without uglifying the code.
Metadata
Metadata
Assignees
Labels
c++clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"missed-optimization