[{"id":3626217,"web_url":"http://patchwork.ozlabs.org/comment/3626217/","msgid":"<08017ebf-0452-4f77-b08a-953fa173f1c1@redhat.com>","list_archive_url":null,"date":"2025-12-16T02:30:14","subject":"Re: [PATCH] c++: initialize constructor_possible_p with LOCAL_CLASS_P","submitter":{"id":4337,"url":"http://patchwork.ozlabs.org/api/people/4337/","name":"Jason Merrill","email":"jason@redhat.com"},"content":"On 12/15/25 4:24 PM, Ben Wu wrote:\n> Bootstrapped and regtested on x86_64-pc-linux-gnu. Any thoughts on this \n> approach?\n\nInstead, I think we want to add in_declarator_p to all the other flags \nthat get cleared/restored in cp_parser_lambda_expression.\n\n> Please use the attached patch file if applying, thanks!\n> \n> -- 8< --\n> \n> Previously, constructors were not possibly parsed while in a\n> declarator, but we may have a constructor in a declarator as in this\n> PR where a lambda expression containing a class definition is a\n> default argument.\n> \n> We can account for this by checking current_class_type when\n> initializing constructor_possible_p so that we allow for a constructor\n> inside a declarator if LOCAL_CLASS_P (current_class_type).\n> \n> PR c++/121443\n> \n> gcc/cp/ChangeLog:\n> \n> * parser.cc (cp_parser_decl_specifier_seq): Consider LOCAL_CLASS_P\n> in initializing constructor_possible_p.\n> \n> gcc/testsuite/ChangeLog:\n> \n> * g++.dg/parse/pr121443.C: New test.\n> ---\n>   gcc/cp/parser.cc                      |  4 +++-\n>   gcc/testsuite/g++.dg/parse/pr121443.C | 10 ++++++++++\n>   2 files changed, 13 insertions(+), 1 deletion(-)\n>   create mode 100644 gcc/testsuite/g++.dg/parse/pr121443.C\n> \n> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc\n> index 214dababeb5..7683c160b14 100644\n> --- a/gcc/cp/parser.cc\n> +++ b/gcc/cp/parser.cc\n> @@ -17700,7 +17700,9 @@ cp_parser_decl_specifier_seq (cp_parser* parser,\n>         cp_decl_specifier_seq *decl_specs,\n>         int* declares_class_or_enum)\n>   {\n> -  bool constructor_possible_p = !parser->in_declarator_p;\n> +  const bool maybe_lambda_p = (current_class_type\n> +       && LOCAL_CLASS_P (current_class_type));\n> +  bool constructor_possible_p = !parser->in_declarator_p || maybe_lambda_p;\n>     bool found_decl_spec = false;\n>     cp_token *start_token = NULL;\n>     cp_decl_spec ds;\n> diff --git a/gcc/testsuite/g++.dg/parse/pr121443.C b/gcc/testsuite/g+ \n> +.dg/parse/pr121443.C\n> new file mode 100644\n> index 00000000000..1022b3cdd90\n> --- /dev/null\n> +++ b/gcc/testsuite/g++.dg/parse/pr121443.C\n> @@ -0,0 +1,10 @@\n> +// { dg-do compile { target c++11 } }\n> +\n> +void f(int i = []() {\n> +  struct X {\n> +    int val;\n> +    X(int v) : val(v) { }\n> +  };\n> +  X x(2);\n> +  return x.val;\n> +}()) {}\n> -- \n> 2.43.0\n>","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=h4d/BCdC;\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=h4d/BCdC","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=redhat.com","sourceware.org; spf=pass smtp.mailfrom=redhat.com","server2.sourceware.org;\n arc=none smtp.remote-ip=170.10.133.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 4dW1Tm6LC8z1y0P\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 17 Dec 2025 02:45:16 +1100 (AEDT)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id F19384BA23DE\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 16 Dec 2025 15:45:14 +0000 (GMT)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.133.124])\n by sourceware.org (Postfix) with ESMTP id 314D34BA2E21\n for <gcc-patches@gcc.gnu.org>; Tue, 16 Dec 2025 15:44:44 +0000 (GMT)","from mail-pf1-f199.google.com (mail-pf1-f199.google.com\n [209.85.210.199]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n us-mta-352-gDondvTzOWSyJsWzMIU29g-1; Tue, 16 Dec 2025 10:44:37 -0500","by mail-pf1-f199.google.com with SMTP id\n d2e1a72fcca58-7c1df71b076so9020318b3a.0\n for <gcc-patches@gcc.gnu.org>; Tue, 16 Dec 2025 07:44:37 -0800 (PST)","from [10.0.1.97] (ppp-171-97-199-165.revip8.asianet.co.th.\n [171.97.199.165]) by smtp.gmail.com with ESMTPSA id\n d2e1a72fcca58-7f4c2772a51sm15945921b3a.17.2025.12.16.07.44.18\n (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n Tue, 16 Dec 2025 07:44:19 -0800 (PST)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org F19384BA23DE","OpenDKIM Filter v2.11.0 sourceware.org 314D34BA2E21"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 314D34BA2E21","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 314D34BA2E21","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1765899884; cv=none;\n b=tBi7jsdNX8FaNw23m0FgLkY5L5UNLc404ki7wRFKy3N5xhmYTXRbt18vOwO5ltmgXQIXgcW8oZwJClOemvplnwyVgzJPOmo03oTwybuNFx5ezOtLoRjyQe0OUMak8+3+ElBFD91eYOryEeFk5VsFiQ6iVhcguUkEimlv9bEeCro=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1765899884; c=relaxed/simple;\n bh=nSm7yEDAUgRItQcsRlJX1j0z93x+uTEgtKrSLAlY1Lw=;\n h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From;\n b=GQhG6GY1BHGIX8Nbc85ESI2QYMABF6VbYDu89kS5ZCw8JND3PzfjdQVrQzI2ZBMctCSjX4yoK05sHploC6BMDPmV7dRjVEPmeLlzOcehGdmrn8AZWm/WNSFCkNEhu1r5XT+HLJP5x/XW90mMq0eKS4VCOCN1y0r7ECsDslrwCV0=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1765899879;\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=oHiEszTILtWfzQKgRaQEGKIYVEqbuHbhYrDnEw3m7Nc=;\n b=h4d/BCdCAJYUQlY5ki8slX6B5MGqNespAgxZj53wLdGygNkSYtozAlcZD9P0UiMnXuz3tR\n 1TZ3OKZql3YKob+1EYMWKGmgR+LcY3ueFYPAnS9EvzpWRNHfBbYVn3Q41ONsYwUX5pUzKT\n TxYSIrNhKcJFyyxAHGZZPEDQnOT6exU=","X-MC-Unique":"gDondvTzOWSyJsWzMIU29g-1","X-Mimecast-MFC-AGG-ID":"gDondvTzOWSyJsWzMIU29g_1765899877","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20230601; t=1765899874; x=1766504674;\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=oHiEszTILtWfzQKgRaQEGKIYVEqbuHbhYrDnEw3m7Nc=;\n b=rhPkd4nE+kBkTYsgk94wV0yvAtCs4OyQzQRwuGhy2/rQvRHNsy9pq6iwdcVl3g0O5Y\n Qgvl2q4ZoKfZsk39vquRQZj73CM6sFipTK8QyQkbTKMuHPsSPVVulBHfH9w4R/2LTUc2\n RZ6AWzzru/GzFyIVG2zI7chNkR0UMAiuNpq0RptFlbzNM1vy3tLVDiF9wML9o3McW7vn\n 1Zg/RehocqPhdo0QdukOAdyakuL12nbfdcpi373edlgnBMVzRf54Enfhj9BtrJIAYBgF\n SJXfSnIepNNmP9oMMBrwFG76Pckqk2Ph52T3gYZbarr8tOCkEthl9RHsUMJqFfqRDXsA\n 0f4Q==","X-Forwarded-Encrypted":"i=1;\n AJvYcCUT+udeXuavT4ZheIaa34aithsq5S+T3rERP+gpVPCcJuQC5IrgYNZvzK67tiUT9yZOZ6QhJRGk58yaKw==@gcc.gnu.org","X-Gm-Message-State":"AOJu0YwIZ+p8Vbv4Cb0dmXE7TRd5HpwrSgfo6CHhSOe30e4xF8jNFtak\n zihlRdYe2MAJjS2qb2Zfa5+HhUIRzMzc94J8IafBUQuhVWsfQn913QxSM/pe3P1aGQZCVRGXQmZ\n sV4Z2OaaiLVdqNWWCHJ2PoMSifyhIq1DibjSW825hHViPA3v5obDT28CXV7ojA0n25Dz9ncF2","X-Gm-Gg":"AY/fxX5TVtr7Y6V3c4BI5qi7qhzbR0gt3EnYCIopSdaKMvcTyX1MWUJORJ9nd9VEiHs\n EfbrNKt6K9UzgkWLZD77lBHvoe90BuqA7TOq4alx9Oqo/hTuHyy4YYNjB5zuAknnqNPc6TjvW4h\n LybIIeXtHmoavAPXGYRpllLtTLRLyQqZFdrdDDh4s3EMaVCuhpcxuDcixoUdfL0Y5UI8MRTIyoX\n ckRtO6WYItTElEdzeyhyEazl4xFCPaT4VPvYHT3U5Mv2t0h0jbb6rcEkbuoqXGljI+G+rieuNUO\n 8JyRuTFAVtTGX6k63oIjfQOxder9mR3k+2gttiytr+l+ZasQSRgRbE+MVPOzSL5VPs1FGN+tmKw\n VktVuMH6ocH1tZtHtI5nIhrfjoLNci/XFm5HLec0Bbrmk6g4P9w==","X-Received":["by 2002:a05:6a00:1f17:b0:7e8:4433:8fb1 with SMTP id\n d2e1a72fcca58-7f669e7dff4mr14500873b3a.57.1765899874182;\n Tue, 16 Dec 2025 07:44:34 -0800 (PST)","by 2002:a05:6a00:1f17:b0:7e8:4433:8fb1 with SMTP id\n d2e1a72fcca58-7f669e7dff4mr14500851b3a.57.1765899873745;\n Tue, 16 Dec 2025 07:44:33 -0800 (PST)"],"X-Google-Smtp-Source":"\n AGHT+IG7P8yRQLMns6ts6CGrOVY2PVCSmkXdsAf1wsFFlzM1C7BgdE40y4MyoE7pV77+LsXd3z5b/A==","Message-ID":"<08017ebf-0452-4f77-b08a-953fa173f1c1@redhat.com>","Date":"Tue, 16 Dec 2025 09:30:14 +0700","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH] c++: initialize constructor_possible_p with LOCAL_CLASS_P","To":"Ben Wu <soggysocks206@gmail.com>, gcc-patches@gcc.gnu.org","References":"\n <CAD+gk=jyb+y=59CD-T1-SrbXt2y-SgT3fZECyyefwyrGYiLkSQ@mail.gmail.com>","From":"Jason Merrill <jason@redhat.com>","In-Reply-To":"\n <CAD+gk=jyb+y=59CD-T1-SrbXt2y-SgT3fZECyyefwyrGYiLkSQ@mail.gmail.com>","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"UVvLGukFj2iHhE7rkX67tsNr_WQs7PREonZ3yBtecHI_1765899877","X-Mimecast-Originator":"redhat.com","Content-Language":"en-US","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","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"}}]