Attribute: nodiscard since C++17¶
nodiscard
is a attribute introduced by c++17. If a function
- declared nodiscard or
- returning an enumeration or class declared nodiscard by value
the compiler will issue a warning when the function is called from a discarded-value expression other than a cast to void.
Here is a example:
[[nodiscard]] int foo()
{
return 7;
}
foo(); // warning: ignoring return value of function declared with 'nodiscard' attribute
int bar = foo(); // no warning
static_cast<void>(foo()); // no warning