diff mbox

C++ PATCH for c++/46159 (bogus lambda pedwarn with array in new-expression)

Message ID 4D6E7764.1020204@redhat.com
State New
Headers show

Commit Message

Jason Merrill March 2, 2011, 4:59 p.m. UTC
We shouldn't complain about use of lambdas just because we see a [ in a 
place that could be an expression.  In this case, we tentatively try to 
parse something in parens after "new" as a new-placement before failing 
and trying again as a type-id.

Tested x86_64-pc-linux-gnu, applied to trunk.
commit 791c8f38f6a4673070c490c74d03e0ac93687142
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Mar 1 17:58:33 2011 -0500

    	PR c++/46159
    	* parser.c (cp_parser_primary_expression): Don't warn about a
    	failed tentative parse.
diff mbox

Patch

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 314a2ff..c63d5b3 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -3712,8 +3712,14 @@  cp_parser_primary_expression (cp_parser *parser,
       if (c_dialect_objc ())
         /* We have an Objective-C++ message. */
         return cp_parser_objc_expression (parser);
-      maybe_warn_cpp0x (CPP0X_LAMBDA_EXPR);
-      return cp_parser_lambda_expression (parser);
+      {
+	tree lam = cp_parser_lambda_expression (parser);
+	/* Don't warn about a failed tentative parse.  */
+	if (cp_parser_error_occurred (parser))
+	  return error_mark_node;
+	maybe_warn_cpp0x (CPP0X_LAMBDA_EXPR);
+	return lam;
+      }
 
     case CPP_OBJC_STRING:
       if (c_dialect_objc ())
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-98.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-98.C
new file mode 100644
index 0000000..ff1085f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-98.C
@@ -0,0 +1,8 @@ 
+// PR c++/46159
+// { dg-options -std=c++98 }
+
+void
+f()
+{
+  int **p = new(int(*[2]));
+}