Question about ASTMatcher `typeAliasTemplateDecl` for gsl::owner

Hello everybody,

iam working on a clang-tidy-check to handle gsl::owner, at least i try to.
What iam doing right now, is trying to get the Matchers done and here is
what I have as testcode for experimentation.

namespace gsl {
template<typename T> using owner = T;
}

template<typename T> class vector {};
template<typename T> using heap_array = vector<T>;

using file = int;

void f() {
    gsl::owner<int*> owner = new int(10);

    int i = 0;
    int* no_owner = &i;
    int** no_owner_at_all = &no_owner;

    file n = 15;

    heap_array<int> array;
}

// match varDecl(hasType(hasDeclaration(typeAliasDecl()))) # works for file
// match varDecl(hasType(hasDeclaration(typeAliasTemplateDecl()))) #
works for file
// match varDecl(hasType(hasDeclaration(typedefNameDecl()))) # works
for file
// match
varDecl(hasType(hasDeclaration(typedefNameDecl(hasName("file"))))) #
works as well, matching the declaration
//
// match typeAliasTemplateDecl() # gets all declaration
// match typeAliasTemplateDecl(hasName("::gsl::owner")) # gets the
declaration right
// match typeAliasTemplateDecl(hasName("heap_array")) # gets the
declaration right
//
// match varDecl(hasType(hasDeclaration(typeAliasTemplateDecl()))) # nothing
// match
varDecl(hasType(hasDeclaration(typeAliasTemplateDecl(hasName("::gsl::owner")))))
# nothing
// match
varDecl(hasType(hasDeclaration(typeAliasTemplateDecl(hasName("owner")))))
# nothing
// match
varDecl(hasType(hasDeclaration(typeAliasTemplateDecl(hasName("::gsl::owner<int
*>"))))) # nothing
// match
varDecl(hasType(hasDeclaration(typeAliasTemplateDecl(hasName("heap_array")))))
# nothing
// match
varDecl(hasType(hasDeclaration(typeAliasTemplateDecl(hasName("heap_array<int>")))))
# nothing

Matching Variables, Parameters and so on for Using-Aliases seems to work
fine, but not for Templated Aliases.
I tested these, with the current clang-query from Trunk.

Is the way, iam approaching the matcher incorrect or is it some kind of
bug in typeAliasTemplateDecl?

Thank you very much for your help :slight_smile:

This is actually a problem with hasDeclaration; I realized that I hadn’t submitted https://reviews.llvm.org/D27104 yet; I now adapted it to also solve your problem (as this was simpler than fixing the current code).

Great, thanks!
I will continue the check for owner then.

Regards, Jonas :slight_smile:

The fixes are now in as of https://reviews.llvm.org/rL309809.

Cheers,
/Manuel