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;
}
```