[llvm] [NFC][CodingStandard] Deprecate use of void casts to suppress warnings (PR #142850)

Rahul Joshi via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 4 13:49:48 PDT 2025


================
@@ -1288,15 +1285,15 @@ These are two interesting different cases. In the first case, the call to
 ``V.size()`` is only useful for the assert, and we don't want it executed when
 assertions are disabled.  Code like this should move the call into the assert
 itself.  In the second case, the side effects of the call must happen whether
-the assert is enabled or not.  In this case, the value should be cast to void to
-disable the warning.  To be specific, it is preferred to write the code like
-this:
+the assert is enabled or not. In this case, the value should be defined using
+the ``[[maybe_unused]]`` attribute to disable the warning. To be specific, it is
+preferred to write the code like this:
 
 .. code-block:: c++
 
   assert(V.size() > 42 && "Vector smaller than it should be");
 
-  bool NewToSet = Myset.insert(Value); (void)NewToSet;
+  [[maybe_unused]] bool NewToSet = Myset.insert(Value);
----------------
jurahul wrote:

I am wondering if we should explicitly say that in C code, using void cast is allowed to suppress warnings and add a C example (this one is not since it's using a member function call).

https://github.com/llvm/llvm-project/pull/142850


More information about the llvm-commits mailing list