diff mbox

[C++] PR 50080

Message ID 507C26A1.4060001@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Oct. 15, 2012, 3:07 p.m. UTC
Hi,

thus, if I understand correctly the resolution of Core/468 [CD1], we can 
simplify a bit the parser and just accept these 'template' outside 
templates. Tested x86_64-linux.

Thanks,
Paolo.

///////////////////////
/cp
2012-10-15  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/50080
	* parser.c (cp_parser_optional_template_keyword): Implement
	Core/468, allow outside template.

/testsuite
2012-10-15  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/50080
	* g++.dg/parse/tmpl-outside2.C: New.
	* g++.dg/parse/tmpl-outside1.C: Adjust.
	* g++.dg/template/qualttp18.C: Likewise.
	* g++.old-deja/g++.pt/memtemp87.C: Likewise.
	* g++.old-deja/g++.pt/overload13.C: Likewise.

Comments

Jason Merrill Oct. 15, 2012, 4:29 p.m. UTC | #1
OK.

Jason
Jason Merrill Oct. 15, 2012, 5:30 p.m. UTC | #2
Actually, let's keep the diagnostic when compiling with -pedantic in 98 
mode.

Jason
diff mbox

Patch

Index: testsuite/g++.old-deja/g++.pt/memtemp87.C
===================================================================
--- testsuite/g++.old-deja/g++.pt/memtemp87.C	(revision 192455)
+++ testsuite/g++.old-deja/g++.pt/memtemp87.C	(working copy)
@@ -12,5 +12,4 @@  class Q {
 template<template<class> class>
 class Y {
 };
-Q::template X<int> x; // { dg-error "" } template syntax
-
+Q::template X<int> x;
Index: testsuite/g++.old-deja/g++.pt/overload13.C
===================================================================
--- testsuite/g++.old-deja/g++.pt/overload13.C	(revision 192455)
+++ testsuite/g++.old-deja/g++.pt/overload13.C	(working copy)
@@ -7,5 +7,5 @@  struct A {
 int main ()
 {
   A a;
-  return a.template f (0); // { dg-error "" } 
+  return a.template f (0);
 }
Index: testsuite/g++.dg/parse/tmpl-outside2.C
===================================================================
--- testsuite/g++.dg/parse/tmpl-outside2.C	(revision 0)
+++ testsuite/g++.dg/parse/tmpl-outside2.C	(working copy)
@@ -0,0 +1,19 @@ 
+// PR c++/50080
+
+template <typename T>
+struct A
+{
+  template <typename U>
+  struct B {};
+};
+
+template <typename T>
+void test()
+{
+  typename A<T>::template B<int> b;
+}
+
+int main()
+{
+  typename A<double>::template B<int> b;
+}
Index: testsuite/g++.dg/parse/tmpl-outside1.C
===================================================================
--- testsuite/g++.dg/parse/tmpl-outside1.C	(revision 192455)
+++ testsuite/g++.dg/parse/tmpl-outside1.C	(working copy)
@@ -7,4 +7,4 @@  struct X
    template <int i> struct Y {};
 };
 
-typedef X::template Y<0> y; // { dg-error "template|invalid" }
+typedef X::template Y<0> y;
Index: testsuite/g++.dg/template/qualttp18.C
===================================================================
--- testsuite/g++.dg/template/qualttp18.C	(revision 192455)
+++ testsuite/g++.dg/template/qualttp18.C	(working copy)
@@ -14,7 +14,7 @@  template <template <class> class TT> struct X
 
 struct C
 {
-	X<A::template B> x; // { dg-error "" }
+	X<A::template B> x;
 };
 
 int main()
Index: cp/parser.c
===================================================================
--- cp/parser.c	(revision 192455)
+++ cp/parser.c	(working copy)
@@ -23252,29 +23252,10 @@  cp_parser_optional_template_keyword (cp_parser *pa
 {
   if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TEMPLATE))
     {
-      /* The `template' keyword can only be used within templates;
-	 outside templates the parser can always figure out what is a
-	 template and what is not.  */
-      if (!processing_template_decl)
-	{
-	  cp_token *token = cp_lexer_peek_token (parser->lexer);
-	  error_at (token->location,
-		    "%<template%> (as a disambiguator) is only allowed "
-		    "within templates");
-	  /* If this part of the token stream is rescanned, the same
-	     error message would be generated.  So, we purge the token
-	     from the stream.  */
-	  cp_lexer_purge_token (parser->lexer);
-	  return false;
-	}
-      else
-	{
-	  /* Consume the `template' keyword.  */
-	  cp_lexer_consume_token (parser->lexer);
-	  return true;
-	}
+      /* Consume the `template' keyword.  */
+      cp_lexer_consume_token (parser->lexer);
+      return true;
     }
-
   return false;
 }