In the next program struct B
has immediate consteval
default constructor, which does not initialize i
field. Then this constructor is used to make a temporary and its i
field remains untouched:
struct B {
bool b = true;
int i;
consteval B() {}
};
static_assert( B{}.b );
Clang and MSVC are fine with it. But GCC complains:
error: 'B{true}' is not a constant expression
7 | static_assert( B{}.b );
| ^
error: 'B()' is not a constant expression because it refers to an incompletely initialized variable
Demo: https://gcc.godbolt.org/z/x4n6ezrhT
Which compiler is right here?
Update:
I reported this issue to GCC: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104512 And it was closed with the explanation
This gives the hint that both MSVC and clang are incorrect really. EDG also implements correctly static_assert not being an immediate function context.