hasType(qualType(...)) is this a legal part of an ASTMatcher?

If I read the documentation at http://clang.llvm.org/docs/LibASTMatchersReference.html correctly, the partial matcher “hasType(qualType(…))” is not legal.

I ask because I’ve seen it used several times, it’s an example in the documentation for “isCanonicalType” (see below), and I’m wrapping the ASTMatcher library in my Common Lisp environment to write refactoring tools in Common Lisp and I’ve used the documentation at http://clang.llvm.org/docs/LibASTMatchersReference.html to define what matchers are legal and which are not.

I think I need to use hasType(qualType(…)) for a matcher that I’m writing and I need to figure out how to work it into my rules.

isCanonicalType documentation follows

Matches QualTypes whose canonical type matches InnerMatcher.

Given:
  typedef int &int_ref;
  int a;
  int_ref b = a;

varDecl(hasType(qualType(referenceType()))))) will not match the
declaration of b but varDecl(hasType(qualType(hasCanonicalType(referenceType())))))) does.

The predicate hasType(…) requires a Matcher as the inner matcher and qualType(…) is of type Matcher, not Matcher.

Any insight that anyone can provide would be very helpful.

Best,

Christian Schafmeister
Associate Professor
Chemistry Department
Temple University

If I read the documentation at
http://clang.llvm.org/docs/LibASTMatchersReference.html correctly, the
partial matcher "hasType(qualType(…))" is not legal.

hasType has an overload for Decl and QualType:
http://clang.llvm.org/doxygen/namespaceclang_1_1ast__matchers.html#a605703cba74d951cd64ee10b82bb4139

We have to fix the docs :slight_smile:

If I read the documentation at
http://clang.llvm.org/docs/LibASTMatchersReference.html correctly, the
partial matcher "hasType(qualType(…))" is not legal.

hasType has an overload for Decl and QualType:

http://clang.llvm.org/doxygen/namespaceclang_1_1ast__matchers.html#a605703cba74d951cd64ee10b82bb4139

We have to fix the docs :slight_smile:

Fixed in r202019. Cheers!