From: Jason Merrill Date: Fri, 30 Jul 2021 20:49:03 +0000 (-0400) Subject: c++: ICE on anon struct with base [PR96636] X-Git-Tag: basepoints/gcc-13~5660 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=af76342b444948ab262b276cdf083c2d2e0cebbb;p=thirdparty%2Fgcc.git c++: ICE on anon struct with base [PR96636] pinski pointed out that my recent change to reject anonymous structs with bases was relevant to this PR. But we still ICEd after giving that error; this fixes the ICE. PR c++/96636 gcc/cp/ChangeLog: * decl.c (fixup_anonymous_aggr): Clear TYPE_NEEDS_CONSTRUCTING after error. gcc/testsuite/ChangeLog: * g++.dg/ext/anon-struct9.C: New test. --- diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index e4be6be18198..6fa6b9adc877 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -5094,7 +5094,11 @@ fixup_anonymous_aggr (tree t) tree field, type; if (BINFO_N_BASE_BINFOS (TYPE_BINFO (t))) - error_at (location_of (t), "anonymous struct with base classes"); + { + error_at (location_of (t), "anonymous struct with base classes"); + /* Avoid ICE after error on anon-struct9.C. */ + TYPE_NEEDS_CONSTRUCTING (t) = false; + } for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field)) if (TREE_CODE (field) == FIELD_DECL) diff --git a/gcc/testsuite/g++.dg/ext/anon-struct9.C b/gcc/testsuite/g++.dg/ext/anon-struct9.C new file mode 100644 index 000000000000..567594296204 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/anon-struct9.C @@ -0,0 +1,9 @@ +// PR c++/96636 +// { dg-options "" } + +typedef class { + class a {}; + class : virtual a {}; // { dg-error "anonymous struct with base" } +} b; +void foo(){ b();} +