PR c++/50080 (again)
authorPaolo Carlini <paolo.carlini@oracle.com>
Mon, 15 Oct 2012 19:13:41 +0000 (19:13 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Mon, 15 Oct 2012 19:13:41 +0000 (19:13 +0000)
/cp
2012-10-15  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/50080 (again)
* parser.c (cp_parser_optional_template_keyword): When -pedantic
and C++98 mode restore pre-Core/468 behavior.

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

PR c++/50080 (again)
* g++.dg/parse/tmpl-outside2.C: Tweak, error in C++98.
* g++.dg/parse/tmpl-outside1.C: Likewise.
* g++.dg/template/qualttp18.C: Likewise.
* g++.old-deja/g++.pt/memtemp87.C: Likewise.
* g++.old-deja/g++.pt/overload13.C: Likewise.

From-SVN: r192470

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
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 5239e7e33cff02524325a694fb9506e7fe719acd..555345f58a800a24546bdf87271767b4eb0ff459 100644 (file)
@@ -1,3 +1,9 @@
+2012-10-15  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/50080 (again)
+       * parser.c (cp_parser_optional_template_keyword): When -pedantic
+       and C++98 mode restore pre-Core/468 behavior.
+
 2012-10-15  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/50080
index 965bc6212771b06fcb798c568849a6f3bf0d95a0..853d789f987f412331fd4736e9386bc64b229cb9 100644 (file)
@@ -23252,9 +23252,29 @@ cp_parser_optional_template_keyword (cp_parser *parser)
 {
   if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TEMPLATE))
     {
-      /* Consume the `template' keyword.  */
-      cp_lexer_consume_token (parser->lexer);
-      return true;
+      /* In C++98 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.  In C++11,  per the resolution of DR 468,
+        `template' is allowed in cases where it is not strictly necessary.  */
+      if (!processing_template_decl
+         && pedantic && cxx_dialect == cxx98)
+       {
+         cp_token *token = cp_lexer_peek_token (parser->lexer);
+         pedwarn (token->location, OPT_Wpedantic,
+                  "in C++98 %<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;
+       }
     }
   return false;
 }
index ea4a46fa454b9139cde6cd5a25adb6c966f0ed62..99c7a70676a382f57a38a41f1d76131d468d528e 100644 (file)
@@ -1,3 +1,12 @@
+2012-10-15  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/50080 (again)
+       * g++.dg/parse/tmpl-outside2.C: Tweak, error in C++98.
+       * g++.dg/parse/tmpl-outside1.C: Likewise.
+       * 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  Uros Bizjak  <ubizjak@gmail.com>
 
        * gcc.target/i386/avx256-unaligned-load-1.c: Update asm scan patterns.
index 0713f170aa08ae2a387c71af8755479ad48d908b..7d969e46858d7ba5e5f96ad1ec7d231183e8edeb 100644 (file)
@@ -7,4 +7,4 @@ struct X
    template <int i> struct Y {};
 };
 
-typedef X::template Y<0> y;
+typedef X::template Y<0> y; // { dg-error "template|invalid" "" { target c++98 } }
index d35656f609ecd8a3570e40e9361b77297a1fcf59..54d39fa88dba944a3e9d4455e1335042188acfaf 100644 (file)
@@ -15,5 +15,5 @@ void test()
 
 int main()
 {
-  typename A<double>::template B<int> b;
+  typename A<double>::template B<int> b; // { dg-error "template|expected" "" { target c++98 } }
 }
index b4d28da5980530208363825910738d4667d24777..691517fd3723135230c102173dae36472502b24e 100644 (file)
@@ -14,7 +14,7 @@ template <template <class> class TT> struct X
 
 struct C
 {
-       X<A::template B> x;
+       X<A::template B> x;  // { dg-error "template" "" { target c++98 } }
 };
 
 int main()
index 2554518b4b4c63c50024007dd5c8f203eb8afc84..51a66fd41164f7db16fa253f78d78bf407d8b18d 100644 (file)
@@ -12,4 +12,4 @@ public:
 template<template<class> class>
 class Y {
 };
-Q::template X<int> x;
+Q::template X<int> x; // { dg-error "template" "" { target c++98 } }
index 78a5e6d6ab82198490a9c8a75deede21fae85ae9..9c985141fd872879ec4c3512b6f35d75081e5928 100644 (file)
@@ -7,5 +7,5 @@ struct A {
 int main ()
 {
   A a;
-  return a.template f (0);
+  return a.template f (0); // { dg-error "template" "" { target c++98 } }
 }