[llvm] [NFC][CodingStandard] Prefer ``[[maybe_unused]]`` over C-style void cast for unused variables (PR #142850)

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 19 00:21:52 PDT 2025


================
@@ -589,8 +589,10 @@ Prefer C++-style casts
 When casting, use ``static_cast``, ``reinterpret_cast``, and ``const_cast``,
 rather than C-style casts. There are two exceptions to this:
 
-* When casting to ``void`` to suppress warnings about unused variables (as an
-  alternative to ``[[maybe_unused]]``). Prefer C-style casts in this instance.
+* Although ``[[maybe_unused]]`` is preferred to suppress warnings about unused
+  variables in simple cases (for example, variables used only in asserts) casting
+  to ``void`` using a C-style cast can also be used to suppress such warnings if
+  using ``[[maybe_unused]]`` is not acceptable.
----------------
jh7370 wrote:

This doesn't clearly explain when `[[maybe_unused]]` is not acceptable, so it isn't really a useful standard, in my opinion.

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


More information about the llvm-commits mailing list