Skip to content

Commit 18bb972

Browse files
committed
[doc] Add casting style preference to coding standards
Differential Revision: https://reviews.llvm.org/D151187
1 parent 1b1c817 commit 18bb972

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

llvm/docs/CodingStandards.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,19 @@ templates like :ref:`isa\<>, cast\<>, and dyn_cast\<> <isa>`.
590590
This form of RTTI is opt-in and can be
591591
:doc:`added to any class <HowToSetUpLLVMStyleRTTI>`.
592592

593+
Prefer C++-style casts
594+
^^^^^^^^^^^^^^^^^^^^^^
595+
596+
When casting, use ``static_cast``, ``reinterpret_cast``, and ``const_cast``,
597+
rather than C-style casts. There are two exceptions to this:
598+
599+
* When casting to ``void`` to suppress warnings about unused variables (as an
600+
alternative to ``[[maybe_unused]]``). Prefer C-style casts in this instance.
601+
602+
* When casting between integral types (including enums that are not strongly-
603+
typed), functional-style casts are permitted as an alternative to
604+
``static_cast``.
605+
593606
.. _static constructor:
594607

595608
Do not use Static Constructors

0 commit comments

Comments
 (0)