From patchwork Fri Jan 5 16:50:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1883075 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=YMmNFm3o; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T68cW6WRfz1xqk for ; Sat, 6 Jan 2024 03:51:38 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 14371385DC1D for ; Fri, 5 Jan 2024 16:51:36 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 6D5903857C53 for ; Fri, 5 Jan 2024 16:51:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6D5903857C53 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 6D5903857C53 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=1704473468; cv=none; b=ksig0NLkKo2zx7+gqI6OSpxbfyfXJ0vNvzYvIDOvjD3gHfQDWtVAoWkIIZru3CEC0+aHnTTbZm5WA4+URuWrX1wIcvuH470oziu++tzg7901x48YPQ+Gs8+sYrOxKbnLl+GNBp1oBwD73Dgp2USZQm0X0ga3kZzWWHYuIXR1IR0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704473468; c=relaxed/simple; bh=b1IXolj6OrXg2neZlojPKBetN4UlLzJma+UDXNuzNkY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=KRiCaqIwhLcQfdFtQFllcu55+3rvjEyeOTZFq684yxsCr+nUp3kTEuRzgDPCCwYQzYvy+WVNdCr9YSUUmvL/0TF39A0mOzPX8LV6KqXkzJBXsnMFaTNbs1hbmPxfNvda82JR3N7GVUKeAi+xXixQs1J3mybqlztWG6pfQKyNAEI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704473463; 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; bh=qofT7u8Swp0KZVUAOTC3+PlvQgWJnEQuDQ3WeiVOu+E=; b=YMmNFm3opQJ1OrA75lbQH0G2US3meu82/yi/FUVzjZdm8cGVolM9VNkG3o3lgN/mNdGOy2 ZJaZ/ELdpjtifXCTKXGHIJ1aslpFLMYsC2th/6baSaEUF8cFXn6Kk9HTN8QcbKwdKn2jJd 2HqViY5hDY1vskuFSkc//Anmg9MZIjc= Received: from mail-yb1-f199.google.com (mail-yb1-f199.google.com [209.85.219.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-39-b9B7YWQIPOGTUo8wo_Wncg-1; Fri, 05 Jan 2024 11:51:01 -0500 X-MC-Unique: b9B7YWQIPOGTUo8wo_Wncg-1 Received: by mail-yb1-f199.google.com with SMTP id 3f1490d57ef6-dbe868fdc33so2606000276.0 for ; Fri, 05 Jan 2024 08:51:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704473459; x=1705078259; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qofT7u8Swp0KZVUAOTC3+PlvQgWJnEQuDQ3WeiVOu+E=; b=UlQeDaQaiWxWbjfdiiuMyUlK9vcXm5F4JmElf69YLHqET5Iew8CLXqfxPCh/nZP1HA EVScymJ4qPePa0KP/WLGGz0pDK46zPTWGAjAB1VKPRarKGsu9KuIRL4z56dAXzK79lgC 5pkkUtaTaQisdpkLtl5Xd4CF3djhNu3SXeCSzJUvEjP29S92Nobibf7+vcMe1Asuj4Ju 7LfO5SRyCtSjH+0qoaFI0QsNs0U6iQgZKi5liuP0wnqMrkZQef8UPXB9rDqISHfxw8iz yY7hyjBWgkmNpiPTuRQdiWlaGpVHwDJ8wOs1wbY+W7aO80Qa7qGPuPOe1IoQKpueQ0DE V6Pw== X-Gm-Message-State: AOJu0Yw28lnrM8K5mYzIn2dl8Wyq+PfJgfm5+bD/NJSZY0MFllzjnM2k RYTw7fiz4gZy9i82KvN+0pWyZEI4cjJAOtp2d0oyssuStfDeVGAyrTtGSyl3kKr+PjKNdiu5Nbz 6a/9TWGd637m0bGB/Ac1xgWI0CCn0RnhGD9W7+9/GXa6pMJS7E6BSeyGKDlW6yCKYPn8WagkQJ6 yqa0LqEg0= X-Received: by 2002:a25:874b:0:b0:dbe:a07c:2687 with SMTP id e11-20020a25874b000000b00dbea07c2687mr1917036ybn.89.1704473459088; Fri, 05 Jan 2024 08:50:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IF14xU6RYB6xXEOl2F4cbf2xa+zIUmaIKLrOUt2XbvFy7gVpDQiui/yUDItAryI85hk8medOQ== X-Received: by 2002:a25:874b:0:b0:dbe:a07c:2687 with SMTP id e11-20020a25874b000000b00dbea07c2687mr1917025ybn.89.1704473458781; Fri, 05 Jan 2024 08:50:58 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id bt11-20020ac8690b000000b00423e8909bfesm866601qtb.6.2024.01.05.08.50.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 08:50:58 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: address of NTTP object as targ [PR113242] Date: Fri, 5 Jan 2024 11:50:56 -0500 Message-ID: <20240105165056.571235-1-ppalka@redhat.com> X-Mailer: git-send-email 2.43.0.254.ga26002b628 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.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_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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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. 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 (complain & tf_error) error ("the address of %qD is not a valid template argument", 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(); +}