public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Nathan Sidwell <nathan@acm.org>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: [PR c++/84602] ICE with anon-struct
Date: Wed, 28 Feb 2018 12:31:00 -0000	[thread overview]
Message-ID: <283ebc10-d9d9-188f-1030-bb9f99051f38@acm.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 310 bytes --]

This fixes an ICE with anon-struct.  When reimplementing this bit of 
name lookup, I relied on what the standard said and the completeness of 
the testsuite WRT extensions.  Silly me.

Anyway, we can just have the anon-struct lookup recurse to 
get_class_binding_direct, so simpler!

nathan
-- 
Nathan Sidwell

[-- Attachment #2: 84602.diff --]
[-- Type: text/x-patch, Size: 3389 bytes --]

2018-02-28  Nathan Sidwell  <nathan@acm.org>

	PR c++/84602
	* name-lookup.h (search_anon_aggr): Add defaulted WANT_TYPE arg.
	* name-lookup.c (fields_linear_search): Look in an anon-aggr
	regardless of want_type.
	(search_anon_aggr): Just use get_class_binding_direct.

	PR c++/84602
	* g++.dg/lookup/pr84602.C: New.

Index: cp/name-lookup.c
===================================================================
--- cp/name-lookup.c	(revision 258044)
+++ cp/name-lookup.c	(working copy)
@@ -1162,11 +1162,10 @@ fields_linear_search (tree klass, tree n
     {
       tree decl = fields;
 
-      if (!want_type
-	  && TREE_CODE (decl) == FIELD_DECL
+      if (TREE_CODE (decl) == FIELD_DECL
 	  && ANON_AGGR_TYPE_P (TREE_TYPE (decl)))
 	{
-	  if (tree temp = search_anon_aggr (TREE_TYPE (decl), name))
+	  if (tree temp = search_anon_aggr (TREE_TYPE (decl), name, want_type))
 	    return temp;
 	}
 
@@ -1191,26 +1190,17 @@ fields_linear_search (tree klass, tree n
   return NULL_TREE;
 }
 
-/* Look for NAME field inside of anonymous aggregate ANON.  */
+/* Look for NAME member inside of anonymous aggregate ANON.  Although
+   such things should only contain FIELD_DECLs, we check that too
+   late, and would give very confusing errors if we weren't
+   permissive here.  */
 
 tree
-search_anon_aggr (tree anon, tree name)
+search_anon_aggr (tree anon, tree name, bool want_type)
 {
   gcc_assert (COMPLETE_TYPE_P (anon));
-  tree ret;
-	  
-  if (vec<tree, va_gc> *member_vec = CLASSTYPE_MEMBER_VEC (anon))
-    ret = member_vec_linear_search (member_vec, name);
-  else
-    ret = fields_linear_search (anon, name, false);
-
-  if (ret)
-    {
-      /* Anon members can only contain fields.  */
-      gcc_assert (!STAT_HACK_P (ret) && !DECL_DECLARES_TYPE_P (ret));
-      return ret;
-    }
-  return NULL_TREE;
+  tree ret = get_class_binding_direct (anon, name, want_type);
+  return ret;
 }
 
 /* Look for NAME as an immediate member of KLASS (including
Index: cp/name-lookup.h
===================================================================
--- cp/name-lookup.h	(revision 258044)
+++ cp/name-lookup.h	(working copy)
@@ -307,7 +307,7 @@ extern void pop_decl_namespace (void);
 extern void do_namespace_alias (tree, tree);
 extern tree do_class_using_decl (tree, tree);
 extern tree lookup_arg_dependent (tree, tree, vec<tree, va_gc> *);
-extern tree search_anon_aggr (tree, tree);
+extern tree search_anon_aggr (tree, tree, bool = false);
 extern tree get_class_binding_direct (tree, tree, int type_or_fns = -1);
 extern tree get_class_binding (tree, tree, int type_or_fns = -1);
 extern tree *find_member_slot (tree klass, tree name);
Index: testsuite/g++.dg/lookup/pr84602.C
===================================================================
--- testsuite/g++.dg/lookup/pr84602.C	(revision 0)
+++ testsuite/g++.dg/lookup/pr84602.C	(working copy)
@@ -0,0 +1,32 @@
+// PR c++/84602 ICE
+// { dg-additional-options "-fpermissive" }
+
+struct X {
+  union {
+    class a; // { dg-warning "can only have" }
+  };
+  a *b;
+};
+X::a *a;
+
+struct Y {
+  union {
+    class a; // { dg-warning "can only have" }
+    int a;
+  };
+  class a *b;
+};
+
+class Y::a *y;
+
+struct Z {
+  union {
+    // Force MEMBER_VEC creation
+    int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10;
+    class a; // { dg-warning "can only have" }
+    int a;
+  };
+  class a *b;
+};
+
+class Z::a *z;

                 reply	other threads:[~2018-02-28 12:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=283ebc10-d9d9-188f-1030-bb9f99051f38@acm.org \
    --to=nathan@acm.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).