Is constexpr if with an initializer guaranteed by the standard? 'constexpr (constexpr auto x = f (); x) {}'

I can not find any information about the new C ++ 17 if the initialization syntax and 'constexpr if' in:

http://open-std.org/JTC1/SC22/WG21/docs/papers/2016/p0128r1.html

However, the syntax is supported by Clang-HEAD ...

constexpr auto f() { return true; } int main() { if constexpr(constexpr auto x = f(); x) { } } 

online code here → http://melpon.org/wandbox/permlink/dj3a9ChvjhlNc8nr

Is constexpr if with an initializer guaranteed by the standard, since constexpr if is just " if with constexpr " or is it not guaranteed and should be explicitly added to the standard?

+6
source share
1 answer

The statement Initialization Output mentions if constexpr and states that " if constexpr work the same way as with the extended if from this sentence."

The specification of the if with an initializer in N4606 [stmt.if] p3 explicitly allows you to use if constexpr .

This is what N4606 [stmt.if] p3 says:

Form if statement

 if constexpr[opt] ( init-statement condition ) statement 

equivalently

 { init-statement if constexpr[opt] ( condition ) statement } 

and form if statement

 if constexpr[opt] ( init-statement condition ) statement else statement 

equivalently

 { init-statement if constexpr[opt] ( condition ) statement else statement } 

except that the names declared in the init-statement are in the same declarative scope as those declared in the condition.

+7
source

All Articles