[cfe-dev] Question about ASTMatcher `typeAliasTemplateDecl` for gsl::owner

Manuel Klimek via cfe-dev cfe-dev at lists.llvm.org
Wed Aug 2 07:05:34 PDT 2017


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

Cheers,
/Manuel

On Fri, Jul 28, 2017 at 11:27 AM Manuel Klimek <klimek at google.com> wrote:

> 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).
>
> On Wed, Jul 26, 2017 at 12:02 PM Jonas Toth via cfe-dev <
> cfe-dev at lists.llvm.org> wrote:
>
>> 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 :)
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170802/64db98e6/attachment.html>


More information about the cfe-dev mailing list