]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Fix member alias template in C++17 and up. [PR96805]
authorJason Merrill <jason@redhat.com>
Thu, 8 Oct 2020 19:43:26 +0000 (15:43 -0400)
committerJason Merrill <jason@redhat.com>
Tue, 24 Nov 2020 17:51:25 +0000 (12:51 -0500)
Here we're trying to push into a<T>::c<N> in order to instantiate t<N>, but
were building a TYPENAME_TYPE for it because a<T> isn't open yet.  Don't
do that when we know we're trying to enter the scope.

gcc/cp/ChangeLog:

PR c++/96805
PR c++/96199
* pt.c (tsubst_aggr_type): Don't build a TYPENAME_TYPE when
entering_scope.
(tsubst_template_decl): Use tsubst_aggr_type.

gcc/testsuite/ChangeLog:

PR c++/96805
* g++.dg/cpp0x/alias-decl-pr96805.C: New test.

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

index 2a0f2527d8c59b272e9e5104335a410b8200aa90..de7cbaa1d65bc3bc41137798c03f6abc11e271cc 100644 (file)
@@ -13397,7 +13397,8 @@ tsubst_aggr_type (tree t,
                                         complain, in_decl);
          if (argvec == error_mark_node)
            r = error_mark_node;
-         else if (cxx_dialect >= cxx2a && dependent_scope_p (context))
+         else if (!entering_scope
+                  && cxx_dialect >= cxx2a && dependent_scope_p (context))
            {
              /* See maybe_dependent_member_ref.  */
              tree name = TYPE_IDENTIFIER (t);
@@ -14082,7 +14083,11 @@ tsubst_template_decl (tree t, tree args, tsubst_flags_t complain,
     {
       tree new_type;
       ++processing_template_decl;
-      new_type = tsubst (TREE_TYPE (t), args, complain, in_decl);
+      if (CLASS_TYPE_P (TREE_TYPE (t)))
+       new_type = tsubst_aggr_type (TREE_TYPE (t), args, complain,
+                                    in_decl, /*entering*/1);
+      else
+       new_type = tsubst (TREE_TYPE (t), args, complain, in_decl);
       --processing_template_decl;
       if (new_type == error_mark_node)
        return error_mark_node;
diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-pr96805.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-pr96805.C
new file mode 100644 (file)
index 0000000..c784f27
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/96805
+// { dg-do compile { target c++11 } }
+
+template <typename T> class a {
+  template <int N> struct c {
+    template <bool B> using t = int;
+    t<N> m;
+  };
+};