The lexical DeclContext of class template instantiations.


I would like to hear some informed opinions on the following, which seems to be an AST quality issue.

When parsing the following file:

$ cat
template <typename T>
struct Outer {
   template <typename U> static void InnerFun(T, U) {}
   template <typename U> struct InnerRecord { T* t; U u; };

struct S {
   static void bar() { Outer<S>::InnerFun<int>(S(), 5); }
   Outer<S>::InnerRecord<int> is;

the AST generated by clang contains implicit instantiations for

It happens that the function Outer<S>::InnerFun<int> has the same semantic and lexical DeclContext, namely struct Outer<S>.

In contrast, the record Outer<S>::InnerRecord<int> has Outer<S> as the semantic DeclContext, but it has struct S as the lexical one.

This looks quite odd ... for instance, one of the consequences is that, when querying Outer<S>::InnerRecord<int> with method
    bool isOutOfLine()
we would be obtaining a positive answer.

Afaict, the problem is caused by method

     TemplateName Name,
     SourceLocation TemplateLoc,
     TemplateArgumentListInfo &TemplateArgs);

around line 2077 of SemaTemplate.cpp, where it does

   ClassTemplate->AddSpecialization(Decl, InsertPos);

Am I guessing correctly if I say that it should be something like

   ClassTemplate->AddSpecialization(Decl, InsertPos);
   if (ClassTemplate->isOutOfLine())






I no one has objections, we would like to apply this patch
(passes all clang tests).


class_templ_inst_lexdc.patch (646 Bytes)

Ping^4 ...

Sorry, I figured Doug would be looking at this, but now he's on vacation. This is fine.