1
GCC无法报告格式错误的constexpr lambda调用
以下是两个未定义行为的测试用例,表示为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由于它在中显示出Undefined Behavior ,因此被正确拒绝constexpr。另一方面test3被接受。 GCC有权接受test3吗?