Say I have this class:
class [[nodiscard]] MyClass
{
public:
MyClass() : _x(x) {}
MyClass(int x) : _x(x) {}
private:
int _x;
};
Does adding the [[nodiscard]]
tag individually to the class's constructors change anything? Or is that wholly redundant with the [[nodiscard]]
tag applied to the class declaration itself, and therefore only adds unnecessary noise to the header file?
(My testing suggests the later, but I might be missing some nuance)
Marking the individual constructors as [[nodiscard]]
is completely redundant and unnecessary if the class as a whole is marked as [[nodiscard]]
.