From patchwork Tue Jan 24 22:11:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 47923 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2396753wrn; Tue, 24 Jan 2023 14:12:03 -0800 (PST) X-Google-Smtp-Source: AK7set9e3fois2pXv6wX0vhoefb3X9JGQDy0yubzHR0bhow37nXDHjpG4u+qCULoG86DgItQqfcp X-Received: by 2002:a05:6402:530a:b0:49f:f60d:1692 with SMTP id eo10-20020a056402530a00b0049ff60d1692mr4523935edb.24.1674598323265; Tue, 24 Jan 2023 14:12:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674598323; cv=none; d=google.com; s=arc-20160816; b=ujTTIi41W72aNiUUXbTnqGI9X7MQ0AClXQ61XxjoRiFVQAHrmAWRiRSiBQZbgXgIh5 6uT5cML7KqzKbyqMEY2sJ5Z/6zeqhZuoeQmSdyEEKCYdMoyPfwMh0OTqXxGPwcOMFxFD jjm795yC6dupNAEf2Y5uu7zkplxeJ6eImJYMb1PXnbU/rNWJOJcxiDCiaeO/MTZQ8mAu td9+mFCmxTXhqzVlNTiHa88j4ghxNSHqTpXxT0lmXNjvk9NDHi0TD53McgN/N+OzoWgG 1HkIgoPL6bW1bAWOlVjeiJILFEDzwB/yHgx1B54p3lgHXGzdH2rpB5u1jF1uUam/kaXz oqjg== 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:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=R/LInibQSY7Ft2jhEP13VdOEURYftnd3OGAXbDEjD18=; b=j+OxMx6zKaARBxHvLkWYMSce5m4uF9gem5P7YPiefyxW4aIv4GFIiN+czZ0gO38kj6 XG6eTYY6Lt1b1cqHWtBvaCwLMr5e3HtlOifuBichQgHKR3eyKwuykI/hrFWeqooWeM0+ E7UDSrK/zX48mm1yH4f8efjA2Tj7/YWLwSn5qfMGWJER3dCoJkXppzD5yFsGSgrZo4er DGwneS1DG1Bw3nrxKIVMfEUA1n+pQAQfIgK7BngokBO+oePgAxfiz1Pl0w2RsLLaSpEA J0pWeWFAIirOcZGcCuvfSlA03AFO73ae2MDgwGuSPSW6mNtM1Npl/JdX1mARJGk5I5KH d8hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ZfoXA777; 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 d1-20020aa7ce01000000b0049e27c2853bsi3880466edv.281.2023.01.24.14.12.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jan 2023 14:12:03 -0800 (PST) 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=ZfoXA777; 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 3AD993858438 for ; Tue, 24 Jan 2023 22:11:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3AD993858438 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674598318; bh=R/LInibQSY7Ft2jhEP13VdOEURYftnd3OGAXbDEjD18=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ZfoXA777dRLRDODHsw9dt+4hLWHpWh2EyQ25uf9enPJNfx1RcE7NbJRFUUIIi9zbs 2xkNIWGC4YYP2w/qhL2dbEzxlJLPrSVYtZ/iUbCGGirrQ2/iHZENz8HUXFmztO0cEr F6ljMI5j3jHkAKDMigsL20dbd+3C1YfozL6eX2KM= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id B1F443858D1E for ; Tue, 24 Jan 2023 22:11:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B1F443858D1E Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-592-nsGap9YyOO-kjHf-bnVqIg-1; Tue, 24 Jan 2023 17:11:11 -0500 X-MC-Unique: nsGap9YyOO-kjHf-bnVqIg-1 Received: by mail-qv1-f71.google.com with SMTP id op7-20020a056214458700b0053548eb08b8so8283358qvb.10 for ; Tue, 24 Jan 2023 14:11:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=R/LInibQSY7Ft2jhEP13VdOEURYftnd3OGAXbDEjD18=; b=2yeOMAQCohkZI4NDUvlP10A8B2Qitq4pygFMoGnJlMktprJyIOyYkBvY9uqPeWQYBf xfR9Ah9rkDEziJwS/odIsHT1fctwCBhe9NqHGZkLaH28IJovcuGwOcwBIE2RguBJztTo xAWcoRHD6gCLCTqgNgMAwJ3CWkUmaS1ORti6MdS4SmNd2VYaO3eROTCYCIt78os5qXeb 2/BwhX6ut1YghinDuVTO6A6oMi7wALXrsDgptUtFvDhzVE5KTINlBBSYDDxU/c0VRQf2 3PSNaljq6P4cTf1XJdIlPsJ96CjIPQz+8jb3FQ7C5MwAmPOKnacKre7CbzBi0ODM155E v6ag== X-Gm-Message-State: AFqh2krf67dfCQwvV9bJr0nRnW4AWpLuvV+FiWNqGDjgf9WFkxwda7Ii Ne9Y17TL4GAxgAy0erePIckkiHgiZHecCnSbnncqkSPGAB88HhitMQDmvC3qMyh6Wd2y23e429x KwLxO1Hv22VlTNafyy/RN+EXjmBAwapf5yHfL8tGOa/iiKQqStuJ4Wjz29j7HaWiuLA== X-Received: by 2002:ac8:7248:0:b0:3b6:35cc:a5c1 with SMTP id l8-20020ac87248000000b003b635cca5c1mr42175384qtp.20.1674598270477; Tue, 24 Jan 2023 14:11:10 -0800 (PST) X-Received: by 2002:ac8:7248:0:b0:3b6:35cc:a5c1 with SMTP id l8-20020ac87248000000b003b635cca5c1mr42175352qtp.20.1674598270032; Tue, 24 Jan 2023 14:11:10 -0800 (PST) Received: from jason.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id x7-20020ac87a87000000b003ae33f9260dsm2029991qtr.49.2023.01.24.14.11.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jan 2023 14:11:09 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: static lambda in template [PR108526] Date: Tue, 24 Jan 2023 17:11:06 -0500 Message-Id: <20230124221106.299101-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.5 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, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP 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: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill 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?1755943611492391904?= X-GMAIL-MSGID: =?utf-8?q?1755943611492391904?= Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- tsubst_lambda_expr uses build_memfn_type to build a METHOD_TYPE for the new lamba op(). This is not what we want for a C++23 static op(), but since we also use that METHOD_TYPE to communicate the closure type down to tsubst_function_decl, let's wait and turn it back at that point. PR c++/108526 gcc/cp/ChangeLog: * pt.cc (tsubst_function_decl): Handle static lambda. gcc/testsuite/ChangeLog: * g++.dg/cpp23/static-operator-call5.C: New test. --- gcc/cp/pt.cc | 5 +++++ gcc/testsuite/g++.dg/cpp23/static-operator-call5.C | 8 ++++++++ 2 files changed, 13 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp23/static-operator-call5.C base-commit: 049a52909075117f5112971cc83952af2a818bc1 diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 2a4d03c5e47..51fc246ed71 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -14306,6 +14306,11 @@ tsubst_function_decl (tree t, tree args, tsubst_flags_t complain, tree ctx = closure ? closure : DECL_CONTEXT (t); bool member = ctx && TYPE_P (ctx); + /* If this is a static lambda, remove the 'this' pointer added in + tsubst_lambda_expr now that we know the closure type. */ + if (lambda_fntype && DECL_STATIC_FUNCTION_P (t)) + lambda_fntype = static_fn_type (lambda_fntype); + if (member && !closure) ctx = tsubst_aggr_type (ctx, args, complain, t, /*entering_scope=*/1); diff --git a/gcc/testsuite/g++.dg/cpp23/static-operator-call5.C b/gcc/testsuite/g++.dg/cpp23/static-operator-call5.C new file mode 100644 index 00000000000..ae022d0b971 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp23/static-operator-call5.C @@ -0,0 +1,8 @@ +// PR c++/108526 +// { dg-do compile { target c++23 } } + +template void f() +{ + auto a = [] (auto x) static { return x; }; +} +template void f();