]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: alias template and typename [PR103057]
authorJason Merrill <jason@redhat.com>
Tue, 25 Jan 2022 20:12:16 +0000 (15:12 -0500)
committerJason Merrill <jason@redhat.com>
Wed, 26 Jan 2022 04:22:57 +0000 (23:22 -0500)
Usually we handle DR1558 substitution near the top of tsubst, but in this
case while substituting TYPENAME_TYPE we were passing an alias
specialization to tsubst_aggr_type, which ignored its aliasness.

PR c++/103057

gcc/cp/ChangeLog:

* pt.cc (tsubst_aggr_type): Call tsubst for alias template
specialization.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/alias-decl-void1.C: New test.

gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp0x/alias-decl-void1.C [new file with mode: 0644]

index 8f50b9c4d3c2e2e18b148f091d6a89cfb5c63e9c..6fbda676527a4dd3af09de9326a6a1f74dcb7a95 100644 (file)
@@ -13585,6 +13585,14 @@ tsubst_aggr_type (tree t,
   if (t == NULL_TREE)
     return NULL_TREE;
 
+  /* If T is an alias template specialization, we want to substitute that
+     rather than strip it, especially if it's dependent_alias_template_spec_p.
+     It should be OK not to handle entering_scope in this case, since
+     DECL_CONTEXT will never be an alias template specialization.  We only get
+     here with an alias when tsubst calls us for TYPENAME_TYPE.  */
+  if (alias_template_specialization_p (t, nt_transparent))
+    return tsubst (t, args, complain, in_decl);
+
   switch (TREE_CODE (t))
     {
     case RECORD_TYPE:
diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-void1.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-void1.C
new file mode 100644 (file)
index 0000000..accc1a4
--- /dev/null
@@ -0,0 +1,18 @@
+// PR c++/103057
+// { dg-do compile { target c++11 } }
+
+template <class T> struct A { };
+template <class T> struct B { using type = A<T>; };
+template <class T> struct C {
+  using type = typename T::foo;        // { dg-error "int" }
+};
+template <class T> using L = B<void>;
+
+template <class T>
+typename L<typename C<T>::type>::type
+f(T) { };
+
+int main()
+{
+  f(42);                       // { dg-error "no match" }
+}