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

James Henderson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 19 02:37:28 PDT 2023


jhenderson updated this revision to Diff 557017.
jhenderson added a comment.

Updated patch based on my latest proposal. Feedback appreciated!


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

https://reviews.llvm.org/D151187

Files:
  llvm/docs/CodingStandards.rst


Index: llvm/docs/CodingStandards.rst
===================================================================
--- llvm/docs/CodingStandards.rst
+++ llvm/docs/CodingStandards.rst
@@ -590,6 +590,18 @@
 This form of RTTI is opt-in and can be
 :doc:`added to any class <HowToSetUpLLVMStyleRTTI>`.
 
+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.
+  
+* When casting integral types (including enums), prefer the prevailing style in
+  the area being worked on.
+
 .. _static constructor:
 
 Do not use Static Constructors


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151187.557017.patch
Type: text/x-patch
Size: 810 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230919/7b443c05/attachment.bin>


More information about the llvm-commits mailing list