Patchwork C++ PATCH for c++/52725 (bogus lambda error with array new)

login
register
mail settings
Submitter Jason Merrill
Date June 1, 2012, 9:17 p.m.
Message ID <4FC93181.7080304@redhat.com>
Download mbox | patch
Permalink /patch/162375/
State New
Headers show

Comments

Jason Merrill - June 1, 2012, 9:17 p.m.
When parsing a new-expression, we first try to parse a new-placement 
before the type.  In this case, the tokens don't make a valid 
expression, but we were still trying to parse [n] as a 
lambda-introducer.  Fixed by bailing out of cp_parser_binary_expression 
sooner if we encounter a parse error while parsing tentatively.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.7.

Patch

commit 17ee6c495d4ab68f1de3d17bceb5f344c1491642
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Jun 1 14:53:46 2012 -0400

    	PR c++/52725
    	* parser.c (cp_parser_binary_expression): Bail early if we're parsing
    	tentatively and the LHS has a parse error.

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 547f9e2..7f9a94b 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -7246,6 +7246,9 @@  cp_parser_binary_expression (cp_parser* parser, bool cast_p,
   current.lhs_type = ERROR_MARK;
   current.prec = prec;
 
+  if (cp_parser_error_occurred (parser))
+    return error_mark_node;
+
   for (;;)
     {
       /* Get an operator token.  */
diff --git a/gcc/testsuite/g++.dg/parse/new6.C b/gcc/testsuite/g++.dg/parse/new6.C
new file mode 100644
index 0000000..213837c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/new6.C
@@ -0,0 +1,10 @@ 
+// PR c++/52725
+
+struct A { };
+
+const int n = 42;
+
+void f()
+{
+  A** p = new (A*[n]);
+}
diff --git a/gcc/testsuite/g++.dg/template/sizeof-template-argument.C b/gcc/testsuite/g++.dg/template/sizeof-template-argument.C
index 2cdc328..31aeeec 100644
--- a/gcc/testsuite/g++.dg/template/sizeof-template-argument.C
+++ b/gcc/testsuite/g++.dg/template/sizeof-template-argument.C
@@ -3,9 +3,9 @@ 
 
 template<int> struct A {};
 
-template<typename> struct B : A <sizeof(=)> {}; /* { dg-error "parse error in template argument list" } */
+template<typename> struct B : A <sizeof(=)> {}; /* { dg-error "template argument" } */
 
-template<typename> struct C : A <sizeof(=)> {}; /* { dg-error "parse error in template argument list" } */
+template<typename> struct C : A <sizeof(=)> {}; /* { dg-error "template argument" } */
 
 int a;