public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: C++ PATCH for c++/47635 (ICE after error with enum scoped function)
Date: Mon, 20 Jun 2011 14:26:00 -0000	[thread overview]
Message-ID: <4DFF5733.5080308@redhat.com> (raw)

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

If we see an enum as a scope for a declarator-id, we should avoid 
setting ctype in the first place as it can't possibly be right.

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

[-- Attachment #2: 47635.patch --]
[-- Type: text/x-patch, Size: 2043 bytes --]

commit 5800b6d699b10f0c15355b8f37fa9beb7957ea72
Author: Jason Merrill <jason@redhat.com>
Date:   Sun Jun 19 22:38:46 2011 -0400

    	PR c++/47635
    	* decl.c (grokdeclarator): Don't set ctype to an ENUMERAL_TYPE.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 85249f1..263ab3f 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -8338,10 +8338,15 @@ grokdeclarator (const cp_declarator *declarator,
 		else if (TYPE_P (qualifying_scope))
 		  {
 		    ctype = qualifying_scope;
-		    if (innermost_code != cdk_function
-			&& current_class_type
-			&& !UNIQUELY_DERIVED_FROM_P (ctype,
-						     current_class_type))
+		    if (!MAYBE_CLASS_TYPE_P (ctype))
+		      {
+			error ("%q#T is not a class or a namespace", ctype);
+			ctype = NULL_TREE;
+		      }
+		    else if (innermost_code != cdk_function
+			     && current_class_type
+			     && !UNIQUELY_DERIVED_FROM_P (ctype,
+							  current_class_type))
 		      {
 			error ("type %qT is not derived from type %qT",
 			       ctype, current_class_type);
@@ -9350,7 +9355,7 @@ grokdeclarator (const cp_declarator *declarator,
      would not have exited the loop above.  */
   if (declarator
       && declarator->u.id.qualifying_scope
-      && TYPE_P (declarator->u.id.qualifying_scope))
+      && MAYBE_CLASS_TYPE_P (declarator->u.id.qualifying_scope))
     {
       tree t;
 
@@ -10156,13 +10161,6 @@ grokdeclarator (const cp_declarator *declarator,
 		       "declared out of global scope", name);
 	  }
 
-	if (ctype != NULL_TREE
-	    && TREE_CODE (ctype) != NAMESPACE_DECL && !MAYBE_CLASS_TYPE_P (ctype))
-	  {
-	    error ("%q#T is not a class or a namespace", ctype);
-	    ctype = NULL_TREE;
-	  }
-
 	if (ctype == NULL_TREE)
 	  {
 	    if (virtualp)
diff --git a/gcc/testsuite/g++.dg/cpp0x/enum20.C b/gcc/testsuite/g++.dg/cpp0x/enum20.C
new file mode 100644
index 0000000..e5dc186
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/enum20.C
@@ -0,0 +1,5 @@
+// PR c++/47635
+// { dg-options -std=c++0x }
+
+enum A { };
+void A::f() { }			// { dg-error "not a class" }

                 reply	other threads:[~2011-06-20 14:20 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=4DFF5733.5080308@redhat.com \
    --to=jason@redhat.com \
    --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).