[cfe-dev] clang-tidy or static analyzer or ...
Artem Dergachev via cfe-dev
cfe-dev at lists.llvm.org
Tue Sep 10 17:13:53 PDT 2019
On 9/10/19 3:54 PM, Stephen Kelly via cfe-dev wrote:
> On 10/09/2019 23:46, Artem Dergachev via cfe-dev wrote:
>> Yup, the most principled way of doing this with ASTMatchers is to
>> start with the function decl and then recurse inside it:
>>
>> functionDecl(matchesName(...), forEachDescendant(returnStmt(...)))
>>
>> You can always do this in an inside out, but it most likely has
>> performance implications (i never really understood how ASTMatcher
>> performance works as i've never had any real performance problems
>> with them):
>>
>> returnStmt(..., hasAncestor(functionDecl(matchesName(...))))
>>
> These will give unexpected results in the presence of lambdas for
> example. The `forFunction` expression should be used instead.
>
Yay nice, i never noticed this one, thanks!
Would it make sense to make a "direct" variant of this matcher as well,
i.e. a variant of forEachDescendant for functionDecls that only scans
statements within that function and doesn't descend into nested
declarations?
> Thanks,
>
> Stephen.
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list