aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2025-04-05 22:39:15 -0400
committerPatrick Palka <ppalka@redhat.com>2025-04-05 22:39:15 -0400
commit7a91400c142899ea0aeb8b62577496cf24c68156 (patch)
tree4b050c8ae9fca711abfd314eb31229ef097f4822
parent58c5055162b698dab6a493b1f90c18af1a34ac65 (diff)
downloadgcc-7a91400c142899ea0aeb8b62577496cf24c68156.zip
gcc-7a91400c142899ea0aeb8b62577496cf24c68156.tar.gz
gcc-7a91400c142899ea0aeb8b62577496cf24c68156.tar.bz2
c++: maybe_dependent_member_ref and typenames [PR118626]
Here during maybe_dependent_member_ref for accepted_type<_Up>, we correctly don't strip the typedef because it's a complex one (its defaulted template parameter isn't used in its definition) and so we recurse to consider its corresponding TYPE_DECL. We then incorrectly decide to not rewrite this use because of the TYPENAME_TYPE shortcut. But I don't think this shortcut should apply to a typedef TYPE_DECL. PR c++/118626 gcc/cp/ChangeLog: * pt.cc (maybe_dependent_member_ref): Restrict TYPENAME_TYPE shortcut to non-typedef TYPE_DECL. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/class-deduction-alias25a.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com>
-rw-r--r--gcc/cp/pt.cc3
-rw-r--r--gcc/testsuite/g++.dg/cpp2a/class-deduction-alias25a.C19
2 files changed, 21 insertions, 1 deletions
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 23e41a0..95b89f12 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -17789,7 +17789,8 @@ maybe_dependent_member_ref (tree t, tree args, tsubst_flags_t complain,
if (TREE_CODE (t) == TYPE_DECL)
{
- if (TREE_CODE (TREE_TYPE (t)) == TYPENAME_TYPE
+ if (!is_typedef_decl (t)
+ && TREE_CODE (TREE_TYPE (t)) == TYPENAME_TYPE
&& TYPE_NAME (TREE_TYPE (t)) == t)
/* The TYPE_DECL for a typename has DECL_CONTEXT of the typename
scope, but it doesn't need to be rewritten again. */
diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias25a.C b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias25a.C
new file mode 100644
index 0000000..74ef1e4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias25a.C
@@ -0,0 +1,19 @@
+// PR c++/118626
+// { dg-do compile { target c++20 } }
+
+template<long> struct _Nth_type { using type = _Nth_type; };
+
+template<class _Up>
+struct variant {
+ template<class _Tp> static constexpr long __accepted_index = 0;
+ template<long _Np> using __to_type = typename _Nth_type<_Np>::type;
+ template<class _Tp, int = sizeof(_Tp)> using __accepted_type = __to_type<__accepted_index<_Tp>>;
+ template<class = __accepted_type<_Up>> variant(_Up);
+};
+
+template<class _Tp>
+struct Node { Node(_Tp); };
+
+template<class R> using Tree = variant<Node<R>>;
+using type = decltype(Tree{Node{42}});
+using type = Tree<int>;