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

johelegp at gmail dot com gcc-bugzilla@gcc.gnu.org
Sun May 31 17:53:20 GMT 2020


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

            Bug ID: 95454
           Summary: type-level nodiscard not applied to constructors
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: johelegp at gmail dot com
  Target Milestone: ---

The following does not warn for constructors. See https://godbolt.org/z/BTZwew.
```C++
struct [[nodiscard]] X {
    int x;
    X operator+() const { return *this; }
};
class [[nodiscard]] Y {
    int y;
public:
    Y operator+() const { return *this; }
};
void f()
{
    X{};
    Y{};
    X x;
    +x;
    Y y;
    +y;
}
```


More information about the Gcc-bugs mailing list