Issue when Generating a Namespace-qualified TemplateSpecializationType

Hi All,

I’m trying to use the getCanonicalTemplateSpecializationType() function from the ASTContext API to generate a TemplateSpecializationType. The API works just fine, except in the case where the Template class is qualified, e.g. with a namespace. For example, if I process the following code:

namespace foo {
templatebar {};

and generate a template specialization with an “int” argument, the result is “bar” whereas it should be “foo::bar”. The reason, it seems, is an oddity in getCanonicalTemplateSpecializationType()'s implementation:

3529 // Look through qualified template names.
3530 if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3531 Template = TemplateName(QTN->getTemplateDecl());

So essentially the ASTContext is just throwing away the namespace qualifier (I’m giving it a QualifiedTemplateName as an argument). Is this a bug? Am I using the wrong api?

Thanks in advance,

Scott Constable

UPDATE: I still haven’t figured out the issue with the getCanonicalTemplateSpecializationType() API, but I have found another API which does the job just fine. What I do is the following:

void *InsertPos;
ClassTemplateSpecializationDecl *TD = MyClassTemplateDecl->findSpecialization(Args, InsertPos);
if (!TD) {
TD = ClassTemplateSpecializationDecl::Create(…);
MyClassTemplateDecl->AddSpecialization(TD, InsertPos);

QualType FullyQualTemplateType(TD->getTypeForDecl());

Indeed, the FullyQualTemplateType includes the namespace(s) in which MyClassTemplateDecl was declared. So in the example above, it is the type “foo::bar”.