diff mbox

[C++] PR 61804

Message ID 53C698A7.6040003@oracle.com
State New
Headers show

Commit Message

Paolo Carlini July 16, 2014, 3:22 p.m. UTC
Hi,

Richard Smith noticed another case, like '[' in C++11, where we want to 
keep the parsing uncommitted after the parenthesized type-id. Tested 
x86_64-linux.

Thanks,
Paolo.

/////////////////////
/cp
2014-07-16  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/61804
	* parser.c (cp_parser_tokens_start_cast_expression): Return -1
	for '++' and '--'.

/testsuite
2014-07-16  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/61804
	* g++.dg/parse/pr61804.C: New.

Comments

Jason Merrill July 17, 2014, 12:42 a.m. UTC | #1
OK.

Jason
diff mbox

Patch

Index: cp/parser.c
===================================================================
--- cp/parser.c	(revision 212581)
+++ cp/parser.c	(working copy)
@@ -7700,8 +7700,8 @@  cp_parser_delete_expression (cp_parser* parser)
 			tf_warning_or_error);
 }
 
-/* Returns 1 if TOKEN may start a cast-expression and, in C++11,
-   isn't '[', -1 if TOKEN is '[' in C++11, 0 otherwise.  */
+/* Returns 1 if TOKEN may start a cast-expression and, in C++11, isn't '[';
+   -1 if TOKEN is '++', '--', or '[' in C++11; 0 otherwise.  */
 
 static int
 cp_parser_tokens_start_cast_expression (cp_parser *parser)
@@ -7755,13 +7755,26 @@  cp_parser_tokens_start_cast_expression (cp_parser
       return cp_lexer_peek_nth_token (parser->lexer, 2)->type
 	     != CPP_CLOSE_PAREN;
 
+    case CPP_OPEN_SQUARE:
       /* '[' may start a primary-expression in obj-c++ and in C++11,
 	 as a lambda-expression, eg, '(void)[]{}'.  */
-    case CPP_OPEN_SQUARE:
       if (cxx_dialect >= cxx11)
 	return -1;
       return c_dialect_objc ();
 
+    case CPP_PLUS_PLUS:
+    case CPP_MINUS_MINUS:
+      /* '++' and '--' may or may not start a cast-expression:
+
+	 struct T { void operator++(int); };
+	 void f() { (T())++; }
+
+	 vs
+
+	 int a;
+	 (int)++a;  */
+      return -1;
+
     default:
       return 1;
     }
@@ -7874,8 +7887,8 @@  cp_parser_cast_expression (cp_parser *parser, bool
 	 function returning T.  */
       if (!cp_parser_error_occurred (parser))
 	{
-	  /* Only commit if the cast-expression doesn't start with '[' in
-	     C++11, which may or may not start a lambda-expression.  */
+	  /* Only commit if the cast-expression doesn't start with
+	     '++', '--', or '[' in C++11.  */
 	  if (cast_expression > 0)
 	    cp_parser_commit_to_topmost_tentative_parse (parser);
 
Index: testsuite/g++.dg/parse/pr61804.C
===================================================================
--- testsuite/g++.dg/parse/pr61804.C	(revision 0)
+++ testsuite/g++.dg/parse/pr61804.C	(working copy)
@@ -0,0 +1,9 @@ 
+// PR c++/61804
+
+struct T { void operator++(int); };
+void f() { (T())++; }
+
+struct U { void operator--(int); };
+void g() { (U())--; }
+
+void h() { int a; (int)++a; (int)--a; }