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]

Re: [PATCH c++] Fix pr22138


On 06/10/2010 03:44 PM, Gabriel Dos Reis wrote:
On Thu, Jun 10, 2010 at 1:40 AM, Shujing Zhao <pearly.zhao@oracle.com> wrote:
Hi,

This patch is to fix pr22138. It would error "local template declarations is
not allowed" instead of "expected primary-expression before 'template'".

that isn't grammatically correct. What about


a template declaration cannot appear at block scope
Ok. Fix the message.

Also why don't you use the function at_function_scope_p() to test whether you are at local scope?
The parser itself know whether or not it is in the body of a function. The in_funtion_body is also more efficient that calling at_function_scope_p. I think using parser->in_function_body is better than at_function_scope_p.
Is it ok?


Thanks
Pearly

Index: cp/parser.c
===================================================================
--- cp/parser.c	(revision 160431)
+++ cp/parser.c	(working copy)
@@ -3754,6 +3754,14 @@ cp_parser_primary_expression (cp_parser 
 	case RID_AT_SELECTOR:
 	  return cp_parser_objc_expression (parser);
 
+	case RID_TEMPLATE:
+	  if (parser->in_function_body)
+	    {
+	      error_at (token->location,
+			"a template declaration cannot appear at block scope");
+	      cp_parser_skip_to_end_of_block_or_statement (parser);
+	      return error_mark_node;
+	    }
 	default:
 	  cp_parser_error (parser, "expected primary-expression");
 	  return error_mark_node;
Index: testsuite/g++.dg/parse/template25.C
===================================================================
--- testsuite/g++.dg/parse/template25.C	(revision 0)
+++ testsuite/g++.dg/parse/template25.C	(revision 0)
@@ -0,0 +1,8 @@
+// PR c++/22318
+// { dg-do compile }
+void f(void)
+{
+  template<typename T> class A /* { dg-error "a template declaration cannot appear at block scope" } */
+  {
+  };
+}

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