This revision was automatically updated to reflect the committed changes.
Closed by commit rGcda093681bad: Update coding standards for constexpr if
statements; NFC (authored by aaron.ballman).
Changed prior to commit:
https://reviews.llvm.org/D132232?vs=453993&id=454085#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D132232/new/
https://reviews.llvm.org/D132232
Files:
llvm/docs/CodingStandards.rst
Index: llvm/docs/CodingStandards.rst
===================================================================
--- llvm/docs/CodingStandards.rst
+++ llvm/docs/CodingStandards.rst
@@ -1026,6 +1026,24 @@
The idea is to reduce indentation and the amount of code you have to keep track
of when reading the code.
+Note: this advice does not apply to a ``constexpr if`` statement. The
+substatement of the ``else`` clause may be a discarded statement, so removing
+the ``else`` can cause unexpected template instantiations. Thus, the following
+example is correct:
+
+.. code-block:: c++
+
+ template<typename T>
+ static constexpr bool VarTempl = true;
+
+ template<typename T>
+ int func() {
+ if constexpr (VarTempl<T>)
+ return 1;
+ else
+ static_assert(!VarTempl<T>);
+ }
+
Turn Predicate Loops into Predicate Functions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Index: llvm/docs/CodingStandards.rst
===================================================================
--- llvm/docs/CodingStandards.rst
+++ llvm/docs/CodingStandards.rst
@@ -1026,6 +1026,24 @@
The idea is to reduce indentation and the amount of code you have to keep track
of when reading the code.
+Note: this advice does not apply to a ``constexpr if`` statement. The
+substatement of the ``else`` clause may be a discarded statement, so removing
+the ``else`` can cause unexpected template instantiations. Thus, the following
+example is correct:
+
+.. code-block:: c++
+
+ template<typename T>
+ static constexpr bool VarTempl = true;
+
+ template<typename T>
+ int func() {
+ if constexpr (VarTempl<T>)
+ return 1;
+ else
+ static_assert(!VarTempl<T>);
+ }
+
Turn Predicate Loops into Predicate Functions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits