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 B984B3858434 for ; Tue, 2 May 2023 19:35:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B984B3858434 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=1683056153; 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=gO7q0hhSKiCwnqEI+2A+xKAEkzvXFucpVf0hsSPG/xY=; b=NJTQsV2OxySiPD1GI33rZPwr7tZySspMWYZmM2sX85paHds8Lv3Pyl0h/xTgJ0NSMqkC39 Y2XteZFog04M7JvEqPxsKaOMxc5ldM3GmtLcr0pPSSKfLrTImDW62ZdfKkL8uO3BVqh9l5 pMj8r3GVejiDRJu3wzorwe9wH0A617g= 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-62-BVRDb0MNOgCM3HyRtKsycA-1; Tue, 02 May 2023 15:35:52 -0400 X-MC-Unique: BVRDb0MNOgCM3HyRtKsycA-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-3f060b8b39cso23037411cf.2 for ; Tue, 02 May 2023 12:35:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683056152; x=1685648152; 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=gO7q0hhSKiCwnqEI+2A+xKAEkzvXFucpVf0hsSPG/xY=; b=Oi85UV1t6Q4pTlQzpXD6dx029znCkikY5Wlr8W58LU0tx6/Wfks8l+UESJX29Zq2l2 9FoNdfwmaA3Lgwpv+HH5NZgsHmTtNvL1g8AA1jQFh7+IVzdxSN4Rz8Eth3VPFMgpYHbS yhzuEE7nM4xXKTFgr1CGosSIcIgtnKilz3FE9tkxsUUVQTNNyftsakl9zfrxAfGONobr zas4NXL/NWm1blNwpiWgDY/EikA9+U5FA9jGhjgp+vlS92zJekGb291rJVFHxctDMval 6VCvf2Dq8pqZhS3+IJvfRQ75oHXG3JV5PCPCw/hOiVLZMwkS/iDoNirH/y1GEXfq5SJr smYg== X-Gm-Message-State: AC+VfDxuOIrDIpvdiXuq7fxay6mOehgXKlxu71e6IvKH04+bwxJouWRT FzjN64jLrvnoOHky9rnd28m5ATU20ozHnvpTvcJGsVAVxU5CIrDJ1im0WZPng0FWVT6VzTPV0cT s6nf8AZ8JCblTVEMAzw== X-Received: by 2002:a05:622a:1054:b0:3f0:a511:174f with SMTP id f20-20020a05622a105400b003f0a511174fmr30480451qte.20.1683056151904; Tue, 02 May 2023 12:35:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ727OLtMGNHVCvRLPizpVlpNxpzu+vS0dw65Ya//elbHFTp4JYIIzgwVLl9sDiVCRKGNUsGQg== X-Received: by 2002:a05:622a:1054:b0:3f0:a511:174f with SMTP id f20-20020a05622a105400b003f0a511174fmr30480419qte.20.1683056151369; Tue, 02 May 2023 12:35:51 -0700 (PDT) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id r6-20020a05620a298600b0074cf9d16cb0sm9885118qkp.14.2023.05.02.12.35.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 May 2023 12:35:50 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Tue, 2 May 2023 15:35:50 -0400 (EDT) To: Jason Merrill cc: Patrick Palka , gcc-patches@gcc.gnu.org Subject: Re: [PATCH 1/2] c++: potentiality of templated memfn call [PR109480] In-Reply-To: <6da23365-02cd-8ac1-2fdc-91b284af6a68@redhat.com> Message-ID: <2aea65a6-eef7-d171-8790-bbb5b9c45d8a@idea> References: <20230501195902.1915703-1-ppalka@redhat.com> <6da23365-02cd-8ac1-2fdc-91b284af6a68@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.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_H2,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 List-Id: On Tue, 2 May 2023, Jason Merrill wrote: > On 5/1/23 15:59, Patrick Palka wrote: > > Here we're incorrectly deeming the templated call a.g() inside b's > > initializer as potentially constant, despite g being non-constexpr, > > which leads to us wastefully instantiating the initializer ahead of time > > and triggering a bug in access checking deferral (which will get fixed > > in the subsequent patch). > > > > This patch fixes this by calling get_fns earlier during potentiality > > checking so that we also handle the templated form of a member function > > call (whose overall callee is a COMPONENT_REF) when checking if the called > > function is constexpr etc. > > > > PR c++/109480 > > > > gcc/cp/ChangeLog: > > > > * constexpr.cc (potential_constant_expression_1) : > > Reorganize to call get_fns sooner. Remove dead store to 'fun'. > > > > gcc/testsuite/ChangeLog: > > > > * g++.dg/cpp0x/noexcept59.C: Make e() constexpr so that the > > expected "without object" diagnostic isn't replaced by a > > "call to non-constexpr function" diagnostic. > > * g++.dg/template/non-dependent25.C: New test. > > --- > > gcc/cp/constexpr.cc | 16 ++++++++-------- > > gcc/testsuite/g++.dg/cpp0x/noexcept59.C | 2 +- > > gcc/testsuite/g++.dg/template/non-dependent25.C | 14 ++++++++++++++ > > 3 files changed, 23 insertions(+), 9 deletions(-) > > create mode 100644 gcc/testsuite/g++.dg/template/non-dependent25.C > > > > diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc > > index d1097764b10..29d872d0a5e 100644 > > --- a/gcc/cp/constexpr.cc > > +++ b/gcc/cp/constexpr.cc > > @@ -9132,6 +9132,10 @@ potential_constant_expression_1 (tree t, bool > > want_rval, bool strict, bool now, > > if (fun && is_overloaded_fn (fun)) > > { > > + if (!RECUR (fun, true)) > > + return false; > > + fun = get_fns (fun); > > + > > if (TREE_CODE (fun) == FUNCTION_DECL) > > { > > if (builtin_valid_in_constant_expr_p (fun)) > > @@ -9167,7 +9171,8 @@ potential_constant_expression_1 (tree t, bool > > want_rval, bool strict, bool now, > > expression the address will be folded away, so look > > through it now. */ > > if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fun) > > - && !DECL_CONSTRUCTOR_P (fun)) > > + && !DECL_CONSTRUCTOR_P (fun) > > + && !processing_template_decl) > > I don't see any rationale for this hunk? Now that we call get_fns earlier, we can reach this code path with a templated non-static memfn call, but the code that follows assumes non-templated form. I tried teaching it to handle the templated form too, but there's apparently two different templated forms for non-static memfn calls, one with a COMPONENT_REF callee and one with an ordinary BASELINK callee (without a implicit object argument). In the former the implict object argument is inside the COMPONENT_REF (and is a reference instead of a pointer), and in the latter we don't even have an implicit object argument to inspect. FWIW I think which form we use depends on whether we know if the called function is a member of the current instantiation, e.g struct A { void f(); }; template struct B; template struct C : B { void g(); void h() { A::f(); // templated form has BASELINK callee, no object arg C::g(); // templated form has COMPONENT_REF callee } }; So it seemed best to punt on templated non-static memfn calls here for now and treat that as a separate enhancement. > > > { > > tree x = get_nth_callarg (t, 0); > > if (is_this_parameter (x)) > > @@ -9182,16 +9187,11 @@ potential_constant_expression_1 (tree t, bool > > want_rval, bool strict, bool now, > > i = 1; > > } > > } > > - else > > - { > > - if (!RECUR (fun, true)) > > - return false; > > - fun = get_first_fn (fun); > > - } > > + > > + fun = OVL_FIRST (fun); > > /* Skip initial arguments to base constructors. */ > > if (DECL_BASE_CONSTRUCTOR_P (fun)) > > i = num_artificial_parms_for (fun); > > - fun = DECL_ORIGIN (fun); > > } > > else if (fun) > > { > > diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept59.C > > b/gcc/testsuite/g++.dg/cpp0x/noexcept59.C > > index c752601ba09..1dc826d3111 100644 > > --- a/gcc/testsuite/g++.dg/cpp0x/noexcept59.C > > +++ b/gcc/testsuite/g++.dg/cpp0x/noexcept59.C > > @@ -3,7 +3,7 @@ > > template class A > > { > > - void e (); > > + constexpr bool e () { return true; }; > > bool f (int() noexcept(this->e())); // { dg-error "this" } > > bool g (int() noexcept(e())); // { dg-error "without object" } > > }; > > diff --git a/gcc/testsuite/g++.dg/template/non-dependent25.C > > b/gcc/testsuite/g++.dg/template/non-dependent25.C > > new file mode 100644 > > index 00000000000..a2f9801e11f > > --- /dev/null > > +++ b/gcc/testsuite/g++.dg/template/non-dependent25.C > > @@ -0,0 +1,14 @@ > > +// PR c++/109480 > > + > > +template > > +struct A { > > + void f() { > > + A a; > > + const bool b = a.g(); > > + } > > + > > +private: > > + bool g() const; > > +}; > > + > > +template struct A; > >