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 B40413858D33 for ; Wed, 17 Jan 2024 15:43:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B40413858D33 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 B40413858D33 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=1705506207; cv=none; b=P06BrH+ojHfk095TKWDepFcL3eHknVMYTHQY4S+Gmnk88/jH/Hq2pqhRtfvydW2IU4PtGCUf8DcTjBK/n/Q+RmNiGYaWA/ykNl+YMXKnO1dl9py43+n2kzh0a6YwCH8yQFXB00ucmtmNDNrIi8KdoWDaaL1jZlFNvodJfgFL7cA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705506207; c=relaxed/simple; bh=+amwaqhSV2xfIIeAQkVm3NXvHskNPmiXSvjhNTUDjJI=; h=DKIM-Signature:From:Date:To:Subject:Message-ID:MIME-Version; b=TGXsh4X8/OW0P88xdHYC3pfLfS0x4pq3jrSjD/iiQChN2wql+HQDHkY8PUjF3msLhQiChIYzGCUzlkpnKFEkCbGQniL5hGeJoNu3FxzK/QYLxNKZXk7Sa2+a4CZrQSXmHyGpFjYDsMy90ClELDto2MM035fgV1Do2B+cZuLV/jo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705506205; 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=rr65XsK2bkShwQi83bBIUd9NXTcd2qgRvvWexDY1EXs=; b=iSZl/AQrqCqQRUGpuWenEIZCPRzk0oiXSXi1RJPlZJdNlEKfGH3c6v1UxGUdqT+kIJCwzO D//dzm9RX1MQUXWFX6/SUIUPAuM+k4YiW/sxikc4z60NHtotfBrq+U/NZmQ7HOcUjMEtsB CzhRjzDRkqK0Hapea2DpkVMjz8yHGo8= 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-624-3i66HySFOp6rDprGJMLnmg-1; Wed, 17 Jan 2024 10:43:21 -0500 X-MC-Unique: 3i66HySFOp6rDprGJMLnmg-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-429a30f4997so116115001cf.3 for ; Wed, 17 Jan 2024 07:43:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705506200; x=1706111000; 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=rr65XsK2bkShwQi83bBIUd9NXTcd2qgRvvWexDY1EXs=; b=pYlFUT1Kri48mjPE+fJOSEbQHqS4oxV5BOibzh2+QKqC9CpHlnrCcmHwHb6CicoeV1 CZNFzlO5gRu3jdF+nRSGoZQb6G67/OoXdW3UeEpyrTuW4DwTiVBBA9feLw21//dkt5Xb mqwnCmvzm9zfietJ1BYE0nrn+K/Urin0oLPcZIIP3LpvQ+siS/ltg7+ddt93XdSq4MI9 6W/v8QGPNHJq0Gw/OX/DvuGL/M9Qcdgb9wVj3EezhAPGwbpUpPwLhoF9h1le2p1uw3U5 cbM4iqxiRuf4uoa6BHnOntcK4XA/pHEWenZcF8u5VAAHCNJQM3hnrqKAxqY4EXIorGjh v2eA== X-Gm-Message-State: AOJu0YyPvv0to5SaL5Js+wa6PQOm6O1rNWqIuRTCyq6m7BUnUX+z/TXT sgqT7vd9UshTbIapprLyqjYzwGlk2+NE6iTm0iwmQ7EbKl6LnQ9laXXoGG3rDI/Nw5gWUbLE5Aa oe39yOdfn7errV+sNrCJYSmms0F3WhxOUfA== X-Received: by 2002:ac8:4e84:0:b0:42a:11ac:7816 with SMTP id 4-20020ac84e84000000b0042a11ac7816mr981562qtp.17.1705506200432; Wed, 17 Jan 2024 07:43:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IGBMOqel2Mc5uKQOxF0ZQPOvuhyVW1HbiRSQjOAb8u+1FA7/Gwo8ATG79sWTrR2cVw2N3XN1g== X-Received: by 2002:ac8:4e84:0:b0:42a:11ac:7816 with SMTP id 4-20020ac84e84000000b0042a11ac7816mr981551qtp.17.1705506200046; Wed, 17 Jan 2024 07:43:20 -0800 (PST) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id ci21-20020a05622a261500b004283595941csm5899451qtb.24.2024.01.17.07.43.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 07:43:19 -0800 (PST) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Wed, 17 Jan 2024 10:43:18 -0500 (EST) To: Jason Merrill cc: Patrick Palka , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] c++: address of NTTP object as targ [PR113242] In-Reply-To: Message-ID: References: <20240105165056.571235-1-ppalka@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=-14.7 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_H3,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 Mon, 15 Jan 2024, Jason Merrill wrote: > On 1/5/24 11:50, Patrick Palka wrote: > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK > > for trunk and perhaps 13? > > > > -- >8 -- > > > > 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. > > > PR c++/113242 > > > > gcc/cp/ChangeLog: > > > > * pt.cc (invalid_tparm_referent_p) : Suppress > > DECL_ARTIFICIAL rejection test for class NTTP objects. > > > > gcc/testsuite/ChangeLog: > > > > * g++.dg/cpp2a/nontype-class61.C: New test. > > --- > > gcc/cp/pt.cc | 3 ++- > > gcc/testsuite/g++.dg/cpp2a/nontype-class61.C | 27 ++++++++++++++++++++ > > 2 files changed, 29 insertions(+), 1 deletion(-) > > create mode 100644 gcc/testsuite/g++.dg/cpp2a/nontype-class61.C > > > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > > index 154ac76cb65..8c7d178328d 100644 > > --- a/gcc/cp/pt.cc > > +++ b/gcc/cp/pt.cc > > @@ -7219,7 +7219,8 @@ invalid_tparm_referent_p (tree type, tree expr, > > tsubst_flags_t complain) > > * a string literal (5.13.5), > > * 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_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? -- >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(); +} -- 2.43.0.367.g186b115d30