GCC 无法报告格式错误的 constexpr lambda 调用

wim*_*aan 9 c++ undefined-behavior avr-gcc constexpr

以下是未定义行为的两个测试用例,表示为 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() {}
Run Code Online (Sandbox Code Playgroud)

当使用 GCC 主干编译时,test4被正确拒绝,因为它在constexpr. 另一方面test3是接受。

GCC 是否有权接受test3

wim*_*aan 7

GCC 是否有权接受 test3?

不,这是一个 GCC 错误。我刚刚将其报告为错误 #93389