------- Comment #6 from dodji at gcc dot gnu dot org 2009-04-21 14:40 ------- In this test case (the last one), the short description of the problem is that we fail at getting canonical types of template arguments when said arguments have composed types.
Let me give the longer description as well, so that I don't forget :) 1/ During the instantiation of E<int>, we try to instantiate the default argument A<T> of the template B with T=int*. 2/ At that point, lookup_template_class selects the A<X*> specialization that was first seen in struct D. There, X was a typedef of W, W being a template parameter of struct D. 3/In the context of 1/, we try to tsubst A<T> with T=int* - actually we try to tsubst the A<X*> specialization of A<T>. In tsubst, we then try to reuse the typedef declaration of T, if T is a typedef. A problem arises in 3/ because T is seen as a typedef of W (remember 2/) but W doesn't have any meaning in the context of 1/, hence the crash. Normally, template arguments are converted to their "canonical type variant" before the stubst-ing process starts. The canonical type variant of a typedef type variant is basically its qualified main type variant. E.g. in typedef const int Foo, the canonical type variant of Foo is const int. The function doing that conversion is canonical_type_variant. The root cause of the problem is that canonical_type_variant doesn't give us canonical variants of composed types. E.g. in typedef int Foo; The canoniacl type variant of Foo* should be int*. The current implementation of canonical_type_variant returns Foo* instead of int* in that case. So I am testing some patches that change the implementation of canonical_type_variant atm. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39754