Live testcase: https://godbolt.org/z/1JYWJS For posterity: struct A { constexpr A() : data() {} struct X { int n; }; X data[2]; }; static_assert((A(), true)); static_assert(A().data[0].n == 0); static_assert(A().data[1].n == 0); constexpr A x; GCC rejects this valid code with: <source>:9:29: error: non-constant condition for static assertion 9 | static_assert(A().data[1].n == 0); | ~~~~~~~~~~~~~~^~~~ <source>:9:29: error: accessing uninitialized member 'A::X::n' <source>:10:13: error: 'A{A::X [2]{A::X{0}, A::X()}}' is not a constant expression 10 | constexpr A x; | Looks like GCC fails to evaluate the initializer of the second and subsequent elements of a value-initialized array during constant evaluation.
Confirmed. Doesn't seem to be a regression.
MSVC has the same bug :).
(In reply to Andrew Pinski from comment #2) > MSVC has the same bug :). Well MSVC rejects it even for array size of 1.
This seems to have been fixed by r15-7260 for PR118285.
The trunk branch has been updated by Jason Merrill <jason@gcc.gnu.org>: https://gcc.gnu.org/g:b38382e36410a9a649b904a2d0a0abcb90f9c418 commit r16-2326-gb38382e36410a9a649b904a2d0a0abcb90f9c418 Author: Jason Merrill <jason@redhat.com> Date: Thu Jul 17 09:46:35 2025 -0400 c++: constexpr array testcase [PR87097] This seems to have been fixed by r15-7260 for PR118285, but is sufficiently different to merit its own test. PR c++/87097 gcc/testsuite/ChangeLog: * g++.dg/cpp0x/constexpr-array29.C: New test.
The releases/gcc-15 branch has been updated by Jason Merrill <jason@gcc.gnu.org>: https://gcc.gnu.org/g:10846d82a895cbc95b7819a5c44cd0216bb21bf4 commit r15-9990-g10846d82a895cbc95b7819a5c44cd0216bb21bf4 Author: Jason Merrill <jason@redhat.com> Date: Thu Jul 17 09:46:35 2025 -0400 c++: constexpr array testcase [PR87097] This seems to have been fixed by r15-7260 for PR118285, but is sufficiently different to merit its own test. PR c++/87097 gcc/testsuite/ChangeLog: * g++.dg/cpp0x/constexpr-array29.C: New test.
The releases/gcc-14 branch has been updated by Jason Merrill <jason@gcc.gnu.org>: https://gcc.gnu.org/g:d7dd08411bc3b4e8431174d036021ecf482e7d61 commit r14-11894-gd7dd08411bc3b4e8431174d036021ecf482e7d61 Author: Jason Merrill <jason@redhat.com> Date: Thu Jul 17 09:46:35 2025 -0400 c++: constexpr array testcase [PR87097] This seems to have been fixed by r15-7260 for PR118285, but is sufficiently different to merit its own test. PR c++/87097 gcc/testsuite/ChangeLog: * g++.dg/cpp0x/constexpr-array29.C: New test.