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: 198145 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2590064dyb; Wed, 7 Feb 2024 16:23:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IFhzHT7zU2ZVln8X65s8GvZBlVF1NJfb1bGnuwPBi+TqfORqnXA/LGqAuW8CIyJpK0WI++n X-Received: by 2002:a05:6902:2293:b0:db5:9004:cf5b with SMTP id dn19-20020a056902229300b00db59004cf5bmr6358637ybb.64.1707351797146; Wed, 07 Feb 2024 16:23:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707351797; cv=pass; d=google.com; s=arc-20160816; b=uXJOXxTPQaTlm2PYjQa2Kvny2QO9j6haR2sE7K7WgB2gU6fTjd6UV/yqw0mOPzC1z7 qMyPXRx2ERXTgRTuncSoLRG/+jayYM0G9XEqQt1pBkUu1itMFa8CmmbuxT96ZeO1Vr1p Q4r3y2L6WD4LoGrOMDztk4Gf0gQks3AtNxzd7SYfQKl5wcae1bZyF9NUbZlOO7gYXcgO tHSTaG/veUae+u9jCZu6ian5mm8mxcKsYIRsQmsrSfWRa8RWQ/TL8lvNHAAcT05Cv5qG ObKjmANhpz7f9xnXjVibM7yzKzEsuKWoxnE24QzjBnH5cVn4jAB5aVNfwQquoF5tsFJP 73dg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=Qu5ZPwpymF9d1GYGZGABm5tMVxT+C1Iss+dtvn2j9Is=; fh=leF2y24M35V9+vlTJ1j61mX8w6ncXQOlNMOVdRVMbwE=; b=gpxK0ReYlOdwW8PtP4f4RKig2eMn2w4KQN8xv5gb1AONAO0ceyMSjbqQEJEE/f09/Y Xgleh+mInX5ZbQpvsfSAG025kQV4kX5jaIpS9uZWhvJft60YGYYLHQd29cWngTEkiFQa vfYOSxdkpqwSgfU8sEbusLMxiUmdvKukIG+QLRYhvHklVqfgPpWlSlZw0nS+kk4AKeWv CzJ/fMlT6wCM+Tedm7edQ8Qb2Sr3VwRmR3UQc4uE5vTtpZHRu8QGejK8BB9DcJhuSx2F CDtY6XtHvf3j5qbOdc8BAiQU/1mIWrwHsZofm2yRaMffUCeDDPpJUMRiEku1hRu2QcCm 58lQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KQI2yMsO; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=2; AJvYcCW+nkFDWehidhcvn+GokpAOFICt4JhlDhieGHpTRhA7928eSPcdXIabYBFODxrXqnojp9IK6nTPdk9UmUP12byPCr7lnw== Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id k20-20020a05620a415400b007858ce6296bsi2499306qko.458.2024.02.07.16.23.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 16:23:17 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KQI2yMsO; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D007A38582B5 for ; Thu, 8 Feb 2024 00:23:16 +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-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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790288117674575818 X-GMAIL-MSGID: 1790288117674575818 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 "" }