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

Aaron Ballman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 13 08:36:57 PDT 2023


aaron.ballman added a comment.

In D151187#4385492 <https://reviews.llvm.org/D151187#4385492>, @nikic wrote:

> -1 from my side. I consider `static_cast<>` to be worse for integer casts by dint of adding unnecessary noise. I could get on board with this if integer/enum casts are excluded.
>
> For the cases where it really matters, we already use our own `cast`/`dyn_cast` anyway. Encouraging use of `const_cast<>` is fine as well, and I believe we already do use that fairly consistently in the cases where it is applicable.

I don't have strong feelings about using `static_cast` with integer or enumeration types. Personally, I tend to use C-style casts for those, but I don't have an objection to preferring  a named cast instead. Someone could put together a quick and dirty clang-tidy check to see if we use C-style casts to integer types with far greater frequency than named casts and use that to make a decision. Barring that amount of effort, I would be fine excluding int/enum casts from this requirement on the assumption that we have more of those casts (just based on my gut feeling, if others have a different gut feeling, definitely speak up).


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