[llvm] [NFC][CodingStandard] Deprecate use of void casts to suppress warnings (PR #142850)
Chris Jackson via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 6 06:51:09 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);
----------------
chrisjbris wrote:
I think it might be worth mentioning the exceptions to the rule where the C-style is preferred for .c.
https://github.com/llvm/llvm-project/pull/142850
More information about the llvm-commits
mailing list