From patchwork Thu Feb 8 00:15:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1896386 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=KQI2yMsO; 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 4TVd3s3szMz23hb for ; Thu, 8 Feb 2024 11:22:47 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2A63738582BD for ; Thu, 8 Feb 2024 00:22:45 +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.133.124]) by sourceware.org (Postfix) with ESMTPS id 4C87A3858C5F for ; Thu, 8 Feb 2024 00:21:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4C87A3858C5F 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 4C87A3858C5F 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=1707351712; cv=none; b=kWjwIyZ+bacRjb0edcCyO0yOHR7ITRPkL5xPVTGm2vi9W1eWzdHP+al7RyhCBpN16gHLhyhz4ByhX5x8JzDW8G5QLHdcLiiH7CueVMbm6xq95lFZdiMrtZ28ovZPYRRZEIGBHBsFKcqlSqJni9UjZeZguvmeO6C6BeNw0mDyct4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707351712; c=relaxed/simple; bh=DaKK9QPqC0M0flL42EHV2cmPy8UJgiGIiLXWC1WH7d0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=s5oe1PycvG3nL9lW78ADzLHpQRHpToHak+JEFkmNxg9s0pjYN8Ke6ujdn46BjKgwQ95KYpyVzbUPTkgOtLEx0zq5gMfa9KuyRTe1/aUiFNTv3X127AJnVVtwAbv3ZY4nIyNEYb2wvDVORv6RDO08MhHe5nwxtKWdcm0qK7roiHo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707351708; 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=Qu5ZPwpymF9d1GYGZGABm5tMVxT+C1Iss+dtvn2j9Is=; b=KQI2yMsOSCkj7UdPPrF3x0Tb4l0vJqBcB7fGaf06aUdSMLiusC0s8O971iFwHotUESRLwA CtGz6cq0vgA9hKOsFz5uEVr7/ROrZ96Nm7I399uiV/dtnkoCoCXCRHP3QTXL6HwWxepbu+ PwE4SKTodLha39oQrflRWAjBSrjj75Q= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-596-eFsavqL4PMCGhqoBIkb2Eg-1; Wed, 07 Feb 2024 19:21:44 -0500 X-MC-Unique: eFsavqL4PMCGhqoBIkb2Eg-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-68c4e69e121so18830116d6.2 for ; Wed, 07 Feb 2024 16:21:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707351704; x=1707956504; 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=Qu5ZPwpymF9d1GYGZGABm5tMVxT+C1Iss+dtvn2j9Is=; b=wouW2E1Oy6Q2WU+s/tt8f7/Od5mPKaf/GnTYjqnWSKOCHQ/3ZqGz/ULSdPXTW3GyRs WTHz+6IBth9sQfiZP8ro13tJvzIAq2Z+H7C0ySNaT7HgcwxPuVN2oka3kqhSQWdkKvJe 1BHoUbhtwBD80kl2ada/tZDGXINRYHIXPrdbgj6WU7eSwzrXV9ZKTw6QWBILcWxnrnCB N1dn7ZYn/w3OrIR4c656skR61W5qRwqpcAsJAs6KB78cg0THMPkT2vMwE0Fb/FbwYb8P N9HN5vATbQ329WXzgaDhM4puBr6lrOgliPVJX/7KTEjXwPd8ZIr9FkIuiyKI8cNvNbGh b4Iw== X-Gm-Message-State: AOJu0Yyi/Q/xP0ShqSvElrp7zlVQfRaVCsu1KwvT8G/6nugwpJ0HbxzL pBEfgXxS/rO81RcZ3aSXZFB5TteV3Zl47kKUrnuX0JksAyTm22p4ogPB3p3xdqvrH6VfrwwqDZV rqbLqiLz2Cx4k4oRGJzuPjSbXFnm0yZFyZQMv8eqAzVe2stV1Q4UhsWEvjZLfNc/1uetyVIEx2N EOzk6Y5TD1aPMUs9flNkc97PZm5O3TVaetG0k= X-Received: by 2002:a05:6214:b62:b0:685:61c2:cf7c with SMTP id ey2-20020a0562140b6200b0068561c2cf7cmr8821705qvb.45.1707351703831; Wed, 07 Feb 2024 16:21:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IEH87pGdOKlG6UgsaP7ZzRvugJBPKo4tqi/MDk5iIH1w4DTIg0NNCvjEEFBgZSAuNkU3sIpiQ== X-Received: by 2002:a05:6214:b62:b0:685:61c2:cf7c with SMTP id ey2-20020a0562140b6200b0068561c2cf7cmr8821684qvb.45.1707351703451; Wed, 07 Feb 2024 16:21:43 -0800 (PST) Received: from jason-thinkpadp1gen4i.rmtusma.csb (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 wv17-20020a05620a5a1100b007859b93e651sm978075qkn.28.2024.02.07.16.21.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 16:21:42 -0800 (PST) From: Jason Merrill To: gcc-patches@gcc.gnu.org Cc: Marek Polacek Subject: [pushed] c++: class nttp ICE Date: Wed, 7 Feb 2024 19:15:00 -0500 Message-ID: <20240208002141.238303-1-jason@redhat.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.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_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_WEB, 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 Tested x86_64-pc-linux-gnu, applying to trunk. Marek, I'll leave it to you to judge if there is anything else needed for P2308. -- 8< -- The new testcase from P2308 crashed trying to expand 'this' without an object to refer to, because we stripped the TARGET_EXPR in create_template_parm_object. So let's leave it on for giving an error. gcc/cp/ChangeLog: * pt.cc (create_template_parm_object): Pass TARGET_EXPR to cxx_constant_value. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/nontype-class64.C: New test. --- gcc/cp/pt.cc | 5 +++-- gcc/testsuite/g++.dg/cpp2a/nontype-class64.C | 23 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/nontype-class64.C base-commit: c5d34912ad576be1ef19be92f7eabde54b9089eb diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 903a4a1c363..55c23b642bc 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -7308,14 +7308,15 @@ invalid_tparm_referent_p (tree type, tree expr, tsubst_flags_t complain) static tree create_template_parm_object (tree expr, tsubst_flags_t complain) { + tree orig = expr; if (TREE_CODE (expr) == TARGET_EXPR) expr = TARGET_EXPR_INITIAL (expr); if (!TREE_CONSTANT (expr)) { if ((complain & tf_error) - && require_rvalue_constant_expression (expr)) - cxx_constant_value (expr); + && require_rvalue_constant_expression (orig)) + cxx_constant_value (orig); return error_mark_node; } if (invalid_tparm_referent_p (TREE_TYPE (expr), expr, complain)) diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class64.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class64.C new file mode 100644 index 00000000000..eb6489238f0 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class64.C @@ -0,0 +1,23 @@ +// Testcase from P2308R1 +// { dg-do compile { target c++20 } } + +template struct B { /* ... */ }; +B<5> b1; // OK, template parameter type is int +B<'a'> b2; // OK, template parameter type is char +B<2.5> b3; // OK, template parameter type is double +B b4; // { dg-error "void" } + +template struct C { /* ... */ }; +C<{ 42 }> c1; // OK + +struct J1 { + J1 *self=this; +}; +B j1; // { dg-error "not a constant expression" } + +struct J2 { + J2 *self=this; + constexpr J2() {} + constexpr J2(const J2&) {} +}; +B j2; // { dg-error "" }