[llvm] [NFC][CodingStandard] Prefer ``[[maybe_unused]]`` over C-style void cast for unused variables (PR #142850)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 20 08:43:07 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.
----------------
jurahul wrote:
Right, but based on the forum discussion, not everyone is on board with that. I have amended the PR now with the above changes. The delta now is essentially that for variables used only in asserts, we require the use of ``maybe_unused`` over C-style casts. I am hoping that will be an acceptable delta.
https://github.com/llvm/llvm-project/pull/142850
More information about the llvm-commits
mailing list