https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97234
Bug ID: 97234 Summary: Constexpr class-scope array initializer referencing previous elements Product: gcc Version: 10.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: botond at mozilla dot com Target Milestone: --- The following code: struct S { static constexpr int rolling_sum[4]{ 0, rolling_sum[0] + 1, rolling_sum[1] + 2, rolling_sum[2] + 3 }; }; produces errors when compiled with g++ 10: test.cpp:4:9: error: ‘rolling_sum’ was not declared in this scope 4 | rolling_sum[0] + 1, | ^~~~~~~~~~~ test.cpp:5:9: error: ‘rolling_sum’ was not declared in this scope 5 | rolling_sum[1] + 2, | ^~~~~~~~~~~ test.cpp:6:9: error: ‘rolling_sum’ was not declared in this scope 6 | rolling_sum[2] + 3 | The code is accepted by clang. It's also accepted by gcc if the array is declared at namespace scope, leading me to believe that rejecting it at class scope is likely a bug.