-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Open
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerconfirmedVerified by a second partyVerified by a second party
Description
This probably effects a lot of code that uses trailing return type syntax.
To make it easily reproducible, I looked at this use case:
const int &return_const_ref(); // expected-note{{function 'return_const_ref' which returns const-qualified type 'const int &' declared here}} |
With trailing return type it generates the note without a location.
Not using trailing return types (conventional prefix syntax):
const int& good();
void test_good() { good() = 10; }
Diagnoses with
<source>:2:27: error: cannot assign to return value because function 'good' returns a const value
2 | void test_good() { good() = 10; }
| ~~~~~~ ^
<source>:1:7: note: function 'good' which returns const-qualified type 'const int &' declared here
1 | const int& good();
| ^~~~
1 error generated.
Compiler returned: 1
However, using trailing return types:
auto bad() -> const int&;
void test_bad() { bad() = 10; }
Diagnoses with
<source>:2:25: error: cannot assign to return value because function 'bad' returns a const value
2 | void test_bad() { bad() = 10; }
| ~~~~~ ^
note: function 'bad' which returns const-qualified type 'const int &' declared here
1 error generated.
Compiler returned: 1
Metadata
Metadata
Assignees
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerconfirmedVerified by a second partyVerified by a second party