How to Ignore [[nodiscard]]
In some circumstances, you may not want the [[nodiscard]] functionality. There are methods of ignoring its warnings. We'll discuss them below.
We'll cover the following
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 use
another attribute from C++17: [[maybe_unused]]
:
Get hands-on with 1400+ tech skills courses.