Search⌘ K

How to Ignore [[nodiscard]]

Explore different methods to suppress compiler warnings when ignoring [[nodiscard]] return values in C++17. Understand how to use attributes like [[maybe_unused]], cast function calls to void, or create wrapper functions, while recognizing the importance of following best practices with code contracts in modern C++.

​With [[nodiscard]] you should use the returned value - by assigning it to a variable or by using it directly. If you forget, you’ll get an “unused variable” warning.

With an Attribute

There are situations where you might want to suppress such a warning. To do that you can ...