diff options
-rw-r--r-- | gcc/cp/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/cp/parser.c | 14 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/parse/friend6.C | 3 |
4 files changed, 23 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index fcfb7f3..57d0110 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2006-05-30 Mark Mitchell <mark@codesourcery.com> + PR c++/27808 + * parser.c (cp_parser_decl_specifier_seq): Issue errors about + "friend" specifiers that do not appear in class scopes. + PR c++/27803 * class.c (check_bitfield_decl): Ensure that all bitfields have integral type. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 60a53c8..98d4c5e 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -7425,9 +7425,17 @@ cp_parser_decl_specifier_seq (cp_parser* parser, /* decl-specifier: friend */ case RID_FRIEND: - ++decl_specs->specs[(int) ds_friend]; - /* Consume the token. */ - cp_lexer_consume_token (parser->lexer); + if (!at_class_scope_p ()) + { + error ("%<friend%> used outside of class"); + cp_lexer_purge_token (parser->lexer); + } + else + { + ++decl_specs->specs[(int) ds_friend]; + /* Consume the token. */ + cp_lexer_consume_token (parser->lexer); + } break; /* function-specifier: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3b8f323..6946b7d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2006-05-30 Mark Mitchell <mark@codesourcery.com> + + PR c++/27808 + * g++.dg/parse/friend6.C: New test. + 2006-05-30 Asher Langton <langton2@llnl.gov> * gfortran.dg/cray_pointers_7.f90: New test. diff --git a/gcc/testsuite/g++.dg/parse/friend6.C b/gcc/testsuite/g++.dg/parse/friend6.C new file mode 100644 index 0000000..2d13606 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/friend6.C @@ -0,0 +1,3 @@ +// PR c++/27808 + +template<typename T> friend void T::foo; // { dg-error "friend|invalid" } |