Open MichelleCDjunaidi opened 2 months ago
I'm working on a documentation update regarding contributing to clang-tidy (went through the process very recently and encountered some issues with the written guide), so I can handle the documentation update side, but I don't think I have the knowledge base to deal with the matchers yet.
As per https://clang.llvm.org/extra/clang-tidy/Contributing.html, clang-query is used for interactive prototyping of AST matchers that will eventually be used via clang-tidy. However, there are differences between two matchers such that a matcher that works in clang-query will not work as intended or doesn't compile in clang-tidy.
See the following discussions for examples/code-samples of this issue cropping up: https://discourse.llvm.org/t/matcher-working-in-clang-query-but-not-in-libtooling/56947 (clang-query matcher works, clang (and clang-tidy) doesn't compile) https://discourse.llvm.org/t/inconsistency-between-hasdescendant-in-clang-query-and-clang-libtooling-matchers/80799 (matcher compiles but doesn't work as intended)
Code samples (extracted from the first discussion, tested to be present at least up to clang 17.0.6):
The way to make the same behaviour as clang-query's matcher is to add a has in the middle:
Of course, this probably isn't ideal.
As it stands the quickest way to make people be at least aware of this difference is to edit the Contributing guide.
Ideally the differences can be resolved or reduced by refining the dynamic matchers (https://github.com/llvm/llvm-project/blob/main/clang/lib/ASTMatchers/Dynamic/Marshallers.cpp, https://github.com/llvm/llvm-project/blob/main/clang/lib/ASTMatchers/Dynamic/Parser.cpp), and the AST matchers (https://github.com/llvm/llvm-project/blob/main/clang/lib/ASTMatchers/ASTMatchersInternal.cpp, https://github.com/llvm/llvm-project/blob/main/clang/include/clang/ASTMatchers/ASTMatchersInternal.h).