[Bug c++/95454] type-level nodiscard not applied to constructors

steve+gcc at tecwec dot eu gcc-bugzilla@gcc.gnu.org
Thu Dec 30 16:31:48 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95454

Eric Estievenart <steve+gcc at tecwec dot eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |steve+gcc at tecwec dot eu

--- Comment #1 from Eric Estievenart <steve+gcc at tecwec dot eu> ---
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 ;-)


More information about the Gcc-bugs mailing list