re PR c++/37875 ([c++0x] misinterpreted closing angle bracket in decltype operand)
authorJason Merrill <jason@redhat.com>
Mon, 12 Oct 2009 21:04:35 +0000 (17:04 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 12 Oct 2009 21:04:35 +0000 (17:04 -0400)
PR c++/37875
* parser.c (cp_parser_decltype): Set greater_than_is_operator_p.

From-SVN: r152686

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/decltype18.C [new file with mode: 0644]

index 07dc96ae8262aebc5d2cde77eef07a0b80b8895d..7765c73b9de63261061e805de7eda831a63bf8de 100644 (file)
@@ -1,5 +1,8 @@
 2009-10-12  Jason Merrill  <jason@redhat.com>
 
+       PR c++/37875
+       * parser.c (cp_parser_decltype): Set greater_than_is_operator_p.
+
        PR c++/37766
        * pt.c (type_unification_real): Call convert_template_argument
        for function default template arguments.
index 44dceb21f745d2276f5cc4aafbd5bc75147503bb..5e37343294b5ec50b5a208906f10dcd3802680f8 100644 (file)
@@ -9541,12 +9541,25 @@ cp_parser_decltype (cp_parser *parser)
     cp_parser_parse_definitely (parser);
   else
     {
+      bool saved_greater_than_is_operator_p;
+
       /* Abort our attempt to parse an id-expression or member access
          expression.  */
       cp_parser_abort_tentative_parse (parser);
 
+      /* Within a parenthesized expression, a `>' token is always
+        the greater-than operator.  */
+      saved_greater_than_is_operator_p
+       = parser->greater_than_is_operator_p;
+      parser->greater_than_is_operator_p = true;
+
       /* Parse a full expression.  */
       expr = cp_parser_expression (parser, /*cast_p=*/false, NULL);
+
+      /* The `>' token might be the end of a template-id or
+        template-parameter-list now.  */
+      parser->greater_than_is_operator_p
+       = saved_greater_than_is_operator_p;
     }
 
   /* Go back to evaluating expressions.  */
index e9ca25b8e526198167c60abc8c5ba6fa70102aa5..32b2ea4f8b40e92a24da2e45ebf5d4a7e52b0620 100644 (file)
@@ -1,5 +1,8 @@
 2009-10-12  Jason Merrill  <jason@redhat.com>
 
+       PR c++/37875
+       * g++.dg/cpp0x/decltype18.C: New.
+
        PR c++/37766
        * g++.dg/cpp0x/fntmpdefarg1.C: New.
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype18.C b/gcc/testsuite/g++.dg/cpp0x/decltype18.C
new file mode 100644 (file)
index 0000000..0d44586
--- /dev/null
@@ -0,0 +1,5 @@
+// PR c++/37875
+// { dg-options "-std=c++0x" }
+
+template <typename> struct X {};
+X<decltype(1 > 2)> x;