Hi,

Andrew noticed that the reason we reject entities like inline-asm or GNU's statement-expressions in the lambda body is simply that we don't set the parser->in_function_body flag. Thus the below, which appears to work perfectly for that. Tested x86_64-linux.

Thanks, Paolo.

///////////////////


/cp
2017-10-04  Paolo Carlini  <paolo.carl...@oracle.com>
            Andrew Pinski  <apin...@cavium.com>

        PR c++/71946
        * parser.c (cp_parser_lambda_body): Set parser->in_function_body.

/testsuite
2017-10-04  Paolo Carlini  <paolo.carl...@oracle.com>
            Andrew Pinski  <apin...@cavium.com>

        PR c++/71946
        * g++.dg/cpp0x/lambda/lambda-asm1.C: New.
        * g++.dg/cpp0x/lambda/lambda-stmtexpr1.C: Likewise.
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 253398)
+++ cp/parser.c (working copy)
@@ -10557,6 +10557,7 @@ cp_parser_lambda_body (cp_parser* parser, tree lam
 {
   bool nested = (current_function_decl != NULL_TREE);
   bool local_variables_forbidden_p = parser->local_variables_forbidden_p;
+  bool in_function_body = parser->in_function_body;
   if (nested)
     push_function_context ();
   else
@@ -10567,6 +10568,7 @@ cp_parser_lambda_body (cp_parser* parser, tree lam
   save_omp_privatization_clauses (omp_privatization_save);
   /* Clear this in case we're in the middle of a default argument.  */
   parser->local_variables_forbidden_p = false;
+  parser->in_function_body = true;
 
   /* Finish the function call operator
      - class_specifier
@@ -10653,6 +10655,7 @@ cp_parser_lambda_body (cp_parser* parser, tree lam
 
   restore_omp_privatization_clauses (omp_privatization_save);
   parser->local_variables_forbidden_p = local_variables_forbidden_p;
+  parser->in_function_body = in_function_body;
   if (nested)
     pop_function_context();
   else
Index: testsuite/g++.dg/cpp0x/lambda/lambda-asm1.C
===================================================================
--- testsuite/g++.dg/cpp0x/lambda/lambda-asm1.C (revision 0)
+++ testsuite/g++.dg/cpp0x/lambda/lambda-asm1.C (working copy)
@@ -0,0 +1,4 @@
+// PR c++/71946
+// { dg-do compile { target c++11 } }
+
+auto test = []{ __asm__ __volatile__ ("" : : "r" (0) ); };
Index: testsuite/g++.dg/cpp0x/lambda/lambda-stmtexpr1.C
===================================================================
--- testsuite/g++.dg/cpp0x/lambda/lambda-stmtexpr1.C    (revision 0)
+++ testsuite/g++.dg/cpp0x/lambda/lambda-stmtexpr1.C    (working copy)
@@ -0,0 +1,5 @@
+// PR c++/71946
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+auto test = []{ int t = ({ int t1; t1 = 7; t1; }); };

Reply via email to