With lambdas, we can have a function body inside a default argument, so we need to clear parser->local_variables_forbidden_p.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit bdbb09d8c20e71b3e4a023fd1bf49005a59b03a7
Author: Jason Merrill <ja...@redhat.com>
Date:   Tue Aug 2 16:22:24 2011 -0400

    	PR c++/43886
    	* parser.c (cp_parser_lambda_body): Clear local_variables_forbidden_p.

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 2d8f457..9b3e56d 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -7801,12 +7801,15 @@ static void
 cp_parser_lambda_body (cp_parser* parser, tree lambda_expr)
 {
   bool nested = (current_function_decl != NULL_TREE);
+  bool local_variables_forbidden_p = parser->local_variables_forbidden_p;
   if (nested)
     push_function_context ();
   else
     /* Still increment function_depth so that we don't GC in the
        middle of an expression.  */
     ++function_depth;
+  /* Clear this in case we're in the middle of a default argument.  */
+  parser->local_variables_forbidden_p = false;
 
   /* Finish the function call operator
      - class_specifier
@@ -7904,6 +7907,7 @@ cp_parser_lambda_body (cp_parser* parser, tree lambda_expr)
     expand_or_defer_fn (finish_function (/*inline*/2));
   }
 
+  parser->local_variables_forbidden_p = local_variables_forbidden_p;
   if (nested)
     pop_function_context();
   else
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-defarg2.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-defarg2.C
new file mode 100644
index 0000000..f47c5ba
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-defarg2.C
@@ -0,0 +1,7 @@
+// PR c++/43886
+// { dg-options -std=c++0x }
+
+void f2() {
+  int i = 1;
+  void g5(int = ([]{ return sizeof i; })());
+}

Reply via email to