Patchwork C++ PATCH for c++/51588 (ICE with invalid pointer-to-member)

login
register
mail settings
Submitter Jason Merrill
Date Dec. 18, 2011, 12:53 a.m.
Message ID <4EED396F.1010302@redhat.com>
Download mbox | patch
Permalink /patch/132028/
State New
Headers show

Comments

Jason Merrill - Dec. 18, 2011, 12:53 a.m.
In C++11 an enum can be used in a nested-name-specifier, but it still 
isn't valid for a pointer-to-member.

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

Patch

commit 80c46fcfb6ea29a6566b285cf94e519ec414d2e9
Author: Jason Merrill <jason@redhat.com>
Date:   Sat Dec 17 15:39:56 2011 -0500

    	PR c++/51588
    	* parser.c (cp_parser_ptr_operator): Reject pointer to member of enum.

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index ac7427e..51d04d4 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -16448,6 +16448,9 @@  cp_parser_ptr_operator (cp_parser* parser,
 
 	  if (TREE_CODE (parser->scope) == NAMESPACE_DECL)
 	    error_at (token->location, "%qD is a namespace", parser->scope);
+	  else if (TREE_CODE (parser->scope) == ENUMERAL_TYPE)
+	    error_at (token->location, "cannot form pointer to member of "
+		      "non-class %q#T", parser->scope);
 	  else
 	    {
 	      /* The type of which the member is a member is given by the
diff --git a/gcc/testsuite/g++.dg/parse/enum7.C b/gcc/testsuite/g++.dg/parse/enum7.C
new file mode 100644
index 0000000..d9e3a89
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/enum7.C
@@ -0,0 +1,9 @@ 
+// PR c++/51588
+
+enum A {};
+
+struct B : A {			// { dg-error "" }
+  int i;
+};
+
+int A::* p = &B::i;		// { dg-error "" }