This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH: PR 27808


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" }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]