diff --git a/llvm/docs/CodingStandards.rst b/llvm/docs/CodingStandards.rst --- a/llvm/docs/CodingStandards.rst +++ b/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 + static constexpr bool VarTempl = true; + + template + int func() { + if constexpr (VarTempl) + return 1; + else + static_assert(!VarTempl); + } + Turn Predicate Loops into Predicate Functions ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^