re PR c++/36460 (No space between >'s not always handled in C++0x)
authorDouglas Gregor <doug.gregor@gmail.com>
Wed, 6 Aug 2008 19:08:12 +0000 (19:08 +0000)
committerDoug Gregor <dgregor@gcc.gnu.org>
Wed, 6 Aug 2008 19:08:12 +0000 (19:08 +0000)
2008-08-06  Douglas Gregor  <doug.gregor@gmail.com>

       PR c++/36460
       * parser.c (cp_parser_template_argument): Don't assume that '>>'
       following a type-id is an error when in C++0x mode.

2008-08-06  Douglas Gregor  <doug.gregor@gmail.com>

       PR c++/36460
       * g++.dg/cpp0x/bracket3.C: Add another test case for the >>
       warning under -Wc++0x-compat.
       * g++.dg/cpp0x/bracket4.C: Add testcase for PR c++/36460.

From-SVN: r138819

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/bracket3.C
gcc/testsuite/g++.dg/cpp0x/bracket4.C

index 4dfd564a7ec582fbf7d50ebd5bdd24c2d1eceae5..7bf5f014e2a305eaff93e6320a90c7aac607164d 100644 (file)
@@ -1,3 +1,9 @@
+2008-08-06  Douglas Gregor  <doug.gregor@gmail.com>
+
+       PR c++/36460
+       * parser.c (cp_parser_template_argument): Don't assume that '>>'
+       following a type-id is an error when in C++0x mode.
+       
 2008-08-06  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
 
        PR 26785
index 76adb633ed7639cb6bc63e704644bd1be3f99b4e..7c1b04d5d04fc3cc38a79a677eb2ac624f29131d 100644 (file)
@@ -10386,9 +10386,10 @@ cp_parser_template_argument (cp_parser* parser)
      Therefore, we try a type-id first.  */
   cp_parser_parse_tentatively (parser);
   argument = cp_parser_type_id (parser);
-  /* If there was no error parsing the type-id but the next token is a '>>',
-     we probably found a typo for '> >'. But there are type-id which are
-     also valid expressions. For instance:
+  /* If there was no error parsing the type-id but the next token is a
+     '>>', our behavior depends on which dialect of C++ we're
+     parsing. In C++98, we probably found a typo for '> >'. But there
+     are type-id which are also valid expressions. For instance:
 
      struct X { int operator >> (int); };
      template <int V> struct Foo {};
@@ -10397,8 +10398,12 @@ cp_parser_template_argument (cp_parser* parser)
      Here 'X()' is a valid type-id of a function type, but the user just
      wanted to write the expression "X() >> 5". Thus, we remember that we
      found a valid type-id, but we still try to parse the argument as an
-     expression to see what happens.  */
+     expression to see what happens. 
+
+     In C++0x, the '>>' will be considered two separate '>'
+     tokens.  */
   if (!cp_parser_error_occurred (parser)
+      && cxx_dialect == cxx98
       && cp_lexer_next_token_is (parser->lexer, CPP_RSHIFT))
     {
       maybe_type_id = true;
index e53ea0b28148ff1310e92c48c1fde620a2183554..b1833996aec67822af1b624b73fd60884c1f8f53 100644 (file)
@@ -1,3 +1,10 @@
+2008-08-06  Douglas Gregor  <doug.gregor@gmail.com>
+
+       PR c++/36460
+       * g++.dg/cpp0x/bracket3.C: Add another test case for the >>
+       warning under -Wc++0x-compat.
+       * g++.dg/cpp0x/bracket4.C: Add testcase for PR c++/36460.
+
 2008-08-06  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
 
        * gcc.dg/Wcxx-compat-2.c: Adjust test for more warnings.
index eb1ef02297d56bf5375e70d74777adf189ef9e4e..4ef7a0e9d3027cd69fcd46d15e5def1bbbc9b330 100644 (file)
@@ -3,3 +3,8 @@
 template<int N> struct X {};
 
 X<1 >> 2> x; // { dg-warning "will be treated as|suggest parentheses" }
+
+// From cp/parser.c
+typedef int Y;
+template <int V> struct Foo {};
+Foo<Y () >> 5> r; // { dg-warning "will be treated as|suggest parentheses" }
index 2ac5ff3d734488ba8765ace6ae72d9eb67c1d671..c0743fb7ff5c3c915342cb3cc3579babe570b0ab 100644 (file)
@@ -1,6 +1,5 @@
 // { dg-do "compile" }
 // { dg-options "-std=c++0x" }
-
 template<typename T>
 struct vector { 
 };
@@ -25,3 +24,12 @@ void f()
 {
   vector<vector<int>>() + 2;
 }
+
+// PR c++/36460
+template <class a>
+class A {};
+template <class b>
+class B {};
+
+A<B<void()>> x;
+