From patchwork Fri Jul 1 14:51:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1651268 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=MvC5ybqj; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LZJ7N0nnpz9s07 for ; Sat, 2 Jul 2022 00:51:44 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EC03F385C41F for ; Fri, 1 Jul 2022 14:51:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EC03F385C41F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1656687102; bh=Px+9ber4DQ61ymMffJsd2kWPTySwp16ahh59HeEfC+w=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=MvC5ybqj6gHhKss0XzWIr7NLIoxGj6muMvPpTEyb3A6HuuVgQgsJ8b8GtlgcVeymu cDZE5RjAU7Xg9+9o8NN8WdtsaTcSbzfeDDiYzNflpkP62gabD5fpgS8qfiZ5Uc0D/9 tdJzEpnASgpvTfReVbdnypNH6Z+2PZaxwjOTRRR8= 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 7A10F3858D28 for ; Fri, 1 Jul 2022 14:51:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7A10F3858D28 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-244-NlZ053dDOTSeSPeTRqMADg-1; Fri, 01 Jul 2022 10:51:20 -0400 X-MC-Unique: NlZ053dDOTSeSPeTRqMADg-1 Received: by mail-qk1-f199.google.com with SMTP id m15-20020a05620a290f00b006a74cf760b2so2246540qkp.20 for ; Fri, 01 Jul 2022 07:51:20 -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=Px+9ber4DQ61ymMffJsd2kWPTySwp16ahh59HeEfC+w=; b=l6juVpK+IoZRSI3nD+AVC//ovFJ0lh+zdj96RLPeYNFcFi3VZ1w7rbzPgbOGQF2led OOpXadJBGUqwHsSkf8UnPE4nH60OgDZf+iGK3tqbkOeIDkt2dbegbsdAmA4uRLO4JuSP I/ugKDCHQ8STaJFTMcRcDXg8dMGmaeenKB7xcEIgKB+APORFKMggoHctZ/2yJKpChFyJ QOK3xqdAQZ/tbU2wgOFWI7DexWTz0xyJiE9ohrq3QnO2+QnVw8QoO4ydDmgLcJfyOFh6 uVypb8816w6H8vPFW+tORgEeOQrAQd9/5uwRONgCvDRyROsxcnPg4328IdlEhiW5IljF FMJg== X-Gm-Message-State: AJIora+4EuH5iRhpXnUwxtNMcSleRN0n6pZrw19yzBlseSDXivNcTt8w D5lU21kaF1Bs9Ds8KHKKOfAED72XS0bZb85FUrzRHvi/jAODuaLf6gw3Yr7FCM2uEvO3L/AK7PJ hJEWoZUCy11LT8qug7+EOMqxSDg/8Gu17wWnYeC6yIdMTl6EMyjBvyxDe9sZagW1rwg== X-Received: by 2002:a05:620a:2727:b0:6b2:52ed:913 with SMTP id b39-20020a05620a272700b006b252ed0913mr3618640qkp.435.1656687079423; Fri, 01 Jul 2022 07:51:19 -0700 (PDT) X-Google-Smtp-Source: AGRyM1stc8M0KEGNJ3hEN3F3h7xzNHwgjMApqBk4xJ0JL1Z5r3z+CPevFOypysPobiWUfuZ3FIsexQ== X-Received: by 2002:a05:620a:2727:b0:6b2:52ed:913 with SMTP id b39-20020a05620a272700b006b252ed0913mr3618609qkp.435.1656687078909; Fri, 01 Jul 2022 07:51:18 -0700 (PDT) Received: from barrymore.cygnus.csb (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 r132-20020a37a88a000000b006af373cec2csm9964728qke.70.2022.07.01.07.51.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Jul 2022 07:51:18 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: dependent generic lambda template-id [PR106024] Date: Fri, 1 Jul 2022 10:51:16 -0400 Message-Id: <20220701145116.906999-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_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: 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 wrongly looking up the generic lambda op() in a dependent scope, and then trying to look up its instantiation at substitution time, but lambdas aren't instantiated, so we crashed. The fix is to not look into dependent class scopes. But this created trouble with wrongly trying to use a template from the enclosing scope when we aren't actually looking at a template-argument-list, in template/lookup18.C, so let's avoid that. Tested x86_64-pc-linux-gnu, applying to trunk and 12. PR c++/106024 gcc/cp/ChangeLog: * parser.cc (missing_template_diag): Factor out... (cp_parser_id_expression): ...from here. (cp_parser_lookup_name): Don't look in dependent object_type. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/lambda-generic10.C: New test. --- gcc/cp/parser.cc | 23 ++++++++++++++++++- gcc/testsuite/g++.dg/cpp2a/lambda-generic10.C | 14 +++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-generic10.C base-commit: 63abe04999283582b258adf60da6c19d541ebc68 diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index da2f370cdca..357fde557c7 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -30676,9 +30676,11 @@ cp_parser_lookup_name (cp_parser *parser, tree name, } else if (object_type) { + bool dep = dependent_scope_p (object_type); + /* Look up the name in the scope of the OBJECT_TYPE, unless the OBJECT_TYPE is not a class. */ - if (CLASS_TYPE_P (object_type)) + if (!dep && CLASS_TYPE_P (object_type)) /* If the OBJECT_TYPE is a template specialization, it may be instantiated during name lookup. In that case, errors may be issued. Even if we rollback the current tentative @@ -30702,6 +30704,25 @@ cp_parser_lookup_name (cp_parser *parser, tree name, : is_template ? LOOK_want::TYPE : prefer_type_arg (tag_type)); + /* If we did unqualified lookup of a dependent member-qualified name and + found something, do we want to use it? P1787 clarified that we need + to look in the object scope first even if it's dependent, but for now + let's still use it in some cases. + FIXME remember unqualified lookup result to use if member lookup fails + at instantiation time. */ + if (decl && dep && is_template) + { + saved_token_sentinel toks (parser->lexer, STS_ROLLBACK); + /* Only use the unqualified class template lookup if we're actually + looking at a template arg list. */ + if (!cp_parser_skip_entire_template_parameter_list (parser)) + decl = NULL_TREE; + /* And only use the unqualified lookup if we're looking at ::. */ + if (decl + && !cp_lexer_next_token_is (parser->lexer, CPP_SCOPE)) + decl = NULL_TREE; + } + /* If we know we're looking for a type (e.g. A in p->A::x), mock up a typename. */ if (!decl && object_type && tag_type != none_type diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-generic10.C b/gcc/testsuite/g++.dg/cpp2a/lambda-generic10.C new file mode 100644 index 00000000000..47a87bbfbd7 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/lambda-generic10.C @@ -0,0 +1,14 @@ +// PR c++/106024 +// { dg-do compile { target c++20 } } + +void sink(...); +template void f() +{ + sink ([] (int...) { return 1; } + .operator()(args...)...); // { dg-warning "-Wmissing-template-keyword" } +} // { dg-prune-output {expected '\)'} } + +int main() +{ + f<1,2,3>(); +}