From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 5F18C3858D1E for ; Thu, 19 Oct 2023 15:07:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5F18C3858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5F18C3858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697728067; cv=none; b=IDUAh8MBBcWEl6fGKg/zivdKf++PLcQoYn0VOXUO8BCepAVawxwaFQ6T/UcFvFwOl8nSlbT9KmdStm1y8HwEyZqwLG2FvmqiAGH5imAQlR+xd+ZmxJvGDqMYKiXDAuNiAkmTtAofwbWV54dnjTIfztm4TlJj+/d8X9Fvx+AdWQ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697728067; c=relaxed/simple; bh=SfQlN2BuVTA4Nj0ELHiKsFMQ2rULwulgJZCQNf7y0bc=; h=DKIM-Signature:From:Date:To:Subject:Message-ID:MIME-Version; b=NRMMY/fjBv1e2lbH7BV5wkO9SNcKwgtA2OBpimqkraBXpui0RZAyH5iAH0PbCZ5+tQbiYM6dVSnH8wMnfff5Wgwf2l9kD1MWVyOoMUM23cRaMXD+0K2xBdFuJs4rxO1bmFJFZBlSE9lQWbHX1x5u37drMEFyd6jIwR55K+cgGfs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697728065; 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: in-reply-to:in-reply-to:references:references; bh=Z+fWGy7/uj34sR/jn98nZhPqf6WrWg9WHL1kdBfNxQQ=; b=D1yiETFQs54hDrF4sNZdPRihRPH/VW8ds+4JMKD74sy9uAeemHvruF2sq2XVMnwWTjwEQW 9NHb2UoekpUlV8K37lD7E+RK37UwH3Rn8sXM8h4Rzr9muqnZ4s54xYY10vyuCPZIkWMp3d 1eEkrCH7YQSbPNea379ba4w0/WCnZGQ= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-570-2ayE2noTNAiKiuovwZ-Q_w-1; Thu, 19 Oct 2023 11:07:43 -0400 X-MC-Unique: 2ayE2noTNAiKiuovwZ-Q_w-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-417fd6a8575so93444991cf.2 for ; Thu, 19 Oct 2023 08:07:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697728063; x=1698332863; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Z+fWGy7/uj34sR/jn98nZhPqf6WrWg9WHL1kdBfNxQQ=; b=J/YV7O+nAHeLTyNBl0sq4xiKLntlYFXmMK6fieKbzLbp3uF4bG0mFgnKf2fKxPNP6q YMhptiMIo1V9FH6PjwIZCD7lSgTz/OxSg7NGjxGhV1QVNdBA+DpDhXpzU3UeRi4t46wf 0rcTBAFzpFpSTT99o5yKSW4dEFSYvFrK4O34F5jUCMz121W/IyEhIQegXP9hAgODSGuH 4Ds/0prp3eApk408leUdK2fb/NMLfH7xd4ipcua++fGEnL3k/WT2nDUHWpAOCA3trZra afu6QLmEfEJlBpwaOhqGSh2jY2x5hrUIm83VokC2bUab9XDMkf7WMLDo+A+aS6eenIB8 hBEg== X-Gm-Message-State: AOJu0YxfD7RHzTq3KTdtUpYAu6TbogFk1KbZ9UwzDhSBx45azE+X8R47 RaxCKdnW23m5CQJYjwPmizRQKIbmDShP0Ia4m4//VWL/x4ersOxMhy1IcNsJs57HKQg9F0E67Ql Q2I4LXTNX0Owum/MSwA== X-Received: by 2002:a05:622a:452:b0:419:6391:6bef with SMTP id o18-20020a05622a045200b0041963916befmr2843559qtx.0.1697728062842; Thu, 19 Oct 2023 08:07:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFjeqT+62QEQ363Qpz0Ik86HlvQPzl4ioo5YTD3sJ3NBhjd6WAQWGABagjtzAQiBOq/yK1haQ== X-Received: by 2002:a05:622a:452:b0:419:6391:6bef with SMTP id o18-20020a05622a045200b0041963916befmr2843532qtx.0.1697728062481; Thu, 19 Oct 2023 08:07:42 -0700 (PDT) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id i12-20020a05622a08cc00b00403cce833eesm795122qte.27.2023.10.19.08.07.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 08:07:42 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Thu, 19 Oct 2023 11:07:41 -0400 (EDT) To: Jason Merrill cc: Patrick Palka , gcc-patches@gcc.gnu.org Subject: Re: [PATCH 2/1] c++: more non-static memfn call dependence cleanup [PR106086] In-Reply-To: <9329458c-ba27-4fc6-a633-6a5d24b3e7d7@redhat.com> Message-ID: References: <20230926142112.1779722-1-ppalka@redhat.com> <20230926154013.2413300-1-ppalka@redhat.com> <3afd5cab-31df-2bb7-e668-07168dbb35bb@idea> <9329458c-ba27-4fc6-a633-6a5d24b3e7d7@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-13.8 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,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 List-Id: On Thu, 19 Oct 2023, Jason Merrill wrote: > On 10/12/23 14:49, Patrick Palka wrote: > > On Tue, 26 Sep 2023, Patrick Palka wrote: > > > > > 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 > > > > On second thought there's no good reason to split these patches into a two > > part series, so here's a single squashed patch: > > OK. Thanks. It turns out this patch slightly depends on the NON_DEPENDENT_EXPR removal patches, since without them finish_call_expr in a template context will undesirably do build_non_dependent_expr on the fn/args before its COMPONENT_REF branch that dispatches to build_new_method_call, but this latter function expects to be called with unwrapped fn/args. This (seemingly latent bug) can trivially be fixed by moving finish_call_expr's build_non_dependent_expr calls to happen after the COMPONENT_REF branch, but I reckon I'll just wait until the NON_DEPENDENT_EXPR removal patches are in before pushing this one. > > > -- >8 -- > > > > Subject: [PATCH] c++: non-static memfn call dependence cleanup [PR106086] > > > > In cp_parser_postfix_expression and in the CALL_EXPR case of > > tsubst_copy_and_build, we essentially repeat the type-dependent and > > COMPONENT_REF callee cases of finish_call_expr. This patch deduplicates > > this logic by making both spots consistently go through finish_call_expr. > > > > This allows us to easily fix PR106086 -- which is about us neglecting to > > capture 'this' when we resolve a use of a non-static member function of > > the current instantiation only at lambda regeneration time -- by moving > > the call to maybe_generic_this_capture from the parser to finish_call_expr > > so that we consider capturing 'this' at regeneration time as well. > > > > PR c++/106086 > > > > gcc/cp/ChangeLog: > > > > * parser.cc (cp_parser_postfix_expression): Consolidate three > > calls to finish_call_expr, one to build_new_method_call and > > one to build_min_nt_call_vec into one call to finish_call_expr. > > Don't call maybe_generic_this_capture here. > > * pt.cc (tsubst_copy_and_build) : Remove > > COMPONENT_REF callee handling. > > (type_dependent_expression_p): Use t_d_object_e_p instead of > > t_d_e_p for COMPONENT_REF and OFFSET_REF. > > * semantics.cc (finish_call_expr): In the type-dependent case, > > call maybe_generic_this_capture here instead. > > > > gcc/testsuite/ChangeLog: > > > > * g++.dg/template/crash127.C: Expect additional error due to > > being able to check the member access expression ahead of time. > > Strengthen the test by not instantiating the class template. > > * g++.dg/cpp1y/lambda-generic-this5.C: New test. > > --- > > gcc/cp/parser.cc | 52 +++---------------- > > gcc/cp/pt.cc | 27 +--------- > > gcc/cp/semantics.cc | 12 +++-- > > .../g++.dg/cpp1y/lambda-generic-this5.C | 22 ++++++++ > > gcc/testsuite/g++.dg/template/crash127.C | 3 +- > > 5 files changed, 38 insertions(+), 78 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 f3abae716fe..b00ef36b831 100644 > > --- a/gcc/cp/parser.cc > > +++ b/gcc/cp/parser.cc > > @@ -8047,54 +8047,12 @@ cp_parser_postfix_expression (cp_parser *parser, > > bool address_p, bool cast_p, > > close_paren_loc); > > iloc_sentinel ils (combined_loc); > > - if (TREE_CODE (postfix_expression) == COMPONENT_REF) > > - { > > - tree instance = TREE_OPERAND (postfix_expression, 0); > > - tree fn = TREE_OPERAND (postfix_expression, 1); > > - > > - if (processing_template_decl > > - && (type_dependent_object_expression_p (instance) > > - || (!BASELINK_P (fn) > > - && TREE_CODE (fn) != FIELD_DECL) > > - || type_dependent_expression_p (fn) > > - || any_type_dependent_arguments_p (args))) > > - { > > - maybe_generic_this_capture (instance, fn); > > - postfix_expression > > - = build_min_nt_call_vec (postfix_expression, args); > > - } > > - else if (BASELINK_P (fn)) > > - { > > - postfix_expression > > - = (build_new_method_call > > - (instance, fn, &args, NULL_TREE, > > - (idk == CP_ID_KIND_QUALIFIED > > - ? LOOKUP_NORMAL|LOOKUP_NONVIRTUAL > > - : LOOKUP_NORMAL), > > - /*fn_p=*/NULL, > > - complain)); > > - } > > - else > > - postfix_expression > > - = finish_call_expr (postfix_expression, &args, > > - /*disallow_virtual=*/false, > > - /*koenig_p=*/false, > > - complain); > > - } > > - else if (TREE_CODE (postfix_expression) == OFFSET_REF > > - || TREE_CODE (postfix_expression) == MEMBER_REF > > - || TREE_CODE (postfix_expression) == DOTSTAR_EXPR) > > + if (TREE_CODE (postfix_expression) == OFFSET_REF > > + || TREE_CODE (postfix_expression) == MEMBER_REF > > + || TREE_CODE (postfix_expression) == DOTSTAR_EXPR) > > postfix_expression = (build_offset_ref_call_from_tree > > (postfix_expression, &args, > > complain)); > > - else if (idk == CP_ID_KIND_QUALIFIED) > > - /* A call to a static class member, or a namespace-scope > > - function. */ > > - postfix_expression > > - = finish_call_expr (postfix_expression, &args, > > - /*disallow_virtual=*/true, > > - koenig_p, > > - complain); > > else > > /* All other function calls. */ > > { > > @@ -8107,12 +8065,14 @@ cp_parser_postfix_expression (cp_parser *parser, > > bool address_p, bool cast_p, > > "not permitted in intervening code"); > > parser->omp_for_parse_state->fail = true; > > } > > + bool disallow_virtual = (idk == CP_ID_KIND_QUALIFIED); > > postfix_expression > > = finish_call_expr (postfix_expression, &args, > > - /*disallow_virtual=*/false, > > + disallow_virtual, > > koenig_p, > > complain); > > } > > + > > if (close_paren_loc != UNKNOWN_LOCATION) > > postfix_expression.set_location (combined_loc); > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > > index 382db4dd01d..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. > > */ > > @@ -28585,7 +28560,7 @@ type_dependent_expression_p (tree expression) > > if (TREE_CODE (expression) == COMPONENT_REF > > || TREE_CODE (expression) == OFFSET_REF) > > { > > - if (type_dependent_expression_p (TREE_OPERAND (expression, 0))) > > + if (type_dependent_object_expression_p (TREE_OPERAND (expression, > > 0))) > > return true; > > expression = TREE_OPERAND (expression, 1); > > if (identifier_p (expression)) > > 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; > > diff --git a/gcc/testsuite/g++.dg/template/crash127.C > > b/gcc/testsuite/g++.dg/template/crash127.C > > index b7c03251f8c..fcf72d871db 100644 > > --- a/gcc/testsuite/g++.dg/template/crash127.C > > +++ b/gcc/testsuite/g++.dg/template/crash127.C > > @@ -16,7 +16,6 @@ struct C : public A > > { > > B < &A::A > b; // { dg-error "taking address of constructor 'A::A" "" > > { target c++98_only } } > > // { dg-error "taking address of constructor 'constexpr A::A" "" { > > target c++11 } .-1 } > > + // { dg-error "template argument 1 is invalid" "" { target *-*-* } .-2 > > } > > } > > }; > > - > > -template class C < int >; > >