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: 1731453 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=r3H9pZUw; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4P1h5M4BLmz23gY for ; Wed, 25 Jan 2023 09:11:35 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7D1943858C39 for ; Tue, 24 Jan 2023 22:11:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7D1943858C39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674598293; bh=R/LInibQSY7Ft2jhEP13VdOEURYftnd3OGAXbDEjD18=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=r3H9pZUwHDUfTxZoNW8/rvhY1eywdlzi0vgY4zb0hNRqm+umSQCLpo4KUcxemWyb4 w53e/lgnRew6lSOhAsYVOBxtTXr4MkJEpyyV/CYqdrCCUW2RJgl5MYT/gGHA1/5Oqk 0D1VUkIrUnQi1tdObjrHiUvnUm5W4a2vtRm40ymc= 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-Google-Smtp-Source: AMrXdXvOcwkNBV3whlt6wNaf86kPL93E/eGiDicIbfNcyia9QzHVJSjxPWi71taMNzIerq4/WV4qTA== 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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();