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

Jonas Toth via cfe-dev cfe-dev at lists.llvm.org
Fri Jul 28 03:29:20 PDT 2017


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

Regards, Jonas :)

Am 28.07.2017 11:28 vorm. schrieb "Manuel Klimek" <klimek at google.com>:

> 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/20170728/774a2b07/attachment.html>


More information about the cfe-dev mailing list