Linkage of NonTypeTemplateParm and TemplateTemplateParm

Hello,

I’m trying to list externally visible “symbols” of a header file with an AST Visitor that queries the NamedDecl::getFormalLinkage() of each NamedDecl that it encounters.

A simplified version look a little bit like this:

class PrintFormalLinkage : public clang::ASTConsumer,
                           public RecursiveASTVisitor<PrintFormalLinkage> {
public:
  void HandleTranslationUnit(clang::ASTContext &Context) override {
    TraverseDecl(Context.getTranslationUnitDecl());
  }

  bool VisitNamedDecl(NamedDecl *D) {
    llvm::outs() << D->getQualifiedNameAsString() << ":\t"
                 << D->getDeclKindName() << "\n\t"
                 << LinkageToString(D->getFormalLinkage()) << "\n\n";
    return true;
  }
};

It’s working pretty well but I encountered two cases where the returned linkage is not the one I would have expected:

template<typename T, bool B, template <typename T2> typename TT>
void foo();

will report ExternalLinakge for both B and TT instead of NoLinkage like in the case of T.

foo:    FunctionTemplate
        ExternalLinkage

T:      TemplateTypeParm
        NoLinkage

B:      NonTypeTemplateParm
        ExternalLinkage

TT:     TemplateTemplateParm
        ExternalLinkage

T2:     TemplateTypeParm
        NoLinkage

foo:    Function
        ExternalLinkage

So I don’t know if clang is reporting something weird or if there is just no meaning in calling NamedDecl::getFormalLinkage() for a template parameter or if it’s something that the c++ standard enforce.
Is anyone know something about it ?

Cheers,
fx