C++ nodiscard attribute
C++17
and
C23
added the [[nodiscard]] attribute to indicate that the result of a function call should not be ignored.
Use care not to overspecify [[nodiscard]] on functions that are not intended to be used in a way that requires the result to be used, as this can make
nuisance warnings.
Example: annotate function declaration in the header file with [[nodiscard]] attribute.
[[nodiscard]] int one();int one() { return 1; }