Hi,

this patch adds handling of aliases within templates and tries to
resolve specialization for them.

ChangeLog

2014-12-18  Kai Tietz  <kti...@redhat.com>

    PR c++/61198
    * pt.c (retrieve_specialization): Handle using.

Tested on x86_64-w64-mingw32.  Ok for apply?

Regards,
Kai

ChangeLog testsuite

2014-12-18  Kai Tietz  <kti...@redhat.com>

    PR c++/61198
    * g++.dg/template/using29.C: New file.

// { dg-do compile }

template<int herp, typename derp_t>
struct broken
{
        template<typename target_t>
        using rebind = broken<herp, target_
};

template<typename derp_t>
struct broken<2, derp_t>
{
        template<typename target_t>
        using rebind = broken<2, target_t>;
};

int main(int argc, char **argv)
{
        broken<2, float>::rebind<double> u;

        return 0;
}

Index: pt.c
===================================================================
--- pt.c    (Revision 218832)
+++ pt.c    (Arbeitskopie)
@@ -1033,6 +1033,8 @@ optimize_specialization_lookup_p (tree tmpl)
 static tree
 retrieve_specialization (tree tmpl, tree args, hashval_t hash)
 {
+  tree tmpl_parms;
+
   if (tmpl == NULL_TREE)
     return NULL_TREE;

@@ -1044,10 +1046,20 @@ retrieve_specialization (tree tmpl, tree args, has

   /* There should be as many levels of arguments as there are
      levels of parameters.  */
-  gcc_assert (TMPL_ARGS_DEPTH (args)
-          == (TREE_CODE (tmpl) == TEMPLATE_DECL
-          ? TMPL_PARMS_DEPTH (DECL_TEMPLATE_PARMS (tmpl))
-          : template_class_depth (DECL_CONTEXT (tmpl))));
+  if (TREE_CODE (tmpl) == TEMPLATE_DECL)
+    {
+      tmpl_parms = DECL_TEMPLATE_PARMS (tmpl);
+      if (TMPL_ARGS_DEPTH (args) > TMPL_PARMS_DEPTH (tmpl_parms))
+    args = get_innermost_template_args
+        (args, TMPL_PARMS_DEPTH (tmpl_parms));
+      gcc_assert (TMPL_ARGS_DEPTH (args)
+          == TMPL_PARMS_DEPTH (tmpl_parms));
+    }
+  else
+    {
+      tmpl_parms = DECL_CONTEXT (tmpl);
+      gcc_assert (TMPL_ARGS_DEPTH (args) == template_class_depth (tmpl_parms));
+    }

   if (optimize_specialization_lookup_p (tmpl))
     {

Reply via email to