From patchwork Tue Jun 6 18:29:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 104030 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3593075vqr; Tue, 6 Jun 2023 11:31:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6v5Yadg9m/XuOnMcrUjVY8bjcbx95Xujm2ooJFybwk/N/4WmHCC7Y+XoP7mCDZqRJH4RIT X-Received: by 2002:a17:907:7e93:b0:94f:6058:4983 with SMTP id qb19-20020a1709077e9300b0094f60584983mr3379858ejc.76.1686076274681; Tue, 06 Jun 2023 11:31:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686076274; cv=none; d=google.com; s=arc-20160816; b=C7YHlEUfmnVl4VQ/+INrctuaADAou4pK7Cp+fUS25hMr2LepZDJWHZm4GSESHhE+iv 1F/5xKY6tOnpK2CQqugcXw0K+cKy6UWAA1XYiIS8InJaWjJeJKUTcfasr995nJwUknY2 5kQ8HHSNf9KGar/sOnNA64Zx4816prjPs1XGYLWwWToCzmDFTxNq+Ien8kopzuIU4CEn ouhCrnIRaJt1dckZyl7J65bzwU6t3iDgZCb+UeLthfSvUIfo4FdNzC5ukqgGL0zC+FKD 2JTnpC1/7G4FQnwYnQ2Q+ZnLW7JahpdajLnRlds6dPVkLeI/Lt/VJ/MB32xfIhPE9yWF +uOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=vDwM1Xw6drlyyv3v4tbS24YBLitW84AgMtZyZVlYunk=; b=Je4+fW9zK+8hOghQXUQVFVidupQ280pZGUJkYwYCRyCdl1yB5/hs8xt2bQ71S5pt2Y ytYhuKC+AF2tOuHYmACMxFw1KTYUTEleghl38MBGkeeWH1VfDBoPRWkay++ljfj8FR4m oLbmALkRB6gF5xyYOEXTFv7seqpimQrEfWLNwE1FmaOrURcbzD7MyWBdJV3wAL1w4HHt SjJ+FrFbQkqXUsLqhpd6EYxojSUaCElvFgNC5GyGv+7gGj//4BOJZ2rl+WpJRugs/g+z gBFhnvmcdoXSR1ABs2XgK+CsGTpaIRDLAvaZ0ICa4FFQaNOWACIW7WkoNsqUPWMhTlvu 3N+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=f6iOdG9y; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id z25-20020a170906715900b0096630a5c7f5si6657695ejj.207.2023.06.06.11.31.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 11:31:14 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=f6iOdG9y; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 57A333857707 for ; Tue, 6 Jun 2023 18:31:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 57A333857707 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686076273; bh=vDwM1Xw6drlyyv3v4tbS24YBLitW84AgMtZyZVlYunk=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=f6iOdG9ysJRDODVRZSoIRyvl7sjVotWR55VjhgznqVif+SlIthNYJSYvrmtsOeMck QBYtSequGL9/NBA3pN1jfaiE1+7knBg0MUteCkLekwQgbc1r+FlCNqW8LBsqkP6gBc RUehMLf3ZaeAx41/pgBx36EsdnWxvif7Byy5DZo4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 0840C3858D38 for ; Tue, 6 Jun 2023 18:30:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0840C3858D38 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-519-tvlHT4_fNDaSsQW8QHG53Q-1; Tue, 06 Jun 2023 14:30:03 -0400 X-MC-Unique: tvlHT4_fNDaSsQW8QHG53Q-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-75d44483fdeso345179485a.0 for ; Tue, 06 Jun 2023 11:30:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686076198; x=1688668198; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=vDwM1Xw6drlyyv3v4tbS24YBLitW84AgMtZyZVlYunk=; b=GlkjLcOg5/1WbJUg50WL7hBOeKlIntLlSEsHnC7CVcphmU6xd2vLGPbxuym7eH+R6y +YXwn/uVx2NgN/7U8frzl0tDQk4N5agaZBQwf+8+x+FuOcKyk6ich3gIyvMDcTxXkqdC c//SK055oJJYw7UJuVmR6BP31XNwV5qJq7Tzf3iYAk1AoMDLvrv+dLAnkH5wvogpTsLU dpbWMvafCeyuhHAVYHK2UDLDC6Twel4dFKmh/B7+RTriCU6itBJfZzPkfMNrV3XxXWbi suMLt+g9LO3DRA+zOrrJ73JSdjH5e1XNF7qC5Z74hZVLwbWvxkN9SVq40eVf5c6g03QX 0v+g== X-Gm-Message-State: AC+VfDzOb8Eb/cJlWf6Edg8peDWrQMhkwYsN+JBfPrjBLJ/aUjSvvliW Cfx52I+ZD/OmlxocpewFWgtHQj18rllP6NyuiTz7C/KGCfKlb0k0WWiJD4/xj78j3BWYSBzCs0d osy0SXHtURu9/lB+ZKsXnAKg7IXEH3QfhqMjDU8PAwuHs11P5uhClnAeUYsamyvBIFJZlAC8zz0 c= X-Received: by 2002:a05:620a:8f0f:b0:75b:23a1:8e46 with SMTP id rh15-20020a05620a8f0f00b0075b23a18e46mr579958qkn.23.1686076198194; Tue, 06 Jun 2023 11:29:58 -0700 (PDT) X-Received: by 2002:a05:620a:8f0f:b0:75b:23a1:8e46 with SMTP id rh15-20020a05620a8f0f00b0075b23a18e46mr579944qkn.23.1686076197908; Tue, 06 Jun 2023 11:29:57 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id s9-20020a05620a16a900b0075914b01c10sm3448899qkj.85.2023.06.06.11.29.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 11:29:57 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: unsynthesized defaulted constexpr fn [PR110122] Date: Tue, 6 Jun 2023 14:29:53 -0400 Message-ID: <20230606182953.815966-1-ppalka@redhat.com> X-Mailer: git-send-email 2.41.0.rc1.10.g9e49351c30 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767979115669405541?= X-GMAIL-MSGID: =?utf-8?q?1767979115669405541?= Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- In the second testcase of PR110122, during regeneration of the generic lambda with V=Bar{}, substitution followed by coerce_template_parms for A's template argument naturally yields a copy of V in terms of Bar's (implicitly) defaulted copy constructor. This however happens inside a template context so although we introduced a use of the copy constructor, mark_used didn't actually synthesize it, which causes subsequent constant evaluation of the template argument to fail with: nontype-class58.C: In instantiation of ‘void f() [with Bar V = Bar{Foo()}]’: nontype-class58.C:22:11: required from here nontype-class58.C:18:18: error: ‘constexpr Bar::Bar(const Bar&)’ used before its definition Conveniently we already make sure to instantiate eligible constexpr functions before such (manifestly) constant evaluation, as per P0859R0. So this patch fixes this by making sure to synthesize eligible defaulted constexpr functions beforehand as well. PR c++/110122 gcc/cp/ChangeLog: * constexpr.cc (instantiate_cx_fn_r): Also synthesize defaulted functions. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/nontype-class58.C: New test. --- gcc/cp/constexpr.cc | 7 ++++-- gcc/testsuite/g++.dg/cpp2a/nontype-class58.C | 23 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/nontype-class58.C diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 8f7f0b7d325..a7efebcded1 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -8110,11 +8110,14 @@ instantiate_cx_fn_r (tree *tp, int *walk_subtrees, void */*data*/) && DECL_DECLARED_CONSTEXPR_P (*tp) && !DECL_INITIAL (*tp) && !trivial_fn_p (*tp) - && DECL_TEMPLOID_INSTANTIATION (*tp) + && (DECL_TEMPLOID_INSTANTIATION (*tp) || DECL_DEFAULTED_FN (*tp)) && !uid_sensitive_constexpr_evaluation_p ()) { ++function_depth; - instantiate_decl (*tp, /*defer_ok*/false, /*expl_inst*/false); + if (DECL_TEMPLOID_INSTANTIATION (*tp)) + instantiate_decl (*tp, /*defer_ok*/false, /*expl_inst*/false); + else + synthesize_method (*tp); --function_depth; } else if (TREE_CODE (*tp) == CALL_EXPR diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class58.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class58.C new file mode 100644 index 00000000000..6e40698da2f --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class58.C @@ -0,0 +1,23 @@ +// PR c++/110122 +// { dg-do compile { target c++20 } } + +struct Foo { + Foo() = default; + constexpr Foo(const Foo&) { } +}; + +struct Bar { + Foo _; +}; + +template +struct A { }; + +template +void f() { + [](auto){ A d; }(0); // { dg-bogus "used before its definition" } +}; + +int main() { + f(); +}