From patchwork Wed Jan 31 17:12:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1893607 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=Bi/AlSlr; 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 4TQ7sk4Spmz1yQ0 for ; Thu, 1 Feb 2024 04:13:30 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9A9433858008 for ; Wed, 31 Jan 2024 17:13:27 +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 2F9F538582B7 for ; Wed, 31 Jan 2024 17:13:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2F9F538582B7 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 2F9F538582B7 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=1706721189; cv=none; b=HYw8kh5pnHoWgS2nhLbmIHDMAzItilyvUS/jjiYYXk4zT4HU17n848wbUIi6jL3Re63cOAe675Ckv3tJR/rcush/u4dUq5J3hghjH7gJ6TAwWjt431Ye61+CQBJ6pgirh53FZSu1HAu008kmJpEKqkXJNdudjpk4oUS+PGKrCuo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706721189; c=relaxed/simple; bh=xoo5dE4IjbPuxfboiqy67BXE9QO4iK21AWhqGX22AEE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=AX9B9mvWu9sxlBKolGEY3QkKG7dUVSA8nl8jEm0UKjYPkDi4dMU4CHSWUKpUmpa6VCnErMDBHSWsoF11jhAYElFkf6a5uo2T7axfXhx9POzh3bZknpjc75VIZQtcQl+YDQiyAnY6JUCQx12RAItJsIlp2ttTGftoXp3GhZT/CcQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706721186; 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=onMHSfBTU+zYzDzAuwDumvSLcXdIn3CddXEZOMLmL9o=; b=Bi/AlSlrLHFgmqbnkYAvMpFU2U5p5Sb3U25rrFRkz0u9PWgAXHieqeLlfUzWuAInMxCfrs WOel6IbwtYnaxfEARQhfatxbA3xngr/g0eb/1Sx6cN23cHK/DurDbmWlIfADIsU6JkDEpu CzmUXVAb9ejPQsokO6UmB8Wbcv5qZvg= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-80-LHD9J8XrOHSFxk8e9fXQuQ-1; Wed, 31 Jan 2024 12:13:00 -0500 X-MC-Unique: LHD9J8XrOHSFxk8e9fXQuQ-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-7833761135dso6742385a.0 for ; Wed, 31 Jan 2024 09:13:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706721178; x=1707325978; 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=onMHSfBTU+zYzDzAuwDumvSLcXdIn3CddXEZOMLmL9o=; b=xTMkrYiPNaWszo8jIOj35FfgTCh+HzH6i8WvnTYPwAEsqw3G5qgHxE7fm3i0F+kTqu 4xbTpKW51+dCMFCUMRukoZdAiIj5QBkhA57koPd8GNt7U+Kt2xSv1INY6BL8VcV04Fz5 vfz1TkILxFvLLpbqFky57EXEl/QPD6SSPSkRqeWgiNtQCdumXrM+YBjwYG/QWge0kt0M s6Fm45+R0EGFNYC0491sxHG9EpqciXAg72as+A3a9G4ks3W45DCm0Zu3kMj3FL5q/3kO 33pEiZx7x+5WH7IsRQHcbSjqBaaB20kwDljUEqgvTqKCdxNeS81dm9HPfAebIQhGMIIK hYsg== X-Gm-Message-State: AOJu0YzgHLUKq/5aHGz8yncUeNVO2qgZXesGWhthmTJgqMiElPM7DmOW xRxb/g20+H4da29/gqVcSO/j5rQz0R5LhDQWB+uQBUJx0W3W79oWLLeEy8qNV4Bnvoo8w2xgDXZ 5d6xyTPlIS1mfh9JZY3g3h/UJFf0Obsu207iX8Aok2lOImIuLUU6tSP3EGfLs1uQRmqajKnf8ko HBdKYAUgQcKOzzHPB++kBASxjzclq0QhGLuXHM X-Received: by 2002:a05:620a:559c:b0:784:aae1:f52 with SMTP id vq28-20020a05620a559c00b00784aae10f52mr30450qkn.7.1706721178313; Wed, 31 Jan 2024 09:12:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IF9WdsJz7siYGdJJ1rtstMLrbQm7ZWOxeLWW+i7Gkw6RHb5/4L0mc/WM8WVyVw/CVzeIttb8Q== X-Received: by 2002:a05:620a:559c:b0:784:aae1:f52 with SMTP id vq28-20020a05620a559c00b00784aae10f52mr30421qkn.7.1706721177911; Wed, 31 Jan 2024 09:12:57 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXpMny8rBn3L1kewVs+mhvc/nGRb7UZLLK8NUaLzupkNPvKg/UujjIxT4FMqPi0l5PPFTuRAMNKDTaybRNuBlkU7g== Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id da35-20020a05620a362300b007853b0cd29csm585517qkb.1.2024.01.31.09.12.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 09:12:57 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: ttp CTAD equivalence [PR112737] Date: Wed, 31 Jan 2024 12:12:45 -0500 Message-ID: <20240131171245.1102131-1-ppalka@redhat.com> X-Mailer: git-send-email 2.43.0.493.gbc7ee2e5e1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.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 Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- Here during declaration matching we undesirably consider the two TT{42} CTAD expressions to be non-equivalent ultimately because for CTAD placeholder equivalence we compare the TEMPLATE_DECLs (which uses pointer identity) and here the corresponding TEMPLATE_DECLs for TT are different since they're from different scopes. On the other hand, the corresponding TEMPLATE_TEMPLATE_PARMs are deemed equivalent (since they have the same position and template parameters). This turns out to be the root cause of some of the xtreme-header modules regressions. We don't have this ttp equivalence issue in other contexts because either the TEMPLATE_TEMPLATE_PARM is used instead of the TEMPLATE_DECL already (e.g. when a ttp is used as a targ), or the equivalence logic is relaxed (e.g. for bound ttps), it seems. So this patch relaxes ttp CTAD placeholder equivalence accordingly, by comparing the TEMPLATE_TEMPLATE_PARM instead of the TEMPLATE_DECL. The ctp_hasher doesn't need to be adjusted since it currently doesn't include CLASS_PLACEHOLDER_TEMPLATE in the hash anyway. PR c++/112737 gcc/cp/ChangeLog: * typeck.cc (structural_comptypes) : If CLASS_PLACEHOLDER_TEMPLATE is a ttp, compare its TEMPLATE_TEMPLATE_PARM instead of its TEMPLATE_DECL. gcc/testsuite/ChangeLog: * g++.dg/template/ttp42: New test. --- gcc/cp/typeck.cc | 20 +++++++++++++++++--- gcc/testsuite/g++.dg/template/ttp42.C | 14 ++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/ttp42.C diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc index a15eda3f5f8..be82877e35c 100644 --- a/gcc/cp/typeck.cc +++ b/gcc/cp/typeck.cc @@ -1573,9 +1573,23 @@ structural_comptypes (tree t1, tree t2, int strict) return false; /* If T1 and T2 don't represent the same class template deduction, they aren't equal. */ - if (CLASS_PLACEHOLDER_TEMPLATE (t1) - != CLASS_PLACEHOLDER_TEMPLATE (t2)) - return false; + if (CLASS_PLACEHOLDER_TEMPLATE (t1) || CLASS_PLACEHOLDER_TEMPLATE (t2)) + { + tree tmpl1 = CLASS_PLACEHOLDER_TEMPLATE (t1); + tree tmpl2 = CLASS_PLACEHOLDER_TEMPLATE (t2); + if (!tmpl1 || !tmpl2) + return false; + if (DECL_TEMPLATE_TEMPLATE_PARM_P (tmpl1) + != DECL_TEMPLATE_TEMPLATE_PARM_P (tmpl2)) + return false; + if (DECL_TEMPLATE_TEMPLATE_PARM_P (tmpl1) + /* Treat two CTAD placeholders that use equivalent ttps + from different scopes as equivalent by comparing their + TEMPLATE_TEMPLATE_PARMs instead of their TEMPLATE_DECLs. */ + ? !same_type_p (TREE_TYPE (tmpl1), TREE_TYPE (tmpl2)) + : tmpl1 != tmpl2) + return false; + } /* Constrained 'auto's are distinct from parms that don't have the same constraints. */ if (!equivalent_placeholder_constraints (t1, t2)) diff --git a/gcc/testsuite/g++.dg/template/ttp42.C b/gcc/testsuite/g++.dg/template/ttp42.C new file mode 100644 index 00000000000..da08e857fc5 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/ttp42.C @@ -0,0 +1,14 @@ +// PR c++/112737 +// { dg-do compile { target c++17 } } + +template class TT> +decltype(TT{42}) f(); // #1 + +template class TT> +decltype(TT{42}) f(); // redeclaration of #1 + +template struct A { A(T); }; + +int main() { + f(); +}