[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 03:59:23 PDT 2023


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

Update second bullet to match proposal.


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 between integral types (including enums that are not strongly-
+  typed), functional-style casts are permitted as an alternative to static_cast.
+
 .. _static constructor:
 
 Do not use Static Constructors


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


More information about the llvm-commits mailing list