[PATCH] D151187: [doc] Add casting style preference to coding standards
James Henderson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 23 04:07:37 PDT 2023
jhenderson updated this revision to Diff 524647.
jhenderson added a comment.
Use `reinterpret_cast` instead of `static_cast`.
Repository:
rG LLVM Github Monorepo
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
@@ -1263,6 +1263,18 @@
bool NewToSet = Myset.insert(Value); (void)NewToSet;
assert(NewToSet && "The value shouldn't be in the set yet");
+Prefer C++-style casts
+^^^^^^^^^^^^^^^^^^^^^^
+
+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:
+
+.. code-block:: c++
+ int x = 42;
+ long *y = reinterpret_cast<long *>(&x);
+ (void)y;
+
Do Not Use ``using namespace std``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151187.524647.patch
Type: text/x-patch
Size: 772 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230523/2508f750/attachment.bin>
More information about the llvm-commits
mailing list