Below are two test-cases for Undefined Behaviour, expressed as IIFE (Immediately Called 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() {}
When compiled with GCC trunk, test4
is correctly rejected as it exhibs Undefined Behaviour in a constexpr
. On the other hand test3
is accepted.
Is GCC right to accept test3
?
Is GCC right to accept test3?
No, this is a GCC bug. I just reported it as bug #93389.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With