https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104765

--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
The attached patch disables ({}) in lambda param list, which fixes the bug, but
also makes things less consistent:

void G() {
  void fn (int i, int = ({ 1; }));  // currently OK
}

void g() {
  auto a = []<int = ({ 1; })>(){}; // currently OK
  a();
}

void g2() {
  auto a = [](int = ({ 1; })){};  // error with the patch
  a();
}

My preference: prohibit any use of ({}) in default arguments.

--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -5605,11 +5605,15 @@ cp_parser_primary_expression (cp_parser *parser,

         at class or namespace scope.  */
      if (!parser->in_function_body
-         || parser->in_template_argument_list_p)
+         || parser->in_template_argument_list_p
+         || (parsing_function_declarator ()
+         && current_class_type
+         && LAMBDA_TYPE_P (current_class_type)))
        {
          error_at (token->location,
            "statement-expressions are not allowed outside "
-           "functions nor in template-argument lists");
+           "functions nor in template-argument lists or in "
+           "lambda parameter lists");
          cp_parser_skip_to_end_of_block_or_statement (parser);
          if (cp_lexer_next_token_is (parser->lexer, CPP_CLOSE_PAREN))
        cp_lexer_consume_token (parser->lexer);

Reply via email to