[Bug c++/95454] type-level nodiscard not applied to constructors
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95454 Eric Estievenart changed: What|Removed |Added CC||steve+gcc at tecwec dot eu --- Comment #1 from Eric Estievenart --- Indeed, confirming with even simpler code ( https://godbolt.org/z/EPbsfxYcj ): struct [[nodiscard]] Z {}; void f() { Z{}; // should warn but does not } Tested all versions: 11.2, trunk, with -Wall -Wextra - This is really a need for modern code, even experienced developpers sometimes forget the 'lock' in Lock lock{&mutex}; and this has severe consequences ;-)
[Bug c++/95454] type-level nodiscard not applied to constructors
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95454 Kyrylo Bohdanenko changed: What|Removed |Added CC||kyrylo.bohdanenko at gmail dot com --- Comment #2 from Kyrylo Bohdanenko --- Still relevant as of the current trunk. A workaround would be to declare the constructor(s) [[nodiscard]]: struct Data { [[nodiscard]] Data() {} }; int main() { Data{}; } This actually issues a warning: : In function 'int main()': :6:11: warning: ignoring return value of 'Data::Data()', declared with attribute 'nodiscard' [-Wunused-result] Sandbox: https://godbolt.org/z/3Koj8rra7
[Bug c++/95454] type-level nodiscard not applied to constructors
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95454 --- Comment #3 from Johel Ernesto Guerrero Peña --- > A workaround would be to declare the constructor(s) [[nodiscard]]: That's generally a [better recommendation](https://github.com/mpusz/units/issues/136). Though I think you'd have to `= default` SMFs to get the same effects as the type-level annotation.
[Bug c++/95454] type-level nodiscard not applied to constructors
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95454 Andrew Pinski changed: What|Removed |Added Resolution|--- |DUPLICATE Status|UNCONFIRMED |RESOLVED --- Comment #4 from Andrew Pinski --- Dup of bug 85973. *** This bug has been marked as a duplicate of bug 85973 ***