public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-8120] c++: ICE with anonymous union [PR97974]
@ 2021-04-11  3:52 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2021-04-11  3:52 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:936d500dfc17f58f2507ecd0f7f26e4f197052ee

commit r11-8120-g936d500dfc17f58f2507ecd0f7f26e4f197052ee
Author: Jason Merrill <jason@redhat.com>
Date:   Sat Apr 10 14:00:15 2021 -0400

    c++: ICE with anonymous union [PR97974]
    
    Here lookup got confused by finding a conversion operator from
    lookup_anon_field.  Let's avoid this by pruning functions from
    CLASSTYPE_MEMBER_VEC as well as TYPE_FIELDS.
    
    gcc/cp/ChangeLog:
    
            PR c++/97974
            * decl.c (fixup_anonymous_aggr): Prune all functions from
            CLASSTYPE_MEMBER_VEC.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/97974
            * g++.dg/lookup/pr84962.C: Adjust diagnostic.
            * g++.dg/other/anon-union5.C: New test.

Diff:
---
 gcc/cp/decl.c                            | 8 ++++++++
 gcc/testsuite/g++.dg/lookup/pr84962.C    | 2 +-
 gcc/testsuite/g++.dg/other/anon-union5.C | 9 +++++++++
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 3294b4fa943..ec05ee1f0b4 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5005,6 +5005,14 @@ fixup_anonymous_aggr (tree t)
     else
       prev_p = &DECL_CHAIN (probe);
 
+  /* Splice all functions out of CLASSTYPE_MEMBER_VEC.  */
+  vec<tree,va_gc>* vec = CLASSTYPE_MEMBER_VEC (t);
+  unsigned store = 0;
+  for (tree elt : vec)
+    if (!is_overloaded_fn (elt))
+      (*vec)[store++] = elt;
+  vec_safe_truncate (vec, store);
+
   /* Anonymous aggregates cannot have fields with ctors, dtors or complex
      assignment operators (because they cannot have these methods themselves).
      For anonymous unions this is already checked because they are not allowed
diff --git a/gcc/testsuite/g++.dg/lookup/pr84962.C b/gcc/testsuite/g++.dg/lookup/pr84962.C
index b9b7a313526..c22b95ce8f9 100644
--- a/gcc/testsuite/g++.dg/lookup/pr84962.C
+++ b/gcc/testsuite/g++.dg/lookup/pr84962.C
@@ -9,6 +9,6 @@ struct X {
     // { dg-error "public non-static data member" "" { target *-*-* } .-1 }
   };
 
-  int  : a; // { dg-error "non-integral" }
+  int  : a; // { dg-error "" }
 };
 
diff --git a/gcc/testsuite/g++.dg/other/anon-union5.C b/gcc/testsuite/g++.dg/other/anon-union5.C
new file mode 100644
index 00000000000..616dea87e88
--- /dev/null
+++ b/gcc/testsuite/g++.dg/other/anon-union5.C
@@ -0,0 +1,9 @@
+// PR c++/97974
+
+struct A {
+  union {
+    operator int ();		// { dg-error "anonymous union" }
+    int a;
+  };
+  operator int;			// { dg-error "" }
+};


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

only message in thread, other threads:[~2021-04-11  3:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-11  3:52 [gcc r11-8120] c++: ICE with anonymous union [PR97974] 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).