[PATCH] D151187: [doc] Add casting style preference to coding standards

Mehdi AMINI via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 23 10:47:02 PDT 2023


mehdi_amini added inline comments.


================
Comment at: llvm/docs/CodingStandards.rst:1270
+When casting, use ``static_cast`` and ``reinterpret_cast`` rather than C-style
+casts. The sole exception to this is when casting to void to suppress warnings
+about unused variables, when C-style casts should be preferred instead:
----------------
aaron.ballman wrote:
> jhenderson wrote:
> > aaron.ballman wrote:
> > > FWIW, I think it would be reasonable to also mention use of `[[maybe_unused]]` as a potential alternative to casting to `void`, but without prejudice as to which approach to use.
> > I feel like any reference to `[[maybe_unused]]` belongs either in its own section (which I don't propose to add at this time) or in the section above where asserts are discussed, as that talks about casting to void to suppress the warnings. What I want to achieve here is to ensure the rule for preferring C++-style doesn't apply to that specific case. `[[maybe_unused]]` is an alternative solution, but isn't relevant to casting.
> SGTM!
What about `The sole exception to this is when casting to ``void`` to suppress warnings about unused variables (as an alternative to `[[maybe_unused]]`, when C-style casts should be preferred instead.` (the example is likely unnecessary).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151187/new/

https://reviews.llvm.org/D151187



More information about the llvm-commits mailing list