[llvm] 18bb972 - [doc] Add casting style preference to coding standards

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 9 03:02:49 PST 2023


Author: James Henderson
Date: 2023-11-09T11:01:51Z
New Revision: 18bb9725619569687bec2c013768511105266a5e

URL: https://github.com/llvm/llvm-project/commit/18bb9725619569687bec2c013768511105266a5e
DIFF: https://github.com/llvm/llvm-project/commit/18bb9725619569687bec2c013768511105266a5e.diff

LOG: [doc] Add casting style preference to coding standards

Differential Revision: https://reviews.llvm.org/D151187

Added: 
    

Modified: 
    llvm/docs/CodingStandards.rst

Removed: 
    


################################################################################
diff  --git a/llvm/docs/CodingStandards.rst b/llvm/docs/CodingStandards.rst
index 3268cf1a9442de7..7ba20c09d04f689 100644
--- a/llvm/docs/CodingStandards.rst
+++ b/llvm/docs/CodingStandards.rst
@@ -590,6 +590,19 @@ templates like :ref:`isa\<>, cast\<>, and dyn_cast\<> <isa>`.
 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


        


More information about the llvm-commits mailing list