diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4faf0010a014..18f1dfdd6bdb 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2011-12-17 Jason Merrill + + PR c++/51588 + * parser.c (cp_parser_ptr_operator): Reject pointer to member of enum. + 2011-12-17 Richard Henderson PR bootstrap/51072 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index ac7427e5e85c..51d04d46fc07 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/ChangeLog b/gcc/testsuite/ChangeLog index 066121dcd36f..235f8c965b5d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2011-12-17 Jason Merrill + PR c++/51588 + * g++.dg/parse/enum7.C: New. + PR c++/51586 * g++.dg/lookup/nested2.C: New. diff --git a/gcc/testsuite/g++.dg/parse/enum7.C b/gcc/testsuite/g++.dg/parse/enum7.C new file mode 100644 index 000000000000..d9e3a89d72e4 --- /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 "" }