From patchwork Tue Sep 26 15:40:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 144944 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp2009101vqu; Tue, 26 Sep 2023 08:40:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHi7aXCMdcVdvt7g4chQXZdF1j1zfs16OYE84FQaqsZ+OTHUTKIE/p6UFvJZ/TJQj34YlAK X-Received: by 2002:a05:6402:31e7:b0:532:c6d7:b93c with SMTP id dy7-20020a05640231e700b00532c6d7b93cmr9386855edb.5.1695742853622; Tue, 26 Sep 2023 08:40:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695742853; cv=none; d=google.com; s=arc-20160816; b=tRj3iCF2FJYABlhYSJ5N/j2YBXv9Uo9iowHG4LH7NQsiCqSKk4ZI1aLFSZ91zBiPGR e4N0Bar3JuM4tgRhv+Pq6Mwqvlsw9y4jF8+9aP7+KLdbIMcNHBIMxsgELpKUNq4+OvT6 vAgrJ/cqp4Xy+Yoyf0xv+6dzwMgq+8f2dgLsLYL01Pv07sJbFkoIU4e/AEgo+mfNwy5N s3nmFeAUtlDyOAPbTn+idzKQGVyOYn4xOaxgNpFRxPojz1PtNNBQb0lKh8/KqzW2hctE YtViA+CpsE0hEzw7bu4El1N/hTlHjhSb04nj2J9m2IoTK6CbOvG93BlWshOQFB+MGxcP JSbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:dmarc-filter:delivered-to; bh=yFnUKCYCnSYEva2TTgir+4cOg+YtPsMetGC0k7BlnlI=; fh=1Hi9m88IqcWZGtfSxUrMGG+GBgL26N02X1SANXM6iTs=; b=ubGpCBbnakWOGMzoqwYLZq/1xXY6LyM0A9GK+1r+z2XLEnLvbdh9rvxVfCrSQEwQai d/zo+LEVow2IMFDDEUnglIujdXOIaGNuq0ETu0hwfUzD4K3H5PtJ/byqs11B0GtCqxU0 nPzcMzlIj3pSuHWSlf9DaJM8HXcKWBC/CRQ9yBCByxxmOes+Lop0c/WDwTXktx9tda9C IhU8zMLkJnIkqLOXf4bGjhcdXTGqntpgfJoMX0uYd3Nx+Y14vFP6HRArUe5WpEi2CM/M lMjN23WPMflH/Bm5WLKuvWShgnXUkn79UhC7QuCZa0MZSYuFhVzXa8n2Uo56YvwPduGo MiyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HodNTlOO; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id t19-20020a056402525300b00533cb33e9e5si8252434edd.641.2023.09.26.08.40.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 08:40:53 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HodNTlOO; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5995A385DC35 for ; Tue, 26 Sep 2023 15:40:48 +0000 (GMT) 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 F1629385C426 for ; Tue, 26 Sep 2023 15:40:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F1629385C426 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695742820; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yFnUKCYCnSYEva2TTgir+4cOg+YtPsMetGC0k7BlnlI=; b=HodNTlOODbIemrjXmnMHpB3Mh5WJlaIJ4wx400O2iqNrWbI3htUT3tMEzxNzsRT2jlJhzZ Atr/cj6v7/DSrKgJBlfmz2JuJkwTGTBUD6Doq056W2ENpvh6UAcrOHUnD2Og4kWnH6n1Rb UmYLvWJnpEwBUptwoF8AKkKsEojW2JA= 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.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-582-cEjIJN6kNbKsaiubFuL_Aw-1; Tue, 26 Sep 2023 11:40:18 -0400 X-MC-Unique: cEjIJN6kNbKsaiubFuL_Aw-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-7740829f2bfso1529276385a.0 for ; Tue, 26 Sep 2023 08:40:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695742818; x=1696347618; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yFnUKCYCnSYEva2TTgir+4cOg+YtPsMetGC0k7BlnlI=; b=KTTSWC5DXL0nEhBpILbz53WJVCPKiocQY3bqEqFwANnawoZK4BpIcoMErVG4gz/YEx U3nGrnssGB7Zq8KgskcdMb6QJmpv4aP5IaJ8+Dbnb/qGZG7E2WCgG62nlo2qi9HrwSJt fofUJxxFM3zvw8GJHZ6j2+gevoN6EgwenFf+ZrHAS/iLb+qGs5KxS9B9wU0pjS/pvFsp 2YKdamQl9nzVBx2/N9HjWEE649ooNJ1kemFkfr9tX8HzIw7RjzD+G7Ua385lj8KEYOg5 R7qqa+d9IBe7EgXbCaToLXAg/lRCwhLpjsHpiGGu59w4PJZx65B9hipSrNjksvM0c+i7 EpcQ== X-Gm-Message-State: AOJu0YxdZ+2/FYLtijazdQZ5VT2OB56QVSEmg5aKv/dUfuQ8xQndRgwZ +aRjlKZW7P+YdUKxOeXMuSRPESW7YRITFqjmgK08V+n7+cAG7o4vG4i3gY97oodHZ/Z2eQTYmW1 fqURg+HdZKCccHhIxZLCNQhOKk9iPAsbQxPIIvO3GanAFs1u+zQS821o8I0PynDEkxDufQUmzkK U= X-Received: by 2002:a05:620a:24cd:b0:767:f108:a5c6 with SMTP id m13-20020a05620a24cd00b00767f108a5c6mr11887388qkn.57.1695742818090; Tue, 26 Sep 2023 08:40:18 -0700 (PDT) X-Received: by 2002:a05:620a:24cd:b0:767:f108:a5c6 with SMTP id m13-20020a05620a24cd00b00767f108a5c6mr11887366qkn.57.1695742817668; Tue, 26 Sep 2023 08:40:17 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id k5-20020ac80745000000b0041950c7f6d8sm561007qth.60.2023.09.26.08.40.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 08:40:16 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH 2/1] c++: more non-static memfn call dependence cleanup [PR106086] Date: Tue, 26 Sep 2023 11:40:13 -0400 Message-ID: <20230926154013.2413300-1-ppalka@redhat.com> X-Mailer: git-send-email 2.42.0.270.gbcb6cae296 In-Reply-To: <20230926142112.1779722-1-ppalka@redhat.com> References: <20230926142112.1779722-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.9 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_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_WEB, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778115258246903218 X-GMAIL-MSGID: 1778115258246903218 Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- This follow-up patch removes some more repetition of the type-dependent case of finish_call_expr, this time in of tsubst_copy_and_build. This allows us to easily fix PR106086 -- which is about us failing to capture 'this' when we resolve a use of a non-static member function of the current instantiation only at lambda regeneration time and neglect to capture 'this' -- by moving the call to maybe_generic_this_capture from the parser to finish_call_expr so that we attempt to capture 'this' at regeneration time as well. PR c++/106086 gcc/cp/ChangeLog: * parser.cc (cp_parser_postfix_expression): Don't call maybe_generic_this_capture here. * pt.cc (tsubst_copy_and_build) : Remove COMPONENT_REF callee handling. * semantics.cc (finish_call_expr): In the type-dependent case, call maybe_generic_this_capture here instead. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/lambda-generic-this5.C: New test. --- gcc/cp/parser.cc | 8 ------ gcc/cp/pt.cc | 25 ------------------- gcc/cp/semantics.cc | 12 ++++++--- .../g++.dg/cpp1y/lambda-generic-this5.C | 22 ++++++++++++++++ 4 files changed, 30 insertions(+), 37 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/lambda-generic-this5.C diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 78082ee7284..b00ef36b831 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -8071,14 +8071,6 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p, disallow_virtual, koenig_p, complain); - - if (type_dependent_expression_p (postfix_expression)) - { - tree fn = CALL_EXPR_FN (postfix_expression); - if (TREE_CODE (fn) == COMPONENT_REF) - maybe_generic_this_capture (TREE_OPERAND (fn, 0), - TREE_OPERAND (fn, 1)); - } } if (close_paren_loc != UNKNOWN_LOCATION) diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index b19b634690a..4400d429b6f 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -21364,31 +21364,6 @@ tsubst_copy_and_build (tree t, || TREE_CODE (function) == MEMBER_REF) ret = build_offset_ref_call_from_tree (function, &call_args, complain); - else if (TREE_CODE (function) == COMPONENT_REF) - { - tree instance = TREE_OPERAND (function, 0); - tree fn = TREE_OPERAND (function, 1); - - if (processing_template_decl - && (type_dependent_expression_p (instance) - || (!BASELINK_P (fn) - && TREE_CODE (fn) != FIELD_DECL) - || type_dependent_expression_p (fn) - || any_type_dependent_arguments_p (call_args))) - ret = build_min_nt_call_vec (function, call_args); - else if (!BASELINK_P (fn)) - ret = finish_call_expr (function, &call_args, - /*disallow_virtual=*/false, - /*koenig_p=*/false, - complain); - else - ret = (build_new_method_call - (instance, fn, - &call_args, NULL_TREE, - qualified_p ? LOOKUP_NONVIRTUAL : LOOKUP_NORMAL, - /*fn_p=*/NULL, - complain)); - } else if (concept_check_p (function)) { /* FUNCTION is a template-id referring to a concept definition. */ diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 1d478f0781f..412eaa12851 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -2793,18 +2793,19 @@ finish_call_expr (tree fn, vec **args, bool disallow_virtual, (c++/89780, c++/107363). This also suppresses the -Wredundant-move warning. */ suppress_warning (result, OPT_Wpessimizing_move); - if (is_overloaded_fn (fn)) - fn = get_fns (fn); if (cfun) { bool abnormal = true; - for (lkp_iterator iter (fn); abnormal && iter; ++iter) + for (lkp_iterator iter (maybe_get_fns (fn)); iter; ++iter) { tree fndecl = STRIP_TEMPLATE (*iter); if (TREE_CODE (fndecl) != FUNCTION_DECL || !TREE_THIS_VOLATILE (fndecl)) - abnormal = false; + { + abnormal = false; + break; + } } /* FIXME: Stop warning about falling off end of non-void function. But this is wrong. Even if we only see @@ -2814,6 +2815,9 @@ finish_call_expr (tree fn, vec **args, bool disallow_virtual, if (abnormal) current_function_returns_abnormally = 1; } + if (TREE_CODE (fn) == COMPONENT_REF) + maybe_generic_this_capture (TREE_OPERAND (fn, 0), + TREE_OPERAND (fn, 1)); return result; } orig_args = make_tree_vector_copy (*args); diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-this5.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-this5.C new file mode 100644 index 00000000000..42f917094d9 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-this5.C @@ -0,0 +1,22 @@ +// PR c++/106086 +// { dg-do compile { target c++14 } } + +template +struct A { + void f(int) const; + static void g(int); +}; + +template +struct B : A { + auto f() const { + auto l1 = [&](auto x) { A::f(x); }; + auto l2 = [&](auto x) { A::g(x); }; + static_assert(sizeof(l1) == sizeof(this), ""); + static_assert(sizeof(l2) == 1, ""); + l1(0); + l2(0); + } +}; + +template struct B;