cig*_*ien 9 c++ language-lawyer constant-expression c++20 consteval
clang(trunk) 给出以下代码的错误:
consteval void f() {}
int main()
{
f(); // error: call to consteval function 'f' is not a constant expression
// note: subobject of type 'void' is not initialized
}
Run Code Online (Sandbox Code Playgroud)
而 gcc(trunk) 编译它没有错误。
我觉得这可能是一个 clang bug,因为 gcc 和 clang 都接受这个代码:
consteval int g() { return 42; }
int main()
{
g(); // ok
}
Run Code Online (Sandbox Code Playgroud)
这是要玩的代码。
那么这是一个 clang bug,还是代码格式不正确,或者有 ub,还是其他什么?
编辑:我觉得指出 clang 允许f
从其他函数调用(如果它们也是保守的)可能是相关的。f
它仅在从非 consteval 函数调用时给出错误:
consteval int h()
{
f(); // ok
return 42;
}
Run Code Online (Sandbox Code Playgroud)
演示。
归档时间: |
|
查看次数: |
4606 次 |
最近记录: |