Possible duplicate of Bug 96241. The following one-line source file triggers an ICE with `-std=c++17`: int main(){[](){enum E{F};struct{E e{F};}p[1]{};return p->e;};} % g++ -std=c++17 ice.cpp ice.cpp: In static member function ‘static constexpr main()::<lambda()>::E main()::<lambda()>::_FUN()’: ice.cpp:1:61: in ‘constexpr’ expansion of ‘0->main()::<lambda()>()’ ice.cpp:1:61: internal compiler error: in verify_ctor_sanity, at cp/constexpr.c:3884 1 | int main(){[](){enum E{F};struct{E e{F};}p[1]{};return p->e;};} | ^ Please submit a full bug report, with preprocessed source if appropriate. See <file:///usr/share/doc/gcc-10/README.Bugs> for instructions.
Not a dup of bug 96241, this one started with r10-6527. Use -std=c++17.
A test without a lambda that ICEs with -std=c++14 too: enum E : int { F }; struct X { E e{F}; }; constexpr X x[1]; auto foo () { return x[0].e; } Note that we don't ICE if the X's member is changed to E e{1};. The difference is that for the former reduced_constant_expression_p says false (due to the CONST_DECL F), so we cxx_eval_bare_aggregate and verify_ctor_sanity in cxx_eval_constant_expression/CONSTRUCTOR. With e{1} reduced_constant_expression_p is true and we don't call cxx_eval_bare_aggregate.
And that also means that this: enum E : int { F }; struct X { E e{F}; }; constexpr X x[1]{}; constexpr auto foo () { return x[0].e; } constexpr auto a = foo (); started to ICE earlier, since r10-6437.
This ought to fix it, though it's completely untested: --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -3661,6 +3661,10 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, tree t, { tree empty_ctor = build_constructor (init_list_type_node, NULL); val = digest_init (elem_type, empty_ctor, tf_warning_or_error); + constexpr_ctx new_ctx = *ctx; + new_ctx.ctor = build_constructor (elem_type, NULL); + new_ctx.object = NULL_TREE; + ctx = &new_ctx; } else val = build_value_init (elem_type, tf_warning_or_error);
...which should also fix Bug 96241 so these in fact are duplicates.
Closing as a dup. *** This bug has been marked as a duplicate of bug 96241 ***