[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)
Yihe Li via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 16 12:23:09 PDT 2024
================
@@ -115,20 +115,20 @@ void usage() {
S('A'); // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute: Don't let that S-Char go!}}
S(1);
S(2.2);
- Y(); // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute: Don't throw me away either!}}
+ Y(); // expected-warning {{ignoring temporary of type 'Y' declared with 'nodiscard' attribute: Don't throw me away either!}}
S s;
- ConvertTo{}; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute: Don't throw me away!}}
+ ConvertTo{}; // expected-warning {{ignoring return value of type 'ConvertTo' declared with 'nodiscard' attribute: Don't throw me away!}}
----------------
Mick235711 wrote:
Yeah, definitely because of that, since the following also gives two different warnings ([CE](https://godbolt.org/z/rPb5jaY1x)):
```cpp
struct [[nodiscard]] A {};
void use()
{
A();
A{};
}
```
This probably is not intended (I hope), but I'm not familiar enough with related infrastructure to suggest a fix. Either way, that is not in the scope of this PR.
https://github.com/llvm/llvm-project/pull/112521
More information about the cfe-commits
mailing list