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

Aaron Ballman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 23 05:06:49 PDT 2023


aaron.ballman 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:
----------------
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.


================
Comment at: llvm/docs/CodingStandards.rst:1274-1276
+  int x = 42;
+  long *y = reinterpret_cast<long *>(&x);
+  (void)y;
----------------
How about a more realistic example along the lines of:
```
int check_value = doSomeWorkWithSideEffects();
assert(check_value == 42 && "the assert is removed in NDEBUG builds");
(void)check_value;
```


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