This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: PR 27808
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 30 May 2006 18:19:40 -0700
- Subject: C++ PATCH: PR 27808
- Reply-to: mark at codesourcery dot com
This patch fixes PR c++/27808, where we got confused by a "friend"
declaration at global scope. We can just zap the bogus specified in
the parser, which again avoids the rest of the front end seeing
representations of invalid C++.
Tested on x86_64-uknown-linux-gnu, applied on the mainline.
--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713
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.
2006-05-30 Mark Mitchell <mark@codesourcery.com>
PR c++/27808
* g++.dg/parse/friend6.C: New test.
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c (revision 114244)
+++ gcc/cp/parser.c (working copy)
@@ -7425,9 +7425,17 @@ cp_parser_decl_specifier_seq (cp_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: gcc/testsuite/g++.dg/parse/friend6.C
===================================================================
--- gcc/testsuite/g++.dg/parse/friend6.C (revision 0)
+++ gcc/testsuite/g++.dg/parse/friend6.C (revision 0)
@@ -0,0 +1,3 @@
+// PR c++/27808
+
+template<typename T> friend void T::foo; // { dg-error "friend|invalid" }