From patchwork Mon May 3 16:48:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1473259 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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@gcc.gnu.org; receiver=) Authentication-Results: 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=qwzl7uZE; 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FYpnh0JCpz9sPf for ; Tue, 4 May 2021 02:48:23 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1E93A3954459; Mon, 3 May 2021 16:48:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1E93A3954459 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1620060500; bh=F86PT2mduIX5axAeKZTVN8fZTDFLYn4oN7PwOnzPtBI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=qwzl7uZEsY3zfYcPRHP7M36OdmH4weEC94O6seB3YrtP+OBU138JJQ5KAX7duy6DU n2eNr7ZX6rHETSp7ddsocJ7EG7MFGVUvRfr1tzF5mLqpC0XOadFiWKtw93cNi6atgd JQzH4a6XrYfldO0C815bNs4ytjNzL8b3LkcNaW9U= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 909DD393BC36 for ; Mon, 3 May 2021 16:48:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 909DD393BC36 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-475-bIegjX0NOW2zggXWNRl84A-1; Mon, 03 May 2021 12:48:12 -0400 X-MC-Unique: bIegjX0NOW2zggXWNRl84A-1 Received: by mail-qt1-f199.google.com with SMTP id d10-20020a05622a100ab02901b8224bae03so1796976qte.2 for ; Mon, 03 May 2021 09:48:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=F86PT2mduIX5axAeKZTVN8fZTDFLYn4oN7PwOnzPtBI=; b=QSxLYekYrsnRfQWFV6D+75jih1SMg61yn8eo2SdrAW6WNqjWluJcu/STg2Ry4Fa2YT u1nOriwYh7Pq9W0bUN9wUoLgiYbr8PAiJtYwUd73pFLYnKNzert0JYW3Muz1Un1M6xBT 418L8fKN9cb/iMgqf1JbS86Sc6n40pdHTJo1B/Ot8pxVZd6F3R9wOXzsx7GaJgopWpmB 8KX2GhRk+kuLQA3qEPomFj6OLwNWlWmTX3qTC7Ps5hLtqsNRCGs8ypPQPo7nCtoBbI4a j+7m8hpLXK9zvKtZwXvf1y4QzIUSCh7Ezy3Y8oGBVfeJdpJ+MRbXCWEojr2dR9gPhBby p3Lg== X-Gm-Message-State: AOAM5328c+0b6WlvUGvgS4X1YVRzGe8stg0OBRer1lSpx3HR15XbO/8J mhaZHAMd5EhorOAHc3nSzcogWJTHcWwG+fWo5FRhWvgih21v3Vfm9m+DXUBbUAz0Z03ssPsGeXJ +75u9eiFFhAI7Kn7Pyk9I9aOmfvCMI5nmnqwn14QeEtC1de//zwFh1lmCoYGCJ/WNv90= X-Received: by 2002:ac8:d83:: with SMTP id s3mr17960429qti.333.1620060491158; Mon, 03 May 2021 09:48:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4Lau9QI2JUdpSYLAmKSvMHkjd5p73sF9UfbXzueaY8zlXpbJTrYlyRJvDX6onJT6986CUiw== X-Received: by 2002:ac8:d83:: with SMTP id s3mr17960395qti.333.1620060490792; Mon, 03 May 2021 09:48:10 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id l199sm8922656qke.118.2021.05.03.09.48.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 May 2021 09:48:10 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: base-clause parsing and implicit 'this' [PR100362] Date: Mon, 3 May 2021 12:48:08 -0400 Message-Id: <20210503164808.155944-1-ppalka@redhat.com> X-Mailer: git-send-email 2.31.1.442.g7e39198978 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-16.4 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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@gcc.gnu.org Sender: "Gcc-patches" My r11-6815 change to defer access checking when processing a base-clause removed a pair of pushclass / popclass calls that seemed to be unnecessary now that we'd also defer access checking while parsing the base-clause. But it turns out this makes a difference in the below testcase, where we have a local class whose base clause implicitly uses the 'this' of the enclosing class. Before r11-6815, while parsing the base-clause of the local class, maybe_resolve_dummy would fail to resolve the dummy 'this' object because the current scope would be the local class. Now, since the current scope is the lambda, maybe_resolve_dummy succeeds and returns the 'this' for the enclosing class Qux. Later, during deferred instantiation of the local class, we get confused trying to resolve the access of 'a_' through this non-dummy 'this'. So this patch just reinstates the calls to pushclass / popclass that were removed in r11-6815. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? gcc/cp/ChangeLog: PR c++/100362 * parser.c (cp_parser_class_head): Reinstate calls to pushclass and popclass during parsing of the base-clause that were removed in r11-6815. gcc/testsuite/ChangeLog: PR c++/100362 * g++.dg/cpp1y/lambda-generic-100362.C: New test. --- gcc/cp/parser.c | 8 +++++- .../g++.dg/cpp1y/lambda-generic-100362.C | 25 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/lambda-generic-100362.C diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index e1b1617da68..28752611b34 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -25683,7 +25683,13 @@ cp_parser_class_head (cp_parser* parser, until the entire list has been seen, as per [class.access.general]. */ push_deferring_access_checks (dk_deferred); if (cp_lexer_next_token_is (parser->lexer, CPP_COLON)) - bases = cp_parser_base_clause (parser); + { + if (type) + pushclass (type); + bases = cp_parser_base_clause (parser); + if (type) + popclass (); + } else bases = NULL_TREE; diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-100362.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-100362.C new file mode 100644 index 00000000000..283c2c9477e --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-100362.C @@ -0,0 +1,25 @@ +// PR c++/100362 +// { dg-do compile { target c++14 } } + +template +struct Qux { + struct A { } a_; + A f(); + + void AsyncOp() { + [](auto) { + struct local : decltype(a_) {}; + local ptr; + }(0); + + [](auto) { + struct local : decltype(f()) {}; + local ptr; + }(0); + } +}; + +void corge() { + Qux qux; + qux.AsyncOp(); +}