[{"id":3687072,"web_url":"http://patchwork.ozlabs.org/comment/3687072/","msgid":"<aftAGPVNrjEfRlNW@redhat.com>","list_archive_url":null,"date":"2026-05-06T13:20:24","subject":"Re: [PATCH] c++: deferred parsing of default arguments [PR50479]","submitter":{"id":14370,"url":"http://patchwork.ozlabs.org/api/people/14370/","name":"Marek Polacek","email":"polacek@redhat.com"},"content":"On Tue, May 05, 2026 at 09:19:12PM -0400, Marek Polacek wrote:\n> @@ -37088,11 +37132,13 @@ cp_parser_save_default_args (cp_parser* parser, tree decl)\n>  /* DEFAULT_ARG contains the saved tokens for the initializer of DECL,\n>     which is either a FIELD_DECL or PARM_DECL.  Parse it and return\n>     the result.  For a PARM_DECL, PARMTYPE is the corresponding type\n> -   from the parameter-type-list.  */\n> +   from the parameter-type-list.  If adjust_lambda_scope_p is true,\n\nThis should be \"ADJUST_LAMBDA_SCOPE_P\", fixed locally.\n\n> +   we do start_/finish_lambda_scope.  */\n\nMarek","headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=aq82AmJe;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=38.145.34.32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (1024-bit key,\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=aq82AmJe","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=redhat.com","sourceware.org; spf=pass smtp.mailfrom=redhat.com","sourceware.org; arc=none smtp.remote-ip=170.10.129.124"],"Received":["from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g9bcD5wwpz1yJq\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 06 May 2026 23:21:00 +1000 (AEST)","from vm01.sourceware.org (localhost [IPv6:::1])\n\tby sourceware.org (Postfix) with ESMTP id 9C25D4BA23E9\n\tfor <incoming@patchwork.ozlabs.org>; Wed,  6 May 2026 13:20:58 +0000 (GMT)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.129.124])\n by sourceware.org (Postfix) with ESMTP id 239604BA5439\n for <gcc-patches@gcc.gnu.org>; Wed,  6 May 2026 13:20:30 +0000 (GMT)","from mail-qv1-f72.google.com (mail-qv1-f72.google.com\n [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n us-mta-679-jvgqmHCFM6eN-HQkT14waQ-1; Wed, 06 May 2026 09:20:28 -0400","by mail-qv1-f72.google.com with SMTP id\n 6a1803df08f44-8acafc224a8so159131866d6.1\n for <gcc-patches@gcc.gnu.org>; Wed, 06 May 2026 06:20:28 -0700 (PDT)","from redhat.com ([2603:7002:1f00:31d2::1db4])\n by smtp.gmail.com with ESMTPSA id\n 6a1803df08f44-8b538b1d8b3sm203907736d6.1.2026.05.06.06.20.25\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Wed, 06 May 2026 06:20:26 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 9C25D4BA23E9","OpenDKIM Filter v2.11.0 sourceware.org 239604BA5439"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 239604BA5439","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 239604BA5439","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778073630; cv=none;\n b=aYEcI8ZqIbhqaLQZHCw/PK1vYerU488C6rGufqx44G/5N2brMhujXUx4JGfltnJPTjUrY6Y7vX9/KeXQ/iaWtGWz6CHwTuHL5bksU/BbzQHMOm3LTNWS3l04YyO9z1NfauKDNVZJ06ZkulrwFoij2piMsxV/Q+P5mkJ+CogMy9g=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1778073630; c=relaxed/simple;\n bh=lZTjIprQjsxCQVU0HtEYSHoBzGkeadNvyeOFpQdrEZo=;\n h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version;\n b=q08vy14stLTlxkkFo9o2HvtXvV1BdtrfUCLlTqp4p89gnc1l0SkaSnqS5lwdaSB7m61tcYKH61Mdq2lV3aLj/dIE2jBoGQtAq8aa4edkzntKBomyj5rPPHdCmBMqUqowVPYxSKS+yN/1ZvrEz/EkSnvpHTPdYbHzbrqYJdQVYco=","ARC-Authentication-Results":"i=1; sourceware.org;\n dkim=pass (1024-bit key, unprotected)\n header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=aq82AmJe","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1778073629;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:mime-version:mime-version:content-type:content-type:\n in-reply-to:in-reply-to:references:references;\n bh=XRoSmVInW5PQwjYlmRuC6B0fzu+uB7BuBvEgpiU3rv8=;\n b=aq82AmJe6OcDa8G4whRfhbkkLoWjPoqVB/+9NkJT1aEGDW1MbtFNTQwYgdMVc4IwtuwSvN\n nlHBmu0t+m1TVsRRy7hnBgjgKohFxt8kcTzJnoIFeo5K9oqh9e59U/94z7JMTI0QmIHiHh\n FSC3mdpjcszKqBXIGR++FBS5d+mTMJk=","X-MC-Unique":"jvgqmHCFM6eN-HQkT14waQ-1","X-Mimecast-MFC-AGG-ID":"jvgqmHCFM6eN-HQkT14waQ_1778073628","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1778073628; x=1778678428;\n h=user-agent:in-reply-to:content-disposition:mime-version:references\n :message-id:subject:to:from:date:x-gm-gg:x-gm-message-state:from:to\n :cc:subject:date:message-id:reply-to;\n bh=XRoSmVInW5PQwjYlmRuC6B0fzu+uB7BuBvEgpiU3rv8=;\n b=kkljMqQenfGSeLQ22lqSvS/Do3XT6lyHL9xWWsCbdXWHD5D2ncplEr+qG14Q5RODvU\n YmAJoqAdFJYNqdFXa/fea1S49+0kebEanglaaATRSnU+GrOIPiUZ41H0y6HQ1zHDHsq4\n biWnWRUeIO6KL4C4m0auY/ELDs2wGSA52fN92LBTo5hVEmFjYnv7DrWoq+0x1LGaO/GN\n kvKDKffl+mVqfoqtfhB5OLinI19/Jpc93BX1ETbt1WigH560oiA9kgOHLimiAdPUwvX7\n yeLzwckP41JrzrVgncayly60fuY5h8v6LQkAWURof4i78W2HaUjrl0Z3aL4dJSBYctzG\n lRBg==","X-Forwarded-Encrypted":"i=1;\n AFNElJ8vvvl5TXGu4LsK0BZRkZiYsSFzWEMrGWfcyU3cWWyx0WxQ49RqaRO0XC4eq/9oYWBOPAhkB34L9EAYOQ==@gcc.gnu.org","X-Gm-Message-State":"AOJu0YwEx/HjjdxoITf3VFmMX6mIpEjG3t3DkzulN2wxhZ5+Mc6PLuvJ\n xuvNiKpXq0qvMUiGy2krYuNMbFL7hIMw/ugfjL+rrJUQLKhK4nfXvvKiVGfsd1i5VwUfDxDJXb1\n 7HsLn5N2zxP4K6KoTglA/FCo5U68nNmZuvxY0le/MahauQqg5oDbMos0YsDk=","X-Gm-Gg":"AeBDieu5VgY48RcOC4A0sNxboDCKh2k8ccxtxtsCYbVa8ZbItcS28OZVGWUWXxkMf8W\n P7FHjmexqmRcu+aSA2oO2u4MFKv+86FbFc5DG6NWPB/ARVAx9kD2BHfM4cPKpgENVbaYe0gS7+7\n Ip5tgLDryAXHfOwOvNp6bUTCkvz9NGA+I7Mg/LhCteXg5RxheS2TezxAQX+6/hPWAfpq6G4gE+A\n EUacg9xymPosqwKYV9dRnREDXeflW3whBibstlWRLT6G8vJCRG3o4+4j92Tryo6XkbF7Z5HtOAS\n hq4ENpEmeA5KGEipSoQLznv12wjB+2g/9tfL5fO+sM9WNYtFEy+9zoYZ9xSj69LOtE1Bac512ZB\n XPeX6O9SZ+ZVP+VU=","X-Received":["by 2002:a05:6214:1312:b0:8ae:5f0f:cc80 with SMTP id\n 6a1803df08f44-8bc46cc2a05mr47409286d6.38.1778073628019;\n Wed, 06 May 2026 06:20:28 -0700 (PDT)","by 2002:a05:6214:1312:b0:8ae:5f0f:cc80 with SMTP id\n 6a1803df08f44-8bc46cc2a05mr47407756d6.38.1778073626693;\n Wed, 06 May 2026 06:20:26 -0700 (PDT)"],"Date":"Wed, 6 May 2026 09:20:24 -0400","From":"Marek Polacek <polacek@redhat.com>","To":"Jason Merrill <jason@redhat.com>, GCC Patches <gcc-patches@gcc.gnu.org>","Subject":"Re: [PATCH] c++: deferred parsing of default arguments [PR50479]","Message-ID":"<aftAGPVNrjEfRlNW@redhat.com>","References":"<20260506011912.1371228-1-polacek@redhat.com>","MIME-Version":"1.0","In-Reply-To":"<20260506011912.1371228-1-polacek@redhat.com>","User-Agent":"Mutt/2.3.1 (2026-03-20)","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"CnoSkGiFLZIp0eJiEiH-CTi3Rqfp1Cydx9KpTDpJlzk_1778073628","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"}},{"id":3687356,"web_url":"http://patchwork.ozlabs.org/comment/3687356/","msgid":"<c36fce84-b266-4996-832d-9bc2ab4d6ac7@redhat.com>","list_archive_url":null,"date":"2026-05-06T20:15:03","subject":"Re: [PATCH] c++: deferred parsing of default arguments [PR50479]","submitter":{"id":4337,"url":"http://patchwork.ozlabs.org/api/people/4337/","name":"Jason Merrill","email":"jason@redhat.com"},"content":"On 5/5/26 9:19 PM, Marek Polacek wrote:\n> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?\n> \n> Additionally tested with the \"Optimization only\" checks disabled\n> to see if it isn't hiding any errors.\n> \n> -- >8 --\n> In\n> \n>    void fn (int i = sizeof (i)) {}\n> \n> the i in sizeof should refer to the parameter ([basic.scope.pdecl]) and\n> since the second i is not evaluated, the code is valid per\n> [dcl.fct.default]/9: A parameter shall not appear as a potentially\n> evaluated expression in a default argument.\n> \n> To make this work, we have to defer parsing of the default argument\n> until we've done grokdeclarator + pushdecl on i.\n\nHow about doing that by moving grokdeclarator/pushdecl into \ncp_parser_parameter_declaration rather than mess with DEFERRED_PARSE?\n\n> Unfortunately,\n> lambdas complicated this patch somewhat.  _late_parse_one_default_arg\n> always does start_lambda_scope which here would set lambda_scope.scope\n> to the parameter which doesn't yet have a DECL_CONTEXT, and we'd crash.\n> But for the default argument in\n> \n>    inline void g(int n) {\n>      int bef(int i = []{ return 1; }());\n>    }\n> \n> the scope should be 'g' anyway, not 'bef'.  Thus the adjust_lambda_scope_p\n> parameter to preserve the existing behavior.\n> \n> \tPR c++/50479\n> \tPR c++/62244\n> \n> gcc/cp/ChangeLog:\n> \n> \t* parser.cc (defining_nonlambda_class_type_p): New.\n> \t(cp_parser_parameter_declaration_list): Maybe perform deferred\n> \tparsing of default arguments.\n> \t(cp_parser_parameter_declaration): Defer parsing of named\n> \tparameters.\n> \t(cp_parser_noexcept_specification_opt): Use\n> \tdefining_nonlambda_class_type_p.\n> \t(cp_parser_late_parse_one_default_arg): New parameter.  Use it to\n> \tavoid the calls to start_/finish_lambda_scope.\n> \n> gcc/testsuite/ChangeLog:\n> \n> \t* g++.dg/reflect/parm1.C: Uncomment code.\n> \t* g++.dg/parse/defarg22.C: New test.\n> \t* g++.dg/parse/defarg23.C: New test.\n> \t* g++.dg/parse/defarg24.C: New test.\n> \t* g++.dg/parse/defarg25.C: New test.\n> \t* g++.dg/parse/defarg26.C: New test.\n> ---\n>   gcc/cp/parser.cc                      | 86 +++++++++++++++++++++------\n>   gcc/testsuite/g++.dg/parse/defarg22.C | 16 +++++\n>   gcc/testsuite/g++.dg/parse/defarg23.C | 36 +++++++++++\n>   gcc/testsuite/g++.dg/parse/defarg24.C | 12 ++++\n>   gcc/testsuite/g++.dg/parse/defarg25.C | 22 +++++++\n>   gcc/testsuite/g++.dg/parse/defarg26.C | 18 ++++++\n>   gcc/testsuite/g++.dg/reflect/parm1.C  |  5 +-\n>   7 files changed, 173 insertions(+), 22 deletions(-)\n>   create mode 100644 gcc/testsuite/g++.dg/parse/defarg22.C\n>   create mode 100644 gcc/testsuite/g++.dg/parse/defarg23.C\n>   create mode 100644 gcc/testsuite/g++.dg/parse/defarg24.C\n>   create mode 100644 gcc/testsuite/g++.dg/parse/defarg25.C\n>   create mode 100644 gcc/testsuite/g++.dg/parse/defarg26.C\n> \n> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc\n> index d128de771b5..9c8cd7bdc90 100644\n> --- a/gcc/cp/parser.cc\n> +++ b/gcc/cp/parser.cc\n> @@ -3104,7 +3104,7 @@ static void cp_parser_save_default_args\n>   static void cp_parser_late_parsing_for_member\n>     (cp_parser *, tree);\n>   static tree cp_parser_late_parse_one_default_arg\n> -  (cp_parser *, tree, tree, tree);\n> +  (cp_parser *, tree, tree, tree, bool = true);\n>   static void cp_parser_late_parsing_nsdmi\n>     (cp_parser *, tree);\n>   static void cp_parser_late_parsing_default_args\n> @@ -28126,6 +28126,17 @@ function_being_declared_is_template_p (cp_parser* parser)\n>   \t  (current_class_type));\n>   }\n>   \n> +/* Return true if we are defining a class which is not a lambda closure\n> +   type.  */\n> +\n> +static bool\n> +defining_nonlambda_class_type_p ()\n> +{\n> +  return (at_class_scope_p ()\n> +\t  && TYPE_BEING_DEFINED (current_class_type)\n> +\t  && !LAMBDA_TYPE_P (current_class_type));\n> +}\n> +\n>   /* Parse a parameter-declaration-clause.\n>   \n>      parameter-declaration-clause:\n> @@ -28370,6 +28381,32 @@ cp_parser_parameter_declaration_list (cp_parser* parser,\n>   \t  retrofit_lang_decl (decl);\n>   \t  DECL_PARM_INDEX (decl) = ++index;\n>   \t  DECL_PARM_LEVEL (decl) = function_parm_depth ();\n> +\n> +\t  if (tree &def = parameter->default_argument)\n> +\t    if (TREE_CODE (def) == DEFERRED_PARSE\n> +\t\t/* If we're defining a class, let _class_specifier\n> +\t\t   -> _late_parsing_default_args re-parse the default\n> +\t\t   argument.  */\n> +\t\t&& !defining_nonlambda_class_type_p ())\n> +\t      {\n> +\t\tauto lvf\n> +\t\t  = make_temp_override (parser->local_variables_forbidden_p);\n> +\t\tparser->local_variables_forbidden_p\n> +\t\t  = LOCAL_VARS_AND_THIS_FORBIDDEN;\n> +\t\tpush_unparsed_function_queues (parser);\n> +\t\t/* We used to not defer parsing for default arguments outside\n> +\t\t   classes, and just called _default_argument.  In order to\n> +\t\t   preserve mangling of lambdas (see e.g. in lambda-mangle.C),\n> +\t\t   we tell this function to omit the call to start_lambda_scope\n> +\t\t   otherwise the lambda scope would be the current PARM_DECL\n> +\t\t   which doesn't have a context yet.  Even if it had a context,\n> +\t\t   it would be wrong for block-extern function declarations\n> +\t\t   where the context should be the enclosing function body.  */\n> +\t\tdef = cp_parser_late_parse_one_default_arg (parser, decl, def,\n> +\t\t\t\t\t\t\t    TREE_TYPE (decl),\n> +\t\t\t\t\t\t\t    /*lscope=*/false);\n> +\t\tpop_unparsed_function_queues (parser);\n> +\t      }\n>   \t}\n>   \n>         /* Add the new parameter to the list.  */\n> @@ -28710,21 +28747,30 @@ cp_parser_parameter_declaration (cp_parser *parser,\n>         eq_token = token;\n>         if (declarator)\n>   \tdeclarator->init_loc = token->location;\n> -      /* If we are defining a class, then the tokens that make up the\n> -\t default argument must be saved and processed later.  */\n> -      if (!template_parm_p && at_class_scope_p ()\n> -\t  && TYPE_BEING_DEFINED (current_class_type)\n> -\t  && !LAMBDA_TYPE_P (current_class_type))\n> -\tdefault_argument = cp_parser_cache_defarg (parser, /*nsdmi=*/false);\n> -\n>         /* A constrained-type-specifier may declare a type\n>   \t template-parameter.  */\n> -      else if (declares_constrained_type_template_parameter (type))\n> +      if (declares_constrained_type_template_parameter (type))\n>           default_argument\n>             = cp_parser_default_type_template_argument (parser);\n> -\n> -      /* Outside of a class definition, we can just parse the\n> -\t assignment-expression.  */\n> +      /* If we are defining a class, then the tokens that make up the\n> +\t default argument must be saved and processed later.  We also\n> +\t have to defer parsing for named parameters to correctly handle\n> +\t   void fn (int i = sizeof (i));\n> +\t which is OK.  */\n> +      else if (!template_parm_p\n> +\t       && (defining_nonlambda_class_type_p ()\n> +\t\t   || (get_id_declarator (declarator)\n> +\t\t       /* Optimization only: if we see \"int i = 42\",\n> +\t\t\t  we don't have to defer parsing.  */\n> +\t\t       && !((cp_lexer_nth_token_is (parser->lexer, 2,\n> +\t\t\t\t\t\t    CPP_NUMBER)\n> +\t\t\t     || cp_lexer_nth_token_is (parser->lexer, 2,\n> +\t\t\t\t\t\t       CPP_KEYWORD))\n> +\t\t\t    && (cp_lexer_nth_token_is (parser->lexer, 3,\n> +\t\t\t\t\t\t       CPP_CLOSE_PAREN)\n> +\t\t\t\t|| cp_lexer_nth_token_is (parser->lexer, 3,\n> +\t\t\t\t\t\t\t  CPP_COMMA))))))\n> +\tdefault_argument = cp_parser_cache_defarg (parser, /*nsdmi=*/false);\n>         else\n>   \tdefault_argument\n>   \t  = cp_parser_default_argument (parser, template_parm_p);\n> @@ -32177,9 +32223,7 @@ cp_parser_noexcept_specification_opt (cp_parser* parser,\n>   \t  && !((cp_lexer_nth_token_is (parser->lexer, 3, CPP_NUMBER)\n>   \t\t|| cp_lexer_nth_token_is (parser->lexer, 3, CPP_KEYWORD))\n>   \t       && cp_lexer_nth_token_is (parser->lexer, 4, CPP_CLOSE_PAREN))\n> -\t  && at_class_scope_p ()\n> -\t  && TYPE_BEING_DEFINED (current_class_type)\n> -\t  && !LAMBDA_TYPE_P (current_class_type))\n> +\t  && defining_nonlambda_class_type_p ())\n>   \treturn cp_parser_save_noexcept (parser);\n>   \n>         cp_lexer_consume_token (parser->lexer);\n> @@ -37088,11 +37132,13 @@ cp_parser_save_default_args (cp_parser* parser, tree decl)\n>   /* DEFAULT_ARG contains the saved tokens for the initializer of DECL,\n>      which is either a FIELD_DECL or PARM_DECL.  Parse it and return\n>      the result.  For a PARM_DECL, PARMTYPE is the corresponding type\n> -   from the parameter-type-list.  */\n> +   from the parameter-type-list.  If adjust_lambda_scope_p is true,\n> +   we do start_/finish_lambda_scope.  */\n>   \n>   static tree\n>   cp_parser_late_parse_one_default_arg (cp_parser *parser, tree decl,\n> -\t\t\t\t      tree default_arg, tree parmtype)\n> +\t\t\t\t      tree default_arg, tree parmtype,\n> +\t\t\t\t      bool adjust_lambda_scope_p/*=true*/)\n>   {\n>     cp_token_cache *tokens;\n>     tree parsed_arg;\n> @@ -37105,14 +37151,16 @@ cp_parser_late_parse_one_default_arg (cp_parser *parser, tree decl,\n>     tokens = DEFPARSE_TOKENS (default_arg);\n>     cp_parser_push_lexer_for_tokens (parser, tokens);\n>   \n> -  start_lambda_scope (decl);\n> +  if (adjust_lambda_scope_p)\n> +    start_lambda_scope (decl);\n>   \n>     /* Parse the default argument.  */\n>     parsed_arg = cp_parser_initializer (parser);\n>     if (BRACE_ENCLOSED_INITIALIZER_P (parsed_arg))\n>       maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);\n>   \n> -  finish_lambda_scope ();\n> +  if (adjust_lambda_scope_p)\n> +    finish_lambda_scope ();\n>   \n>     if (parsed_arg == error_mark_node)\n>       cp_parser_skip_to_end_of_statement (parser);\n> diff --git a/gcc/testsuite/g++.dg/parse/defarg22.C b/gcc/testsuite/g++.dg/parse/defarg22.C\n> new file mode 100644\n> index 00000000000..f393b95a591\n> --- /dev/null\n> +++ b/gcc/testsuite/g++.dg/parse/defarg22.C\n> @@ -0,0 +1,16 @@\n> +// PR c++/50479\n> +// { dg-do compile }\n> +\n> +void fn1 (int i = sizeof (i)) {}\n> +void fn2 (int i, int = sizeof (i)) {}\n> +\n> +void\n> +g ()\n> +{\n> +  void fn4 (int i = sizeof (i));\n> +  void fn5 (int i, int = sizeof (i));\n> +  fn1 ();\n> +  fn2 (42);\n> +  fn4 ();\n> +  fn5 (42);\n> +}\n> diff --git a/gcc/testsuite/g++.dg/parse/defarg23.C b/gcc/testsuite/g++.dg/parse/defarg23.C\n> new file mode 100644\n> index 00000000000..0aeb1b33394\n> --- /dev/null\n> +++ b/gcc/testsuite/g++.dg/parse/defarg23.C\n> @@ -0,0 +1,36 @@\n> +// PR c++/50479\n> +// { dg-do compile { target c++14 } }\n> +\n> +inline void\n> +fn1 ()\n> +{\n> +  int f (int i = []{ return 1; }());\n> +}\n> +\n> +auto l = [](int i = sizeof (i)) { };\n> +void fn2 (int i = []{ return 1; }()) {}\n> +void fn3 (int x = []{ decltype(x) y{}; return y; }()) {}\n> +void fn6 (int i = sizeof (i), decltype (i) = sizeof (i)) {}\n> +\n> +struct S {\n> +  int mfn1 (int i = sizeof (i)) { return i; }\n> +  int mfn2 (int i, int = sizeof (i)) { return i; }\n> +  int lm = [](int i6 = sizeof (i6)) { return i6; }();\n> +  int mfn3 (int i = []{ return 1; }()) { return i; }\n> +  int i = mfn1 () + mfn2 (42) + mfn3 () + lm;\n> +};\n> +\n> +void\n> +g ()\n> +{\n> +  auto ll = [](int i5 = sizeof (i5)) { };\n> +  void fn4 (int i = []{ return 1; }());\n> +  void fn5 (int x = []{ decltype(x) y{}; return y; }());\n> +  fn1 ();\n> +  fn2 ();\n> +  fn3 ();\n> +  fn4 ();\n> +  fn5 ();\n> +  fn6 ();\n> +  l ();\n> +}\n> diff --git a/gcc/testsuite/g++.dg/parse/defarg24.C b/gcc/testsuite/g++.dg/parse/defarg24.C\n> new file mode 100644\n> index 00000000000..48b6f1f2a1c\n> --- /dev/null\n> +++ b/gcc/testsuite/g++.dg/parse/defarg24.C\n> @@ -0,0 +1,12 @@\n> +// PR c++/50479\n> +// { dg-do compile { target c++11 } }\n> +\n> +void fn1 (int x = []{ return x; }()) {}\t      // { dg-error \"use of parameter outside function body\" }\n> +void fn2 (int x, int = []{ return x; }()) {}  // { dg-error \"use of parameter outside function body\" }\n> +\n> +void\n> +g ()\n> +{\n> +  void fn3 (int z = []{ return z; }());\t      // { dg-error \"use of parameter outside function body\" }\n> +  void fn4 (int z, int = []{ return z; }());  // { dg-error \"use of parameter outside function body\" }\n> +}\n> diff --git a/gcc/testsuite/g++.dg/parse/defarg25.C b/gcc/testsuite/g++.dg/parse/defarg25.C\n> new file mode 100644\n> index 00000000000..95989885dfa\n> --- /dev/null\n> +++ b/gcc/testsuite/g++.dg/parse/defarg25.C\n> @@ -0,0 +1,22 @@\n> +// PR c++/62244\n> +// { dg-do compile { target c++11 } }\n> +\n> +int a;\n> +void f (int a = a); // { dg-error \"parameter .a. may not appear in this context\" }\n> +\n> +int foo(int x = (decltype(x)(42))) { return 0; }\n> +\n> +static int value;\n> +\n> +int\n> +bar (int &value = value)  // { dg-error \"parameter .value. may not appear in this context\" }\n> +{\n> +  return value;\n> +}\n> +\n> +void\n> +g ()\n> +{\n> +  bar ();\n> +}\n> +\n> diff --git a/gcc/testsuite/g++.dg/parse/defarg26.C b/gcc/testsuite/g++.dg/parse/defarg26.C\n> new file mode 100644\n> index 00000000000..170f7f5c0ec\n> --- /dev/null\n> +++ b/gcc/testsuite/g++.dg/parse/defarg26.C\n> @@ -0,0 +1,18 @@\n> +// PR c++/50479\n> +// { dg-do compile { target c++11 } }\n> +\n> +template<class>\n> +struct A;\n> +\n> +template<>\n> +struct A<long> {\n> +  static const int value = 1;\n> +};\n> +\n> +long foo;\n> +\n> +void bar(char foo = A<decltype(foo)>::value) {} // { dg-error \"incomplete type\" }\n> +\n> +int main() {\n> +  bar();\n> +}\n> diff --git a/gcc/testsuite/g++.dg/reflect/parm1.C b/gcc/testsuite/g++.dg/reflect/parm1.C\n> index 8416be5b0db..c844c1dff3f 100644\n> --- a/gcc/testsuite/g++.dg/reflect/parm1.C\n> +++ b/gcc/testsuite/g++.dg/reflect/parm1.C\n> @@ -4,9 +4,8 @@\n>   \n>   #include <meta>\n>   \n> -// FIXME PR62244\n> -//consteval int fn(decltype(^^::) x = ^^x) { return 0; }\n> -//constexpr int x = fn ();\n> +consteval int fn(decltype(^^::) x = ^^x) { return 0; }\n> +constexpr int x = fn ();\n>   \n>   consteval auto\n>   ref (std::meta::info r)\n> \n> base-commit: 3a9643ffe7fea815aab8afa122a4bf12fbc5b54e","headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=iiC6QzB1;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (1024-bit key,\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=iiC6QzB1","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=redhat.com","sourceware.org; spf=pass smtp.mailfrom=redhat.com","sourceware.org; arc=none smtp.remote-ip=170.10.129.124"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g9mpk1WNyz1y04\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 07 May 2026 06:15:42 +1000 (AEST)","from vm01.sourceware.org (localhost [IPv6:::1])\n\tby sourceware.org (Postfix) with ESMTP id EA97F4BA23DC\n\tfor <incoming@patchwork.ozlabs.org>; Wed,  6 May 2026 20:15:39 +0000 (GMT)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.129.124])\n by sourceware.org (Postfix) with ESMTP id 4A6B74BA2E30\n for <gcc-patches@gcc.gnu.org>; Wed,  6 May 2026 20:15:08 +0000 (GMT)","from mail-qv1-f69.google.com (mail-qv1-f69.google.com\n [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n us-mta-529-3wzKo6qfMWK50rvLqK4MuA-1; Wed, 06 May 2026 16:15:06 -0400","by mail-qv1-f69.google.com with SMTP id\n 6a1803df08f44-8b49424ad88so2661646d6.1\n for <gcc-patches@gcc.gnu.org>; Wed, 06 May 2026 13:15:06 -0700 (PDT)","from [192.168.50.130]\n (130-44-146-247.s12789.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com.\n [130.44.146.247]) by smtp.gmail.com with ESMTPSA id\n 6a1803df08f44-8b53d831651sm183672866d6.47.2026.05.06.13.15.04\n (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n Wed, 06 May 2026 13:15:04 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org EA97F4BA23DC","OpenDKIM Filter v2.11.0 sourceware.org 4A6B74BA2E30"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 4A6B74BA2E30","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 4A6B74BA2E30","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778098508; cv=none;\n b=o2iwn0q4I9W1tszrGM0x/l47P1KSuPgNMGqzO60D41eVFXZ2bVyx72W847pa5pniwNtCqlau2eZjKvGe4ROS2kc6mPzb7ZalwAMqkps/HWB6nAGCUOwtkcM0kpLWCI1BASacA13nNEZ+TIa37pdyN9PbPluXVAHkNEzkfGgWJKc=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1778098508; c=relaxed/simple;\n bh=CPx8nPYXGZDF7+1afrCQtZ8GHCIDS7GU5Neq7T+uvLQ=;\n h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From;\n b=kj37FYIZT8fugYtOw7hdM4mLkCstTQVcyTFfF+WZW/+zHC2FuGc3EsQbnLpuvbYNhAg5cxuFZkxVkwrVOy1inx2dYDEYBHLWfX84mP0hYDHWjZZ4h/xn5X5nmIQt9+eDqmnNv3AdTZSiCyDCFciGKbghJhKC7rblTs8gqWzQHko=","ARC-Authentication-Results":"i=1; sourceware.org;\n dkim=pass (1024-bit key, unprotected)\n header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=iiC6QzB1","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1778098507;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:mime-version:mime-version:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=RUfWSbimgO1yJs2BJiJjkGA67QicMUmCU+r9BWcR1TI=;\n b=iiC6QzB1jQBy9nXkL//jeTm0jKK5uLT2Jakc4d6Ajtt1+auFUdP5m/phR9HNG+oyY4naap\n iuGvPhKBUFS3g3Iw3eVG/4Q3UzKtsExh0dOBe+b/Cduga0f/DABxPE3FRT4oaR4Gfu95dB\n NDfs8AP2P43yZINb/gYTlD/Y1AHKtiM=","X-MC-Unique":"3wzKo6qfMWK50rvLqK4MuA-1","X-Mimecast-MFC-AGG-ID":"3wzKo6qfMWK50rvLqK4MuA_1778098506","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1778098506; x=1778703306;\n h=content-transfer-encoding:in-reply-to:from:content-language\n :references:to:subject:user-agent:mime-version:date:message-id\n :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id\n :reply-to;\n bh=RUfWSbimgO1yJs2BJiJjkGA67QicMUmCU+r9BWcR1TI=;\n b=hr/8csLudBC7p+MfJg9ImS/N+4natG9vfQznTGeYP4Foy5Cw2udZhfU01Uc/Wfg9B2\n H6S6k8zrR8t8NI6Wwn+1wc+trZf8tF0/QZ11+KmVV06ZVdblbDi4JMXCIKiPnx2w4ckb\n vTP9qNj3ZLXO94S3kax+uM4hU24EWrsbjNU6vMOJT88tGEJFHbFGgCE12lXB/yxu3onV\n EoZ6Nt4M6dH1/amWt/J18FHdR/h/QrQwYCYqcRW5SBIlfWIGmOeKKB5Xt2zBUMTItLwO\n IHFkdghaN6dLrBGNJ1Mza9zCq7iFLhJAaD6zkEeuz3I68a+g/IYglTM9cCNVlHiOYKeo\n u5Pw==","X-Forwarded-Encrypted":"i=1;\n AFNElJ+zN069i+COlMtpOTaDDMWUNZIik89E4Iiw+mqrE1c6a1DyXVRoBSA2rx1d65Ycq6uFihwcs1hmNlctww==@gcc.gnu.org","X-Gm-Message-State":"AOJu0Yz3MsCkG2P8jCDxtKAlxO53L1oRQ5//jFzeFb4tOS9dX8yZjG6Z\n FN9QuqA7y3GsKy70s20g75qXR0HFlngZTmVQ9IDK5s58gjfAId5djpU4BhTMT3FMzOU3fLLJ3RC\n HWmdM2GP6PelPREEbxitkA7vWNDL+N5MHbni9Zoza0IOVuZnn4AbczKjrdjg=","X-Gm-Gg":"AeBDieuRRP7q0eTxA8P0jhaNx5iiyEDBAs9ocu5KWu/Vd0TPE/Gm8w+1Ye8Oa1kG2xu\n OmFpt8E4Nn0sVPynzLu4lx/5bFyUunUOc2W5XvePGjc9ZYdsU8uMkVxrDf3zjq8Uq/dEX4VLK0H\n G0VwXRAzsPz4//WU+JZrAm7Jl+cy8vxzsqhrcxRBrLqZ7yduTRZBc5ZeaZfd+RyQ8Wk8PASOVIX\n YarWk7VW2ayjhQQyi8HvHm0kToI1/WOSSTxYN2CnTiTyPNz+ZFmHQoZLrthkwqez6UMVf8wAZEJ\n 7be/XkEMmHwkemdP0neSaWOGd7kY+KLL/RJV0yo7l+VY4V+es3W/mte2epfGOcRhV5zzM/goqcS\n gZUKDXvYDQ8HguKRuWLOzOGSETMzhrY5MaFcoPkkNo+iV2v5/sGVCcjEwHSBoKSkZtte7d1brgg\n 8CCO4NSma8bbj2f1qbi3eNX83PXgyOstJeV6j5+4Kjnw==","X-Received":["by 2002:a05:6214:4706:b0:89c:eabb:f58d with SMTP id\n 6a1803df08f44-8bc462fa626mr62523406d6.47.1778098505953;\n Wed, 06 May 2026 13:15:05 -0700 (PDT)","by 2002:a05:6214:4706:b0:89c:eabb:f58d with SMTP id\n 6a1803df08f44-8bc462fa626mr62522456d6.47.1778098505166;\n Wed, 06 May 2026 13:15:05 -0700 (PDT)"],"Message-ID":"<c36fce84-b266-4996-832d-9bc2ab4d6ac7@redhat.com>","Date":"Wed, 6 May 2026 16:15:03 -0400","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH] c++: deferred parsing of default arguments [PR50479]","To":"Marek Polacek <polacek@redhat.com>, GCC Patches <gcc-patches@gcc.gnu.org>","References":"<20260506011912.1371228-1-polacek@redhat.com>","From":"Jason Merrill <jason@redhat.com>","In-Reply-To":"<20260506011912.1371228-1-polacek@redhat.com>","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"5v7WZlO_661NuZ9PBJjiJEx0PMHrOiYLW3AS9YaXsrc_1778098506","X-Mimecast-Originator":"redhat.com","Content-Language":"en-US","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"}}]