Isn't it better to just write
(void) x;
instead of including a whole header file:
#include
On Sat, Apr 16, 2022 at 10:57 AM Vinnie Falco wrote:
Isn't it better to just write (void) x;
Doesn't always work. For example: https://godbolt.org/z/3zn11ErKG Compare to use of boost::ignore_used: https://godbolt.org/z/Maf4KcPeo See also Herb's comment: https://herbsutter.com/2009/10/18/mailbag-shutting-up-compiler-warnings/#com... For those rare users that can afford to target C++17 or higher, they have [[maybe_unused]] Glen Glen
instead of including a whole header file:
#include
just to write
boost::ignore_unused( x );
?
-- Regards, Vinnie
Follow me on GitHub: https://github.com/vinniefalco
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
On 17/04/2022 03:59, Glen Fernandes wrote:
Doesn't always work. For example: https://godbolt.org/z/3zn11ErKG
That's not really a common usage pattern, though, unless there are some conditional compilation constructs (#if or assert) involved; you just wouldn't assign it to a variable in the first place. Typically `(void) x` is only used for parameters, and `(void) f()` for method calls (although most compilers will not complain by default about discarded return values, though that can usually be enabled).
For those rare users that can afford to target C++17 or higher, they have [[maybe_unused]]
That attribute name irks me. [[may_be_unused]] would have been better, or just [[unused]] (to save typing). "May be unused" denotes permission, while "maybe unused" denotes uncertainty. And you shouldn't be uncertain about your code. Also compare with [[nodiscard]] (and as always, C++ having the opposite default of the correct one, due to backwards compatibility).
participants (4)
-
Gavin Lambert
-
Glen Fernandes
-
Michael Caisse
-
Vinnie Falco