re PR c++/27808 (ICE with invalid friend declaration)
authorMark Mitchell <mark@codesourcery.com>
Wed, 31 May 2006 01:18:24 +0000 (01:18 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Wed, 31 May 2006 01:18:24 +0000 (01:18 +0000)
PR c++/27808
* parser.c (cp_parser_decl_specifier_seq): Issue errors about
"friend" specifiers that do not appear in class scopes.
PR c++/27808
* g++.dg/parse/friend6.C: New test.

From-SVN: r114259

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/friend6.C [new file with mode: 0644]

index fcfb7f30a615b7c00597d7006fe3f1862de57ba0..57d01106da320fe79f4be2fa2090e64719efc984 100644 (file)
@@ -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.
index 60a53c8076adcb5fb9aa23ae4835657b5a1c3e1e..98d4c5eedb9fe7b98bed85a691cb0e870262df10 100644 (file)
@@ -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:
index 3b8f323ba73b281fa4e99ada82a4057f9b28688e..6946b7d89dadc734276da7bc21f8777a714e1436 100644 (file)
@@ -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 (file)
index 0000000..2d13606
--- /dev/null
@@ -0,0 +1,3 @@
+// PR c++/27808
+
+template<typename T> friend void T::foo; // { dg-error "friend|invalid" }