[cfe-dev] Question about ASTMatcher `typeAliasTemplateDecl` for gsl::owner
Jonas Toth via cfe-dev
cfe-dev at lists.llvm.org
Wed Jul 26 03:00:26 PDT 2017
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 :)
More information about the cfe-dev
mailing list