re PR c++/50080 ([DR 468] error: 'template' (as a disambiguator) is only allowed...
authorPaolo Carlini <paolo.carlini@oracle.com>
Mon, 15 Oct 2012 16:47:52 +0000 (16:47 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Mon, 15 Oct 2012 16:47:52 +0000 (16:47 +0000)
/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.

From-SVN: r192465

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/tmpl-outside1.C
gcc/testsuite/g++.dg/parse/tmpl-outside2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/qualttp18.C
gcc/testsuite/g++.old-deja/g++.pt/memtemp87.C
gcc/testsuite/g++.old-deja/g++.pt/overload13.C

index 6621c114899d6b98cf45704c398531780c593fd3..5239e7e33cff02524325a694fb9506e7fe719acd 100644 (file)
@@ -1,3 +1,9 @@
+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.
+
 2012-10-14  Jason Merrill  <jason@redhat.com>
            Ville Voutilainen  <ville.voutilainen@gmail.com>
 
index a7939c87647dbfde8ae761205e7c3b9d60aaafeb..965bc6212771b06fcb798c568849a6f3bf0d95a0 100644 (file)
@@ -23252,29 +23252,10 @@ cp_parser_optional_template_keyword (cp_parser *parser)
 {
   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;
 }
 
index 74e7b1c3fd62c959d9b09045e06dafff36d0ddf8..38055629b881e3f0bfb328a392fceef1e6d12769 100644 (file)
@@ -1,3 +1,12 @@
+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.
+
 2012-10-15  Marc Glisse  <marc.glisse@inria.fr>
 
        PR tree-optimization/54915
index e63e3cd44129c39857fd0bfca6a2fef47934d72a..0713f170aa08ae2a387c71af8755479ad48d908b 100644 (file)
@@ -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;
diff --git a/gcc/testsuite/g++.dg/parse/tmpl-outside2.C b/gcc/testsuite/g++.dg/parse/tmpl-outside2.C
new file mode 100644 (file)
index 0000000..d35656f
--- /dev/null
@@ -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 31dfa6a83d052e2c5c721a5a76a0be42a381a4e5..b4d28da5980530208363825910738d4667d24777 100644 (file)
@@ -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 99b4cd384fbb0553a08472c540a2047db4b7fcd5..2554518b4b4c63c50024007dd5c8f203eb8afc84 100644 (file)
@@ -12,5 +12,4 @@ public:
 template<template<class> class>
 class Y {
 };
-Q::template X<int> x; // { dg-error "" } template syntax
-
+Q::template X<int> x;
index f66f1038c7c1e5befe78a403666eff82384b0d6f..78a5e6d6ab82198490a9c8a75deede21fae85ae9 100644 (file)
@@ -7,5 +7,5 @@ struct A {
 int main ()
 {
   A a;
-  return a.template f (0); // { dg-error "" } 
+  return a.template f (0);
 }