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 EB2C738582B3 for ; Wed, 17 Jan 2024 16:35:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EB2C738582B3 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 EB2C738582B3 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705509343; cv=none; b=M8NqgIQKxqIimzzsjt1EN2cPZJLOqp7biDTBdgxasWTfmvWZEzqMzFUnvhSb9ZnX0YS+r0hfnq4fLsx1hJsyllw7dvV4kqUqoroZIA7ZNqZxenUZ396fIn1Q9gdulj9F5ehosC5mZAB8ND0UDOHaiZZNo6jOexUf977c4hAYVpg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705509343; c=relaxed/simple; bh=NRkNitgYdG+IXU2e6tmDxI3xBQGhktdZrZEVfb5j1pk=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=XpB6ks4P/2Z3nHrTYFJ2b2GOrNbKhRSNFRCjsImYWM8gjSVjKtk+iCeE4g8CHz3dSzT2kS/8omjx6L7w3mfBTSoBO1tTOXwqI3vEJdpfJThP0/PLvz9xfz8VBjag24k/3aUnRFwsNoGUPCk3RuN0QClt3nQDkl0J3Xs+mG+TV9E= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705509325; 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=yFxjv/C/oVV+UpqKPHbFDDGaNTFLpcW+0CWvPfndfPI=; b=KOmmW2HHL7JKvf/90f0x26LyANFlKYcL2wke8Ca6JcrAye7l/DyfdihDoybyDdDbM3PD2Y UK4MILSLphrof4BZtPxWKQgPGJtdxdtDKZcRK0AEex7E4BLDbe1SUuLDQAgUkzOUz6NIsc J1ZWTRjq/Hea8NQZsTkKbyAZghDVFkA= Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-511-6jGp4TUUOQ-3xB30o94QWQ-1; Wed, 17 Jan 2024 11:34:54 -0500 X-MC-Unique: 6jGp4TUUOQ-3xB30o94QWQ-1 Received: by mail-oi1-f198.google.com with SMTP id 5614622812f47-3bbacb61978so8588152b6e.3 for ; Wed, 17 Jan 2024 08:34:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705509289; x=1706114089; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yFxjv/C/oVV+UpqKPHbFDDGaNTFLpcW+0CWvPfndfPI=; b=otTCw11CCGPzWth98ezuIGaZzl5KuIKXI8ZmaiaCxUTp58G7JGCDy2GOL33I4JstmI 8Pg1wz5MB3CoGU0oN2Fms0tsBjJZgIbknJkkN8+RsBSa1//OXGGjKaNBSLkPTDPyug8+ F3YEIRPYvknGi9o5DUGHKgRObC37O3ftD7KwA5QWi3p7s4sC/Hl2LC7NFF7JSPtbXnTy 8fEoJkXQ1VLFm38GvimaSbpafyEKf+TpdRXRdOiGL0FSGkXWF73xtOPgZqEShniqpLWJ 0f1WR4KRhEgmji4KOsH68tZDOSYrCzFiu0w/7St5PvpYoBSbRXu9hPQ15rgIr6PwZ3CW RFDA== X-Gm-Message-State: AOJu0YykD2EDPvvN4cunJskTxU3i141vhRD8voPZ/38IfuTj75RRq/vN jqRHPu9j0XCiV8wQ6QhudlPBVGlVftC8OqLTyLhP598xG8dL8HVtveTaQ6JpOHDa5K1P1JPRjjB mb1yRRGYkvRt9efcqbqtPq4/M/w== X-Received: by 2002:a05:6808:13d4:b0:3bd:93bd:ea43 with SMTP id d20-20020a05680813d400b003bd93bdea43mr1304258oiw.36.1705509288885; Wed, 17 Jan 2024 08:34:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IGyMw5TTX55ytLfhkMcdOR/Q++x5ZWjDMtg1Gr3TqLenOtkIVeHq6rRGi5miEuHDbkO36q1Mw== X-Received: by 2002:a05:6808:13d4:b0:3bd:93bd:ea43 with SMTP id d20-20020a05680813d400b003bd93bdea43mr1304252oiw.36.1705509288619; Wed, 17 Jan 2024 08:34:48 -0800 (PST) Received: from [192.168.1.146] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id 3-20020ac85643000000b004282ce42c71sm5926025qtt.86.2024.01.17.08.34.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 17 Jan 2024 08:34:48 -0800 (PST) Message-ID: Date: Wed, 17 Jan 2024 11:34:47 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c++: address of NTTP object as targ [PR113242] To: Patrick Palka Cc: gcc-patches@gcc.gnu.org References: <20240105165056.571235-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,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 1/17/24 10:43, Patrick Palka wrote: > On Mon, 15 Jan 2024, Jason Merrill wrote: >> On 1/5/24 11:50, Patrick Palka wrote: >>> >>> invalid_tparm_referent_p was rejecting using the address of a class NTTP >>> object as a template argument, but this should be fine. >> >> Hmm, I suppose so; https://eel.is/c++draft/temp#param-8 saying "No two >> template parameter objects are template-argument-equivalent" suggests there >> can be only one. And clang/msvc allow it. >> >>> + else if (VAR_P (decl) && !DECL_NTTP_OBJECT_P (decl) >>> + && DECL_ARTIFICIAL (decl)) >> >> If now some artificial variables are OK and others are not, perhaps we should >> enumerate them either way and abort if it's one we haven't specifically >> considered. > > Sounds good, like so? Shall we backport this patch or the original > patch to the 13 branch? Hmm, looks like this patch changes the non-checking default behavior from reject to accept; maybe just add a checking_assert (tinfo || fname) to your original patch? OK with that change, for trunk and 13. > -- >8 -- > > Subject: [PATCH] c++: address of class NTTP object as targ [PR113242] > > invalid_tparm_referent_p was rejecting using the address of a class NTTP > object as a template argument, but this should be fine. > > This patch fixes this by refining the DECL_ARTIFICIAL rejection test to > check specifically for the kinds of artificial variables we want to > exclude. > > PR c++/113242 > > gcc/cp/ChangeLog: > > * pt.cc (invalid_tparm_referent_p) : Refine > DECL_ARTIFICIAL rejection test. Assert that C++20 template > parameter objects are the only artificial variables we accept. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp2a/nontype-class61.C: New test. > --- > gcc/cp/pt.cc | 13 +++++++--- > gcc/testsuite/g++.dg/cpp2a/nontype-class61.C | 27 ++++++++++++++++++++ > 2 files changed, 37 insertions(+), 3 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/cpp2a/nontype-class61.C > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index b6117231de1..885c297450e 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -7212,12 +7212,14 @@ invalid_tparm_referent_p (tree type, tree expr, tsubst_flags_t complain) > /* C++17: For a non-type template-parameter of reference or pointer > type, the value of the constant expression shall not refer to (or > for a pointer type, shall not be the address of): > - * a subobject (4.5), > + * a subobject (4.5), (relaxed in C++20) > * a temporary object (15.2), > - * a string literal (5.13.5), > + * a string literal (5.13.5), (we diagnose this early in > + convert_nontype_argument) > * the result of a typeid expression (8.2.8), or > * a predefined __func__ variable (11.4.1). */ > - else if (VAR_P (decl) && DECL_ARTIFICIAL (decl)) > + else if (VAR_P (decl) > + && (DECL_TINFO_P (decl) || DECL_FNAME_P (decl))) > { > if (complain & tf_error) > error ("the address of %qD is not a valid template argument", > @@ -7242,6 +7244,11 @@ invalid_tparm_referent_p (tree type, tree expr, tsubst_flags_t complain) > decl); > return true; > } > + > + /* The only artificial variables we do accept are C++20 > + template parameter objects. */ > + if (VAR_P (decl) && DECL_ARTIFICIAL (decl)) > + gcc_checking_assert (DECL_NTTP_OBJECT_P (decl)); > } > break; > > diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class61.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class61.C > new file mode 100644 > index 00000000000..90805a05ecf > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class61.C > @@ -0,0 +1,27 @@ > +// PR c++/113242 > +// { dg-do compile { target c++20 } } > + > +struct wrapper { > + int n; > +}; > + > +template > +void f1() { > + static_assert(X.n == 42); > +} > + > +template > +void f2() { > + static_assert(X->n == 42); > +} > + > +template > +void g() { > + f1(); > + f2<&X>(); > +} > + > +int main() { > + constexpr wrapper X = {42}; > + g(); > +}