From patchwork Tue Jul 11 12:16:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 118441 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp432641vqm; Tue, 11 Jul 2023 05:17:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlF2sz9OFlp7YNpE5ehoE9bc1PI/gg9dfqxE6BEg41c79PcOvDvl2roHeA1pVjx5lNsipgcq X-Received: by 2002:a17:907:7f89:b0:98d:cacb:888f with SMTP id qk9-20020a1709077f8900b0098dcacb888fmr21512989ejc.49.1689077849140; Tue, 11 Jul 2023 05:17:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689077849; cv=none; d=google.com; s=arc-20160816; b=dcdC4KEjkwPz0r7yQGsZuUcjnwBp4k/wjelBkaEbiG2O/8/D9SFO9K9PoIWlKTw6f6 /Yq955lInHt6rEoMdu5trvk4QPcmmEE90ua3bWTGjBpzozdtLqtFT/imIEdblQpalLep LidDwa9+6PiDjOX4QchJ+YsZaTQlaTeZ4l61JPiowXQjYh3D4QPYblyTXXFEgS6FnZha kQSVSlkT5H4+tObCW7BmWwLIk3ikbvW04G11JoK38riIqD+jTM02c2WIz/Tw2hZ6WA9K SzfkCbIfVXS1Aq2KEfJcMB7+9oT/Jzw0egleFvSZl3c1l/vnbsivqZcPGUJR+fBG/ReR 2r6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=gc4gfhIddsguGTIiDCiO6EsyGVcvTK5Y0/dRaLvxgtQ=; fh=M5GO8duY/t9+1sJXvBSRQ4u8k9z8sLFDsSO1kARbltQ=; b=HRayxIuuxQ/ZnZGxLQttQPF0AZPFyZIiB1aoq2vWIhCyEfOvJtNfRfLYl5fLmanWjk dXEjafNJJJhMMPMAo/ygCs8pm35KbFCS1NopY1UZd3Ai3/rvt9WIUfjNO7ujV77r7uHQ 8HPsZ3bSiB7ADaxSm/RNfNhqUjmRaK5fVTplQpB/0Ax0o7wbHG/uLs5o/cg2NLdh1aDl C36ELrsTK2/ZLcB0a+mdC7Osg/09nqvVX51QVplbw1OlQ7mJ0k9io+Y0m8Jz3z7lYPb1 jZRinzLJXCUT2yBU2yYYtA0UzdaFUwM2bYjEWdTcVm57qwxNpeOoq1Z4AMv5kInGoG+J mBUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=lomUF6AP; 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=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id p6-20020a1709060dc600b0098e291bed8fsi1974029eji.451.2023.07.11.05.17.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 05:17:29 -0700 (PDT) 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=@gcc.gnu.org header.s=default header.b=lomUF6AP; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0E71C3858284 for ; Tue, 11 Jul 2023 12:17:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0E71C3858284 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689077848; bh=gc4gfhIddsguGTIiDCiO6EsyGVcvTK5Y0/dRaLvxgtQ=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=lomUF6APgytJTpovQ7GwGyVZfyXW+JUJSa6FkHr/ChYRUWiAStmO3q7Ei2Zy8z6Vm 2BBsTMS6tYZXUhlY+oLM4AYKO50VryffG5YguF5egAf4PRXb29u5A3xXzwmXHNC3fJ hFYGCang9GvQsV7wZiCXTm/st5mxNOMaMqowRyCw= 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 A915C3858D20 for ; Tue, 11 Jul 2023 12:16:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A915C3858D20 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-551-HzF-ZRTLM3yvPbeGx5B-VA-1; Tue, 11 Jul 2023 08:16:43 -0400 X-MC-Unique: HzF-ZRTLM3yvPbeGx5B-VA-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-403b4983a24so15076431cf.2 for ; Tue, 11 Jul 2023 05:16:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689077803; x=1691669803; 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=gc4gfhIddsguGTIiDCiO6EsyGVcvTK5Y0/dRaLvxgtQ=; b=eLg5H9dTtK+nIcxoZ3X87HvTemYhbKLZCfEfTS+y0Q6gmeCpcv1c82u2MhoCtjyY82 SY/OdEY17hVCxbJb9hzDESMMLjJQ+8dblbNGo/GvYBh+auwxK3YmafJMB3mGu4K2ASKp 1aaJ/01J51Uo6ZY0G6bWZd/vfsoAZ8AVkcZGRYymeOfCQeYrV2Us8Mzgh5LbReoCybHf xtgZ+VDBArH/SAOjEn9igZlLdH7C4EkGeFmDFrpvi+hbqYdEml4qrMhy7jDOpLtZ9wZ+ Nrq5TH9oAXg+vYsK4jWBkedVECW6MBZO1psejKb0Xg7Kbeu3u9OqVV31QKpHTDMxuGBv ZxCw== X-Gm-Message-State: ABy/qLZj2kmd4sE7ehrKng8EjVXgqOos7Kk4pP06qRl9aJHZ2gUe0o52 lMZLqhhhdig5xA1TBDEo6WrApmq+cvX+WLxrtwkdzVqgf090l5+LVj0tBmgRKPI3diBg5PXZMOq pvjHl4l5uH9qmS097pYSisrHvA2WoXPpokgtndT6G65uhrbARQOKUYhEt6KRWvDCdaVi5x5fRRb 8= X-Received: by 2002:ac8:7f09:0:b0:403:a039:e851 with SMTP id f9-20020ac87f09000000b00403a039e851mr10470335qtk.10.1689077802842; Tue, 11 Jul 2023 05:16:42 -0700 (PDT) X-Received: by 2002:ac8:7f09:0:b0:403:a039:e851 with SMTP id f9-20020ac87f09000000b00403a039e851mr10470310qtk.10.1689077802495; Tue, 11 Jul 2023 05:16:42 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id c6-20020ac87d86000000b0040378535dccsm1032513qtd.43.2023.07.11.05.16.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 05:16:42 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: coercing variable template from current inst [PR110580] Date: Tue, 11 Jul 2023 08:16:39 -0400 Message-ID: <20230711121639.2421168-1-ppalka@redhat.com> X-Mailer: git-send-email 2.41.0.327.gaa9166bcc0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.7 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771126495194043607 X-GMAIL-MSGID: 1771126495194043607 Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- Here during ahead of time coercion of the variable template-id v1, since we pass only the innermost arguments to coerce_template_parms (and outer arguments are still dependent at this point), substitution of the default template argument V=U prematurely lowers U from level 2 to level 1. Thus we incorrectly resolve v1 to v1 (effectively) instead of to v1. Coercion of a class/alias template-id on the other hand is always done using the full set of arguments relative to the most general template, so ahead of time coercion there does the right thing. I suppose we should do the same for variable template-ids. PR c++/110580 gcc/cp/ChangeLog: * pt.cc (lookup_template_variable): Pass all arguments to coerce_template_parms, and use the innermost parameters from the most general template. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/var-templ83.C: New test. --- gcc/cp/pt.cc | 4 +++- gcc/testsuite/g++.dg/cpp1y/var-templ83.C | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/var-templ83.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 076f788281e..fa15b75b9c5 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -10345,7 +10345,9 @@ lookup_template_variable (tree templ, tree arglist, tsubst_flags_t complain) if (flag_concepts && variable_concept_p (templ)) return build_concept_check (templ, arglist, tf_none); - tree parms = DECL_INNERMOST_TEMPLATE_PARMS (templ); + tree gen_templ = most_general_template (templ); + tree parms = DECL_INNERMOST_TEMPLATE_PARMS (gen_templ); + arglist = add_outermost_template_args (templ, arglist); arglist = coerce_template_parms (parms, arglist, templ, complain); if (arglist == error_mark_node) return error_mark_node; diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ83.C b/gcc/testsuite/g++.dg/cpp1y/var-templ83.C new file mode 100644 index 00000000000..f5268f258d7 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/var-templ83.C @@ -0,0 +1,16 @@ +// PR c++/110580 +// { dg-do compile { target c++14 } } + +template +struct A { + template + static constexpr bool v1 = __is_same(U, V); + + template + static constexpr bool v2 = !__is_same(U, V); + + static_assert(v1, ""); + static_assert(v2, ""); +}; + +template struct A;