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.129.124]) by sourceware.org (Postfix) with ESMTPS id E5816385842C for ; Mon, 3 Jan 2022 15:28:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E5816385842C Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-221-lKX5-QKIOmC6CwM0h76hyQ-1; Mon, 03 Jan 2022 10:28:27 -0500 X-MC-Unique: lKX5-QKIOmC6CwM0h76hyQ-1 Received: by mail-ed1-f69.google.com with SMTP id eg23-20020a056402289700b003f80a27ca2bso23076676edb.14 for ; Mon, 03 Jan 2022 07:28:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=Wlx1llpZj1MF/OSBX+pr8BIUyYoR/RupoRPWTwVA8gA=; b=pEZe/pw0901RUmBkGADP/8M9najkY1Cnl1vxBAR7hsnx+/6Guu5Jsaw2TXQulLOVG+ 5b5a57Xm4ctydUs4MkHR0X8c/O1JdbEKxqyZaiRKdwb0Et1yMWwm2rWnpQ/svriH6QZa Idp18M97vgtxbZ6gPvYoOdz2I0iFUWMGXFhXt8rs7SzPfmnIbT4/LMgag/rwnSCZmtHk I1WijJnyvtpTCpTMk7snx2UOH2iodHefPwdwd7mRmLQSQEe6rfKqyt2jtEqe4T8E2B2a hzE3j3d77OglF81K1DBCgSUvR9/EBLkVMMS9qyv+HRoABxV20U7AgO9HSxvOBm495PlQ U6Ng== X-Gm-Message-State: AOAM533yy/gsHtpvWEdds/aIQYSBLsrumEjV+1L0EARw3G3g53x/cRAt sxJ5B71GPr3Swzl9FEmlLQUGWYVQcbdckwpShWcWL4bRIx3oQ266YFGXpKC2oos4pWiMTDVD0q8 MC2Y9NWoh7YWwFPczsp4vedIhlIyPOfuKTg== X-Received: by 2002:a17:907:7f8f:: with SMTP id qk15mr38393616ejc.455.1641223705948; Mon, 03 Jan 2022 07:28:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJxumalGRgvbZdSk9ZpOiVZ9k8Oyb4iQGuVmL//+MMz2jgjc7IO+1thvrsa7u7dp3rDzuTEds+JK97WfOKn9++8= X-Received: by 2002:a17:907:7f8f:: with SMTP id qk15mr38393602ejc.455.1641223705604; Mon, 03 Jan 2022 07:28:25 -0800 (PST) MIME-Version: 1.0 References: <20211228150815.2034316-1-ppalka@redhat.com> In-Reply-To: <20211228150815.2034316-1-ppalka@redhat.com> From: Patrick Palka Date: Mon, 3 Jan 2022 10:28:14 -0500 Message-ID: Subject: Re: [PATCH] c++: dependent bases and 'this' availability [PR103831] To: GCC Patches X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-14.5 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_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Mon, 03 Jan 2022 15:28:35 -0000 On Tue, Dec 28, 2021 at 10:08 AM Patrick Palka wrote: > > Here during satisfaction of B's associated constraints we're failing to > reject the object-less call to the non-static member function A::size > ultimately because satisfaction is performed in the (access) context of > the class template B, which has a dependent bases, and so the > any_dependent_bases_p check within build_new_method_call causes us to > avoid rejecting the call. > > This patch fixes this by refining the any_dependent_bases_p check within > build_new_method_call: dependent bases can't make a difference for > resolving the implicit object parameter if we're in a conext where > 'this' is unavailable, so let's check current_class_ptr too. > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk and perhaps 11? The first testcase exhibits a regression > introduced by r12-1937. D'oh, never mind about the backport request since this is at worst a 12 regression. > > PR c++/103831 > > gcc/cp/ChangeLog: > > * call.c (build_new_method_call): Consider dependent bases only > if 'this' is available. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp2a/concepts-class3.C: New test. > * g++.dg/template/non-dependent18.C: New test. > --- > gcc/cp/call.c | 2 +- > gcc/testsuite/g++.dg/cpp2a/concepts-class3.C | 12 ++++++++++++ > .../g++.dg/template/non-dependent18.C | 19 +++++++++++++++++++ > 3 files changed, 32 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-class3.C > create mode 100644 gcc/testsuite/g++.dg/template/non-dependent18.C > > diff --git a/gcc/cp/call.c b/gcc/cp/call.c > index bee367f57d7..3da9e7a6284 100644 > --- a/gcc/cp/call.c > +++ b/gcc/cp/call.c > @@ -11098,7 +11098,7 @@ build_new_method_call (tree instance, tree fns, vec **args, > we know we really need it. */ > cand->first_arg = instance; > } > - else if (any_dependent_bases_p ()) > + else if (current_class_ptr && any_dependent_bases_p ()) > /* We can't tell until instantiation time whether we can use > *this as the implicit object argument. */; > else > diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-class3.C b/gcc/testsuite/g++.dg/cpp2a/concepts-class3.C > new file mode 100644 > index 00000000000..68b50b71278 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-class3.C > @@ -0,0 +1,12 @@ > +// PR c++/103831 > +// { dg-do compile { target c++20 } } > + > +struct A { > + constexpr int size() { return 42; } // non-static > +}; > + > +template > + requires (T::size() == 42) // { dg-error "without object" } > +struct B : T { }; > + > +template struct B; // { dg-error "constraint" } > diff --git a/gcc/testsuite/g++.dg/template/non-dependent18.C b/gcc/testsuite/g++.dg/template/non-dependent18.C > new file mode 100644 > index 00000000000..7fe623d497f > --- /dev/null > +++ b/gcc/testsuite/g++.dg/template/non-dependent18.C > @@ -0,0 +1,19 @@ > +// PR c++/103831 > +// { dg-do compile { target c++11 } } > + > +struct A { > + constexpr int size() { return 42; } // non-static > +}; > + > +template > +struct B : T { > + static_assert(A::size() == 42); // { dg-error "without object" } > + > + static int f() { > + static_assert(A::size() == 42, ""); // { dg-error "without object" } > + return A::size(); // { dg-error "without object" } > + } > + > + int n = A::size(); > + static const int m = A::size(); // { dg-error "without object" } > +}; > -- > 2.34.1.390.g2ae0a9cb82 >