From patchwork Thu Apr 7 03:25:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1614247 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=WG4OzZhp; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KYmy063RVz9sFk for ; Thu, 7 Apr 2022 13:26:31 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 18BA13858427 for ; Thu, 7 Apr 2022 03:26:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 18BA13858427 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1649301986; bh=FDrY25VUbijH7sg2ajVrPg31FUvdjtOcckMKmFTRK7c=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=WG4OzZhp9yOm/8+QHSDDTrOj1qacQ5Bxc9xjUfxfm3B/uZJrZzi81N1M4e4fD8XJX h4DMo4TnjpwkEM193J0vN+elQsJHkwRzDxA1dN0/XN4BIFpJoQ9VKLM2xutmFC+xec lBcDds2yc97fbZpLZnH8cGy9FRI/Ziwz4i3xi+P8= 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 259AC3858C54 for ; Thu, 7 Apr 2022 03:25:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 259AC3858C54 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-232-g5-BmXkjNoSnw_2ykECISw-1; Wed, 06 Apr 2022 23:25:41 -0400 X-MC-Unique: g5-BmXkjNoSnw_2ykECISw-1 Received: by mail-qv1-f72.google.com with SMTP id fw9-20020a056214238900b0043522aa5b81so5571981qvb.21 for ; Wed, 06 Apr 2022 20:25:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=FDrY25VUbijH7sg2ajVrPg31FUvdjtOcckMKmFTRK7c=; b=A2h/B8/Q8s+WlGEAI/Rywac5O37HPV8CA5kr0p2wteYfYM8AG9MdsE+xYT4nLir200 vMAVqWV68x47tgRCBTPMQ79QJyrOUxMUORkZ37k+MzodhSfayNYgL4IQo09jwxLm5ksx Ldvusx/5XTB5011CuUsfwOWexTUlfKmXCBPYhqGjeg9sdgyRpOXVuniNE2oVLO/W2edT KGSeflO8JzzR2VGrtV/IaY9wWfLA+Dx7Pt4jXS1ML8suihak7RFJ4ZVw2PziITsmbxOF k0W2PwGlnF5wyn2BQ1VkIfHmvF5Dh+5+VHpkL0A0RKfj+RP/Y2WF1lPM2SKWT4wP7O9p whoA== X-Gm-Message-State: AOAM530OoMOeUwP7SwLXI/2QFrpV/DuN2cSYS0t1g8pMTJy7wW6Y1P+J plLBsa5uCfLyTJOblVbwgvZX9jfD1s3RJPyTorqJ0Q8aAExpOHZoumkemUwRnhQajYvMaLfTsvj dxq8Fvggz47/4/sM+KgqlXmirlDK6ep1Tj3CTIPwX7Lsa2jG9fL0x8inmVDTqXff8RA== X-Received: by 2002:a05:620a:40ce:b0:67d:4ebe:f3c2 with SMTP id g14-20020a05620a40ce00b0067d4ebef3c2mr7700246qko.631.1649301940837; Wed, 06 Apr 2022 20:25:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFhzxaAl632ZMmfkep+8t7F8lyHyWHRKt0I1Xu+R2iGDSq+c/4HVNMafPkuT3q6M8sTUO22Q== X-Received: by 2002:a05:620a:40ce:b0:67d:4ebe:f3c2 with SMTP id g14-20020a05620a40ce00b0067d4ebef3c2mr7700236qko.631.1649301940446; Wed, 06 Apr 2022 20:25:40 -0700 (PDT) Received: from barrymore.redhat.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 y7-20020a05620a0e0700b00699a30d6d10sm10191192qkm.111.2022.04.06.20.25.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 20:25:39 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: nested generic lambda in DMI [PR101717] Date: Wed, 6 Apr 2022 23:25:36 -0400 Message-Id: <20220407032536.2422317-1-jason@redhat.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.0 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_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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" We were already checking COMPLETE_TYPE_P to recognize instantiation of a generic lambda, but didn't consider that we might be nested in a non-generic lambda. Tested x86_64-pc-linux-gnu, applying to trunk. PR c++/101717 gcc/cp/ChangeLog: * lambda.cc (lambda_expr_this_capture): Check all enclosing lambdas for completeness. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/lambda-generic-this4.C: New test. --- gcc/cp/lambda.cc | 8 +++++++- gcc/testsuite/g++.dg/cpp1y/lambda-generic-this4.C | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/lambda-generic-this4.C base-commit: d9421784980276b42ecdce85b6dde28e965c88c6 diff --git a/gcc/cp/lambda.cc b/gcc/cp/lambda.cc index 4cc3a47f9c2..f22798d51e8 100644 --- a/gcc/cp/lambda.cc +++ b/gcc/cp/lambda.cc @@ -741,6 +741,7 @@ lambda_expr_this_capture (tree lambda, int add_capture_p) { tree lambda_stack = NULL_TREE; tree init = NULL_TREE; + bool saw_complete = false; /* If we are in a lambda function, we can move out until we hit: 1. a non-lambda function or NSDMI, @@ -759,6 +760,11 @@ lambda_expr_this_capture (tree lambda, int add_capture_p) lambda_stack); tree closure = LAMBDA_EXPR_CLOSURE (tlambda); + if (COMPLETE_TYPE_P (closure)) + /* We're instantiating a generic lambda op(), the containing + scope may be gone. */ + saw_complete = true; + tree containing_function = decl_function_context (TYPE_NAME (closure)); @@ -768,7 +774,7 @@ lambda_expr_this_capture (tree lambda, int add_capture_p) /* Lambda in an NSDMI. We don't have a function to look up 'this' in, but we can find (or rebuild) the fake one from inject_this_parameter. */ - if (!containing_function && !COMPLETE_TYPE_P (closure)) + if (!containing_function && !saw_complete) /* If we're parsing a lambda in a non-local class, we can find the fake 'this' in scope_chain. */ init = scope_chain->x_current_class_ptr; diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-this4.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-this4.C new file mode 100644 index 00000000000..38d582bec5e --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-this4.C @@ -0,0 +1,7 @@ +// PR c++/101717 +// { dg-do compile { target c++14 } } + +struct x { + static void f() { } + void (*_)() = [] { [=](auto) { f(); }(0); }; +};