This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH to cp_parser_decltype for c++/37875


The operand of decltype is enclosed in parens, making a > unambiguous, but the parser wasn't adjusting greater_than_is_operator_p when consuming the parens the way, say, cp_parser_primary_expression does.

Tested x86_64-pc-linux-gnu, applied to trunk.
commit 0a831a5d2e6eb37509a780f937987c114fb592be
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Oct 12 01:53:04 2009 -0400

    	PR c++/37875
    	* parser.c (cp_parser_decltype): Set greater_than_is_operator_p.

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 44dceb2..5e37343 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -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.  */
diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype18.C b/gcc/testsuite/g++.dg/cpp0x/decltype18.C
new file mode 100644
index 0000000..0d44586
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/decltype18.C
@@ -0,0 +1,5 @@
+// PR c++/37875
+// { dg-options "-std=c++0x" }
+
+template <typename> struct X {};
+X<decltype(1 > 2)> x;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]