以下是两个未定义行为的测试用例,表示为IIFE(即所谓的Lambda-Axpression):
constexpr auto test3 = []{
int* p{};
{
int x{};
p = &x;
}
return *p; // Undefined Behaviour
}(); // IIFE
constexpr auto test4 = []{
int x = std::numeric_limits<int>::min();
int y = -x; // Undefined Behaviour
return y;
}();
int main() {}
使用GCC主干编译时,由于
test4
会显示constexpr
中的Undefined Behavior,因此会被正确拒绝。另一方面,test3
被接受。GCC有权接受
test3
吗?
最佳答案
关于c++ - GCC无法报告格式错误的constexpr lambda调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59862914/