constexpr是否有标准保证的初始化程序?'constexpr(constexpr auto x = f(); x){}'

Kri*_*ris 6 c++ clang constexpr c++17

如果初始化语法和'constexpr if'中有以下内容,我找不到有关新C++ 17的任何信息:

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

然而,Clang-HEAD支持语法...

constexpr auto f() { return true; }
int main() {
    if constexpr(constexpr auto x = f(); x) { }
}
Run Code Online (Sandbox Code Playgroud)

在线代码 - > http://melpon.org/wandbox/permlink/dj3a9ChvjhlNc8nr

是否constexpr if有标准保证的初始化程序,因为constexpr if它只是一个" ifconstexpr"或者它不能保证并且必须明确地添加到标准中?

cpp*_*ner 7

带有初始化程序提议的Selection语句提及if constexpr,并指出" if constexpr工作设施与if此提案中的扩展语句一样".

N4606 [stmt.if] p3中关于if具有初始化程序的语句的规范明确允许使用.if constexpr

这是N4606 [stmt.if] p3所说的:

表格的if语句

if constexpr[opt] ( init-statement condition ) statement
Run Code Online (Sandbox Code Playgroud)

相当于

{
  init-statement
  if constexpr[opt] ( condition ) statement
}
Run Code Online (Sandbox Code Playgroud)

以及表格的if语句

if constexpr[opt] ( init-statement condition ) statement else statement
Run Code Online (Sandbox Code Playgroud)

相当于

{
  init-statement
  if constexpr[opt] ( condition ) statement else statement
}
Run Code Online (Sandbox Code Playgroud)

除了在init语句中声明的名称与条件中声明的名称在同一声明区域中.