[[nodiscard]] is C++17 attribute, which was extended in C++20; its purpose is to warn about discarded return value. Tag questions directly related to usage of this attribute and entities marked with this attribute.
Starting in C++17 [[nodiscard]]
encourages the compiler to emit a warning when the return value of a function is discarded. It can be applied to a function, or a type.
There's a defect report that makes [[nodiscard]]
work with constructors too, and it is incorporated in C++20.
Starting in C++20, nodiscard can provide a message: [[nodiscard("message")]]
To suppress the warning, cast the result to void
; see How can I intentionally discard a [[nodiscard]] return value?