[gcc r15-8671] c++: structural equality and partially inst typedef [PR119379]
Patrick Palka
ppalka@gcc.gnu.org
Sat Mar 22 14:16:13 GMT 2025
https://gcc.gnu.org/g:df5fa3a3d0d7f2413c832548c88f76dfe67802fd
commit r15-8671-gdf5fa3a3d0d7f2413c832548c88f76dfe67802fd
Author: Patrick Palka <ppalka@redhat.com>
Date: Sat Mar 22 10:15:52 2025 -0400
c++: structural equality and partially inst typedef [PR119379]
Complex alias templates (and their dependent specializations) always use
structural equality because we need to treat them as transparent in some
contexts but not others. Structural-ness however wasn't being preserved
during partial instantiation, which for the below testcase leads to the
checking ICE
same canonical type node for different types 'S<int>::P<U>' and 'pair<int, U>'
when comparing those two types with comparing_dependent_aliases set
(from alias_ctad_tweaks).
This patch fixes this by making us preserve structural-ness for
partially instantiated typedefs in general.
PR c++/119379
gcc/cp/ChangeLog:
* pt.cc (tsubst_decl) <case TYPE_DECL>: Preserve structural-ness
of a partially instantiated typedef.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/class-deduction-alias24.C: New test.
Reviewed-by: Jason Merrill <jason@redhat.com>
Diff:
---
gcc/cp/pt.cc | 5 +++++
gcc/testsuite/g++.dg/cpp2a/class-deduction-alias24.C | 16 ++++++++++++++++
2 files changed, 21 insertions(+)
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 538ff220d745..39c0ee610bbd 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -15920,6 +15920,11 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain,
if (TYPE_USER_ALIGN (TREE_TYPE (t)))
TREE_TYPE (r) = build_aligned_type (TREE_TYPE (r),
TYPE_ALIGN (TREE_TYPE (t)));
+
+ /* Preserve structural-ness of a partially instantiated typedef. */
+ if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (t))
+ && dependent_type_p (TREE_TYPE (r)))
+ SET_TYPE_STRUCTURAL_EQUALITY (TREE_TYPE (r));
}
layout_decl (r, 0);
diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias24.C b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias24.C
new file mode 100644
index 000000000000..cceddac0359f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias24.C
@@ -0,0 +1,16 @@
+// PR c++/119379
+// { dg-do compile { target c++20 } }
+
+template<class T, class U>
+struct pair {
+ pair(T, U);
+};
+
+template<class T>
+struct S {
+ template<class U> requires true
+ using P = pair<T, U>;
+};
+
+using type = decltype(S<int>::P(1, 2));
+using type = S<int>::P<int>;
More information about the Gcc-cvs
mailing list