public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed] c++: ICE on anon struct with base [PR96636]
@ 2021-07-31 14:45 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2021-07-31 14:45 UTC (permalink / raw)
  To: gcc-patches

pinskia 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.

Tested x86_64-pc-linux-gnu, applying to trunk.

	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.
---
 gcc/cp/decl.c                           | 6 +++++-
 gcc/testsuite/g++.dg/ext/anon-struct9.C | 9 +++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/ext/anon-struct9.C

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index e4be6be1819..6fa6b9adc87 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 00000000000..56759429620
--- /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();}
+

base-commit: 4c4249b71de3b15ba1e176ce90a57fb7bc54b917
prerequisite-patch-id: 62730bcaf1f07786fd756efb6f3bbd94d778c092
-- 
2.27.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-07-31 14:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-31 14:45 [pushed] c++: ICE on anon struct with base [PR96636] Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).