AST Matcher Reference

This document shows all currently implemented matchers. The matchers are grouped by category and node type they match. You can click on matcher names to show the matcher's source documentation.

There are three different basic categories of matchers:

Within each category the matchers are ordered by node type they match on. Note that if a matcher can match multiple node types, it will it will appear multiple times. This means that by searching for Matcher<Stmt> you can find all matchers that can be used to match on Stmt nodes.

The exception to that rule are matchers that can match on any node. Those are marked with a * and are listed in the beginning of each category.

Note that the categorization of matchers is a great help when you combine them into matcher expressions. You will usually want to form matcher expressions that read like english sentences by alternating between node matchers and narrowing or traversal matchers, like this:

recordDecl(hasDescendant(
    ifStmt(hasTrueExpression(
        expr(hasDescendant(
            ifStmt()))))))

Node Matchers

Node matchers are at the core of matcher expressions - they specify the type of node that is expected. Every match expression starts with a node matcher, which can then be further refined with a narrowing or traversal matcher. All traversal matchers take node matchers as their arguments.

For convenience, all node matchers take an arbitrary number of arguments and implicitly act as allOf matchers.

Node matchers are the only matchers that support the bind("id") call to bind the matched node to the given string, to be later retrieved from the match callback.

It is important to remember that the arguments to node matchers are predicates on the same node, just with additional information about the type. This is often useful to make matcher expression more readable by inlining bind calls into redundant node matchers inside another node matcher:

// This binds the CXXRecordDecl to "id", as the decl() matcher will stay on
// the same node.
recordDecl(decl().bind("id"), hasName("::MyClass"))

Return typeNameParameters
Matcher<CXXCtorInitializer>cxxCtorInitializerMatcher<CXXCtorInitializer>...
Matches constructor initializers.

Examples matches i(42).
  class C {
    C() : i(42) {}
    int i;
  };
Matcher<Decl>accessSpecDeclMatcher<AccessSpecDecl>...
Matches C++ access specifier declarations.

Given
  class C {
  public:
    int a;
  };
accessSpecDecl()
  matches 'public:'
Matcher<Decl>blockDeclMatcher<BlockDecl>...
Matches block declarations.

Example matches the declaration of the nameless block printing an input
integer.

  myFunc(^(int p) {
    printf("%d", p);
  })
Matcher<Decl>classTemplateDeclMatcher<ClassTemplateDecl>...
Matches C++ class template declarations.

Example matches Z
  template<class T> class Z {};
Matcher<Decl>classTemplatePartialSpecializationDeclMatcher<ClassTemplatePartialSpecializationDecl>...
Matches C++ class template partial specializations.

Given
  template<class T1, class T2, int I>
  class A {};

  template<class T, int I>
  class A<T, T*, I> {};

  template<>
  class A<int, int, 1> {};
classTemplatePartialSpecializationDecl()
  matches the specialization A<T,T*,I> but not A<int,int,1>
Matcher<Decl>classTemplateSpecializationDeclMatcher<ClassTemplateSpecializationDecl>...
Matches C++ class template specializations.

Given
  template<typename T> class A {};
  template<> class A<double> {};
  A<int> a;
classTemplateSpecializationDecl()
  matches the specializations A<int> and A<double>
Matcher<Decl>cxxConstructorDeclMatcher<CXXConstructorDecl>...
Matches C++ constructor declarations.

Example matches Foo::Foo() and Foo::Foo(int)
  class Foo {
   public:
    Foo();
    Foo(int);
    int DoSomething();
  };
Matcher<Decl>cxxConversionDeclMatcher<CXXConversionDecl>...
Matches conversion operator declarations.

Example matches the operator.
  class X { operator int() const; };
Matcher<Decl>cxxDeductionGuideDeclMatcher<CXXDeductionGuideDecl>...
Matches user-defined and implicitly generated deduction guide.

Example matches the deduction guide.
  template<typename T>
  class X { X(int) };
  X(int) -> X<int>;
Matcher<Decl>cxxDestructorDeclMatcher<CXXDestructorDecl>...
Matches explicit C++ destructor declarations.

Example matches Foo::~Foo()
  class Foo {
   public:
    virtual ~Foo();
  };
Matcher<Decl>cxxMethodDeclMatcher<CXXMethodDecl>...
Matches method declarations.

Example matches y
  class X { void y(); };
Matcher<Decl>cxxRecordDeclMatcher<CXXRecordDecl>...
Matches C++ class declarations.

Example matches X, Z
  class X;
  template<class T> class Z {};
Matcher<Decl>declMatcher<Decl>...
Matches declarations.

Examples matches X, C, and the friend declaration inside C;
  void X();
  class C {
    friend X;
  };
Matcher<Decl>declaratorDeclMatcher<DeclaratorDecl>...
Matches declarator declarations (field, variable, function
and non-type template parameter declarations).

Given
  class X { int y; };
declaratorDecl()
  matches int y.
Matcher<Decl>enumConstantDeclMatcher<EnumConstantDecl>...
Matches enum constants.

Example matches A, B, C
  enum X {
    A, B, C
  };
Matcher<Decl>enumDeclMatcher<EnumDecl>...
Matches enum declarations.

Example matches X
  enum X {
    A, B, C
  };
Matcher<Decl>fieldDeclMatcher<FieldDecl>...
Matches field declarations.

Given
  class X { int m; };
fieldDecl()
  matches 'm'.
Matcher<Decl>friendDeclMatcher<FriendDecl>...
Matches friend declarations.

Given
  class X { friend void foo(); };
friendDecl()
  matches 'friend void foo()'.
Matcher<Decl>functionDeclMatcher<FunctionDecl>...
Matches function declarations.

Example matches f
  void f();
Matcher<Decl>functionTemplateDeclMatcher<FunctionTemplateDecl>...
Matches C++ function template declarations.

Example matches f
  template<class T> void f(T t) {}
Matcher<Decl>indirectFieldDeclMatcher<IndirectFieldDecl>...
Matches indirect field declarations.

Given
  struct X { struct { int a; }; };
indirectFieldDecl()
  matches 'a'.
Matcher<Decl>labelDeclMatcher<LabelDecl>...
Matches a declaration of label.

Given
  goto FOO;
  FOO: bar();
labelDecl()
  matches 'FOO:'
Matcher<Decl>linkageSpecDeclMatcher<LinkageSpecDecl>...
Matches a declaration of a linkage specification.

Given
  extern "C" {}
linkageSpecDecl()
  matches "extern "C" {}"
Matcher<Decl>namedDeclMatcher<NamedDecl>...
Matches a declaration of anything that could have a name.

Example matches X, S, the anonymous union type, i, and U;
  typedef int X;
  struct S {
    union {
      int i;
    } U;
  };
Matcher<Decl>namespaceAliasDeclMatcher<NamespaceAliasDecl>...
Matches a declaration of a namespace alias.

Given
  namespace test {}
  namespace alias = ::test;
namespaceAliasDecl()
  matches "namespace alias" but not "namespace test"
Matcher<Decl>namespaceDeclMatcher<NamespaceDecl>...
Matches a declaration of a namespace.

Given
  namespace {}
  namespace test {}
namespaceDecl()
  matches "namespace {}" and "namespace test {}"
Matcher<Decl>nonTypeTemplateParmDeclMatcher<NonTypeTemplateParmDecl>...
Matches non-type template parameter declarations.

Given
  template <typename T, int N> struct C {};
nonTypeTemplateParmDecl()
  matches 'N', but not 'T'.
Matcher<Decl>objcCategoryDeclMatcher<ObjCCategoryDecl>...
Matches Objective-C category declarations.

Example matches Foo (Additions)
  @interface Foo (Additions)
  @end
Matcher<Decl>objcCategoryImplDeclMatcher<ObjCCategoryImplDecl>...
Matches Objective-C category definitions.

Example matches Foo (Additions)
  @implementation Foo (Additions)
  @end
Matcher<Decl>objcImplementationDeclMatcher<ObjCImplementationDecl>...
Matches Objective-C implementation declarations.

Example matches Foo
  @implementation Foo
  @end
Matcher<Decl>objcInterfaceDeclMatcher<ObjCInterfaceDecl>...
Matches Objective-C interface declarations.

Example matches Foo
  @interface Foo
  @end
Matcher<Decl>objcIvarDeclMatcher<ObjCIvarDecl>...
Matches Objective-C instance variable declarations.

Example matches _enabled
  @implementation Foo {
    BOOL _enabled;
  }
  @end
Matcher<Decl>objcMethodDeclMatcher<ObjCMethodDecl>...
Matches Objective-C method declarations.

Example matches both declaration and definition of -[Foo method]
  @interface Foo
  - (void)method;
  @end

  @implementation Foo
  - (void)method {}
  @end
Matcher<Decl>objcPropertyDeclMatcher<ObjCPropertyDecl>...
Matches Objective-C property declarations.

Example matches enabled
  @interface Foo
  @property BOOL enabled;
  @end
Matcher<Decl>objcProtocolDeclMatcher<ObjCProtocolDecl>...
Matches Objective-C protocol declarations.

Example matches FooDelegate
  @protocol FooDelegate
  @end
Matcher<Decl>parmVarDeclMatcher<ParmVarDecl>...
Matches parameter variable declarations.

Given
  void f(int x);
parmVarDecl()
  matches int x.
Matcher<Decl>recordDeclMatcher<RecordDecl>...
Matches class, struct, and union declarations.

Example matches X, Z, U, and S
  class X;
  template<class T> class Z {};
  struct S {};
  union U {};
Matcher<Decl>staticAssertDeclMatcher<StaticAssertDecl>...
Matches a C++ static_assert declaration.

Example:
  staticAssertExpr()
matches
  static_assert(sizeof(S) == sizeof(int))
in
  struct S {
    int x;
  };
  static_assert(sizeof(S) == sizeof(int));
Matcher<Decl>templateTypeParmDeclMatcher<TemplateTypeParmDecl>...
Matches template type parameter declarations.

Given
  template <typename T, int N> struct C {};
templateTypeParmDecl()
  matches 'T', but not 'N'.
Matcher<Decl>translationUnitDeclMatcher<TranslationUnitDecl>...
Matches the top declaration context.

Given
  int X;
  namespace NS {
  int Y;
  }  // namespace NS
decl(hasDeclContext(translationUnitDecl()))
  matches "int X", but not "int Y".
Matcher<Decl>typeAliasDeclMatcher<TypeAliasDecl>...
Matches type alias declarations.

Given
  typedef int X;
  using Y = int;
typeAliasDecl()
  matches "using Y = int", but not "typedef int X"
Matcher<Decl>typeAliasTemplateDeclMatcher<TypeAliasTemplateDecl>...
Matches type alias template declarations.

typeAliasTemplateDecl() matches
  template <typename T>
  using Y = X<T>;
Matcher<Decl>typedefDeclMatcher<TypedefDecl>...
Matches typedef declarations.

Given
  typedef int X;
  using Y = int;
typedefDecl()
  matches "typedef int X", but not "using Y = int"
Matcher<Decl>typedefNameDeclMatcher<TypedefNameDecl>...
Matches typedef name declarations.

Given
  typedef int X;
  using Y = int;
typedefNameDecl()
  matches "typedef int X" and "using Y = int"
Matcher<Decl>unresolvedUsingTypenameDeclMatcher<UnresolvedUsingTypenameDecl>...
Matches unresolved using value declarations that involve the
typename.

Given
  template <typename T>
  struct Base { typedef T Foo; };

  template<typename T>
  struct S : private Base<T> {
    using typename Base<T>::Foo;
  };
unresolvedUsingTypenameDecl()
  matches using Base<T>::Foo 
Matcher<Decl>unresolvedUsingValueDeclMatcher<UnresolvedUsingValueDecl>...
Matches unresolved using value declarations.

Given
  template<typename X>
  class C : private X {
    using X::x;
  };
unresolvedUsingValueDecl()
  matches using X::x 
Matcher<Decl>usingDeclMatcher<UsingDecl>...
Matches using declarations.

Given
  namespace X { int x; }
  using X::x;
usingDecl()
  matches using X::x 
Matcher<Decl>usingDirectiveDeclMatcher<UsingDirectiveDecl>...
Matches using namespace declarations.

Given
  namespace X { int x; }
  using namespace X;
usingDirectiveDecl()
  matches using namespace X 
Matcher<Decl>valueDeclMatcher<ValueDecl>...
Matches any value declaration.

Example matches A, B, C and F
  enum X { A, B, C };
  void F();
Matcher<Decl>varDeclMatcher<VarDecl>...
Matches variable declarations.

Note: this does not match declarations of member variables, which are
"field" declarations in Clang parlance.

Example matches a
  int a;
Matcher<NestedNameSpecifierLoc>nestedNameSpecifierLocMatcher<NestedNameSpecifierLoc>...
Same as nestedNameSpecifier but matches NestedNameSpecifierLoc.
Matcher<NestedNameSpecifier>nestedNameSpecifierMatcher<NestedNameSpecifier>...
Matches nested name specifiers.

Given
  namespace ns {
    struct A { static void f(); };
    void A::f() {}
    void g() { A::f(); }
  }
  ns::A a;
nestedNameSpecifier()
  matches "ns::" and both "A::"
Matcher<OMPClause>ompDefaultClauseMatcher<OMPDefaultClause>...
Matches OpenMP ``default`` clause.

Given

  #pragma omp parallel default(none)
  #pragma omp parallel default(shared)
  #pragma omp parallel

``ompDefaultClause()`` matches ``default(none)`` and ``default(shared)``.
Matcher<QualType>qualTypeMatcher<QualType>...
Matches QualTypes in the clang AST.
Matcher<Stmt>addrLabelExprMatcher<AddrLabelExpr>...
Matches address of label statements (GNU extension).

Given
  FOO: bar();
  void *ptr = &&FOO;
  goto *bar;
addrLabelExpr()
  matches '&&FOO'
Matcher<Stmt>arraySubscriptExprMatcher<ArraySubscriptExpr>...
Matches array subscript expressions.

Given
  int i = a[1];
arraySubscriptExpr()
  matches "a[1]"
Matcher<Stmt>asmStmtMatcher<AsmStmt>...
Matches asm statements.

 int i = 100;
  __asm("mov al, 2");
asmStmt()
  matches '__asm("mov al, 2")'
Matcher<Stmt>atomicExprMatcher<AtomicExpr>...
Matches atomic builtins.
Example matches __atomic_load_n(ptr, 1)
  void foo() { int *ptr; __atomic_load_n(ptr, 1); }
Matcher<Stmt>autoreleasePoolStmtMatcher<ObjCAutoreleasePoolStmt>...
Matches an Objective-C autorelease pool statement.

Given
  @autoreleasepool {
    int x = 0;
  }
autoreleasePoolStmt(stmt()) matches the declaration of "x"
inside the autorelease pool.
Matcher<Stmt>binaryConditionalOperatorMatcher<BinaryConditionalOperator>...
Matches binary conditional operator expressions (GNU extension).

Example matches a ?: b
  (a ?: b) + 42;
Matcher<Stmt>binaryOperatorMatcher<BinaryOperator>...
Matches binary operator expressions.

Example matches a || b
  !(a || b)
Matcher<Stmt>blockExprMatcher<BlockExpr>...
Matches a reference to a block.

Example: matches "^{}":
  void f() { ^{}(); }
Matcher<Stmt>breakStmtMatcher<BreakStmt>...
Matches break statements.

Given
  while (true) { break; }
breakStmt()
  matches 'break'
Matcher<Stmt>cStyleCastExprMatcher<CStyleCastExpr>...
Matches a C-style cast expression.

Example: Matches (int) 2.2f in
  int i = (int) 2.2f;
Matcher<Stmt>callExprMatcher<CallExpr>...
Matches call expressions.

Example matches x.y() and y()
  X x;
  x.y();
  y();
Matcher<Stmt>caseStmtMatcher<CaseStmt>...
Matches case statements inside switch statements.

Given
  switch(a) { case 42: break; default: break; }
caseStmt()
  matches 'case 42:'.
Matcher<Stmt>castExprMatcher<CastExpr>...
Matches any cast nodes of Clang's AST.

Example: castExpr() matches each of the following:
  (int) 3;
  const_cast<Expr *>(SubExpr);
  char c = 0;
but does not match
  int i = (0);
  int k = 0;
Matcher<Stmt>characterLiteralMatcher<CharacterLiteral>...
Matches character literals (also matches wchar_t).

Not matching Hex-encoded chars (e.g. 0x1234, which is a IntegerLiteral),
though.

Example matches 'a', L'a'
  char ch = 'a';
  wchar_t chw = L'a';
Matcher<Stmt>chooseExprMatcher<ChooseExpr>...
Matches GNU __builtin_choose_expr.
Matcher<Stmt>compoundLiteralExprMatcher<CompoundLiteralExpr>...
Matches compound (i.e. non-scalar) literals

Example match: {1}, (1, 2)
  int array[4] = {1};
  vector int myvec = (vector int)(1, 2);
Matcher<Stmt>compoundStmtMatcher<CompoundStmt>...
Matches compound statements.

Example matches '{}' and '{{}}' in 'for (;;) {{}}'
  for (;;) {{}}
Matcher<Stmt>conditionalOperatorMatcher<ConditionalOperator>...
Matches conditional operator expressions.

Example matches a ? b : c
  (a ? b : c) + 42
Matcher<Stmt>constantExprMatcher<ConstantExpr>...
Matches a constant expression wrapper.

Example matches the constant in the case statement:
    (matcher = constantExpr())
  switch (a) {
  case 37: break;
  }
Matcher<Stmt>continueStmtMatcher<ContinueStmt>...
Matches continue statements.

Given
  while (true) { continue; }
continueStmt()
  matches 'continue'
Matcher<Stmt>cudaKernelCallExprMatcher<CUDAKernelCallExpr>...
Matches CUDA kernel call expression.

Example matches,
  kernel<<<i,j>>>();
Matcher<Stmt>cxxBindTemporaryExprMatcher<CXXBindTemporaryExpr>...
Matches nodes where temporaries are created.

Example matches FunctionTakesString(GetStringByValue())
    (matcher = cxxBindTemporaryExpr())
  FunctionTakesString(GetStringByValue());
  FunctionTakesStringByPointer(GetStringPointer());
Matcher<Stmt>cxxBoolLiteralMatcher<CXXBoolLiteralExpr>...
Matches bool literals.

Example matches true
  true
Matcher<Stmt>cxxCatchStmtMatcher<CXXCatchStmt>...
Matches catch statements.

  try {} catch(int i) {}
cxxCatchStmt()
  matches 'catch(int i)'
Matcher<Stmt>cxxConstCastExprMatcher<CXXConstCastExpr>...
Matches a const_cast expression.

Example: Matches const_cast<int*>(&r) in
  int n = 42;
  const int &r(n);
  int* p = const_cast<int*>(&r);
Matcher<Stmt>cxxConstructExprMatcher<CXXConstructExpr>...
Matches constructor call expressions (including implicit ones).

Example matches string(ptr, n) and ptr within arguments of f
    (matcher = cxxConstructExpr())
  void f(const string &a, const string &b);
  char *ptr;
  int n;
  f(string(ptr, n), ptr);
Matcher<Stmt>cxxDefaultArgExprMatcher<CXXDefaultArgExpr>...
Matches the value of a default argument at the call site.

Example matches the CXXDefaultArgExpr placeholder inserted for the
    default value of the second parameter in the call expression f(42)
    (matcher = cxxDefaultArgExpr())
  void f(int x, int y = 0);
  f(42);
Matcher<Stmt>cxxDeleteExprMatcher<CXXDeleteExpr>...
Matches delete expressions.

Given
  delete X;
cxxDeleteExpr()
  matches 'delete X'.
Matcher<Stmt>cxxDependentScopeMemberExprMatcher<CXXDependentScopeMemberExpr>...
Matches member expressions where the actual member referenced could not be
resolved because the base expression or the member name was dependent.

Given
  template <class T> void f() { T t; t.g(); }
cxxDependentScopeMemberExpr()
  matches t.g
Matcher<Stmt>cxxDynamicCastExprMatcher<CXXDynamicCastExpr>...
Matches a dynamic_cast expression.

Example:
  cxxDynamicCastExpr()
matches
  dynamic_cast<D*>(&b);
in
  struct B { virtual ~B() {} }; struct D : B {};
  B b;
  D* p = dynamic_cast<D*>(&b);
Matcher<Stmt>cxxForRangeStmtMatcher<CXXForRangeStmt>...
Matches range-based for statements.

cxxForRangeStmt() matches 'for (auto a : i)'
  int i[] =  {1, 2, 3}; for (auto a : i);
  for(int j = 0; j < 5; ++j);
Matcher<Stmt>cxxFunctionalCastExprMatcher<CXXFunctionalCastExpr>...
Matches functional cast expressions

Example: Matches Foo(bar);
  Foo f = bar;
  Foo g = (Foo) bar;
  Foo h = Foo(bar);
Matcher<Stmt>cxxMemberCallExprMatcher<CXXMemberCallExpr>...
Matches member call expressions.

Example matches x.y()
  X x;
  x.y();
Matcher<Stmt>cxxNewExprMatcher<CXXNewExpr>...
Matches new expressions.

Given
  new X;
cxxNewExpr()
  matches 'new X'.
Matcher<Stmt>cxxNullPtrLiteralExprMatcher<CXXNullPtrLiteralExpr>...
Matches nullptr literal.
Matcher<Stmt>cxxOperatorCallExprMatcher<CXXOperatorCallExpr>...
Matches overloaded operator calls.

Note that if an operator isn't overloaded, it won't match. Instead, use
binaryOperator matcher.
Currently it does not match operators such as new delete.
FIXME: figure out why these do not match?

Example matches both operator<<((o << b), c) and operator<<(o, b)
    (matcher = cxxOperatorCallExpr())
  ostream &operator<< (ostream &out, int i) { };
  ostream &o; int b = 1, c = 1;
  o << b << c;
Matcher<Stmt>cxxReinterpretCastExprMatcher<CXXReinterpretCastExpr>...
Matches a reinterpret_cast expression.

Either the source expression or the destination type can be matched
using has(), but hasDestinationType() is more specific and can be
more readable.

Example matches reinterpret_cast<char*>(&p) in
  void* p = reinterpret_cast<char*>(&p);
Matcher<Stmt>cxxStaticCastExprMatcher<CXXStaticCastExpr>...
Matches a C++ static_cast expression.

See also: hasDestinationType
See also: reinterpretCast

Example:
  cxxStaticCastExpr()
matches
  static_cast<long>(8)
in
  long eight(static_cast<long>(8));
Matcher<Stmt>cxxStdInitializerListExprMatcher<CXXStdInitializerListExpr>...
Matches C++ initializer list expressions.

Given
  std::vector<int> a({ 1, 2, 3 });
  std::vector<int> b = { 4, 5 };
  int c[] = { 6, 7 };
  std::pair<int, int> d = { 8, 9 };
cxxStdInitializerListExpr()
  matches "{ 1, 2, 3 }" and "{ 4, 5 }"
Matcher<Stmt>cxxTemporaryObjectExprMatcher<CXXTemporaryObjectExpr>...
Matches functional cast expressions having N != 1 arguments

Example: Matches Foo(bar, bar)
  Foo h = Foo(bar, bar);
Matcher<Stmt>cxxThisExprMatcher<CXXThisExpr>...
Matches implicit and explicit this expressions.

Example matches the implicit this expression in "return i".
    (matcher = cxxThisExpr())
struct foo {
  int i;
  int f() { return i; }
};
Matcher<Stmt>cxxThrowExprMatcher<CXXThrowExpr>...
Matches throw expressions.

  try { throw 5; } catch(int i) {}
cxxThrowExpr()
  matches 'throw 5'
Matcher<Stmt>cxxTryStmtMatcher<CXXTryStmt>...
Matches try statements.

  try {} catch(int i) {}
cxxTryStmt()
  matches 'try {}'
Matcher<Stmt>cxxUnresolvedConstructExprMatcher<CXXUnresolvedConstructExpr>...
Matches unresolved constructor call expressions.

Example matches T(t) in return statement of f
    (matcher = cxxUnresolvedConstructExpr())
  template <typename T>
  void f(const T& t) { return T(t); }
Matcher<Stmt>declRefExprMatcher<DeclRefExpr>...
Matches expressions that refer to declarations.

Example matches x in if (x)
  bool x;
  if (x) {}
Matcher<Stmt>declStmtMatcher<DeclStmt>...
Matches declaration statements.

Given
  int a;
declStmt()
  matches 'int a'.
Matcher<Stmt>defaultStmtMatcher<DefaultStmt>...
Matches default statements inside switch statements.

Given
  switch(a) { case 42: break; default: break; }
defaultStmt()
  matches 'default:'.
Matcher<Stmt>designatedInitExprMatcher<DesignatedInitExpr>...
Matches C99 designated initializer expressions [C99 6.7.8].

Example: Matches { [2].y = 1.0, [0].x = 1.0 }
  point ptarray[10] = { [2].y = 1.0, [0].x = 1.0 };
Matcher<Stmt>doStmtMatcher<DoStmt>...
Matches do statements.

Given
  do {} while (true);
doStmt()
  matches 'do {} while(true)'
Matcher<Stmt>explicitCastExprMatcher<ExplicitCastExpr>...
Matches explicit cast expressions.

Matches any cast expression written in user code, whether it be a
C-style cast, a functional-style cast, or a keyword cast.

Does not match implicit conversions.

Note: the name "explicitCast" is chosen to match Clang's terminology, as
Clang uses the term "cast" to apply to implicit conversions as well as to
actual cast expressions.

See also: hasDestinationType.

Example: matches all five of the casts in
  int((int)(reinterpret_cast<int>(static_cast<int>(const_cast<int>(42)))))
but does not match the implicit conversion in
  long ell = 42;
Matcher<Stmt>exprMatcher<Expr>...
Matches expressions.

Example matches x()
  void f() { x(); }
Matcher<Stmt>exprWithCleanupsMatcher<ExprWithCleanups>...
Matches expressions that introduce cleanups to be run at the end
of the sub-expression's evaluation.

Example matches std::string()
  const std::string str = std::string();
Matcher<Stmt>floatLiteralMatcher<FloatingLiteral>...
Matches float literals of all sizes / encodings, e.g.
1.0, 1.0f, 1.0L and 1e10.

Does not match implicit conversions such as
  float a = 10;
Matcher<Stmt>forStmtMatcher<ForStmt>...
Matches for statements.

Example matches 'for (;;) {}'
  for (;;) {}
  int i[] =  {1, 2, 3}; for (auto a : i);
Matcher<Stmt>gnuNullExprMatcher<GNUNullExpr>...
Matches GNU __null expression.
Matcher<Stmt>gotoStmtMatcher<GotoStmt>...
Matches goto statements.

Given
  goto FOO;
  FOO: bar();
gotoStmt()
  matches 'goto FOO'
Matcher<Stmt>ifStmtMatcher<IfStmt>...
Matches if statements.

Example matches 'if (x) {}'
  if (x) {}
Matcher<Stmt>imaginaryLiteralMatcher<ImaginaryLiteral>...
Matches imaginary literals, which are based on integer and floating
point literals e.g.: 1i, 1.0i
Matcher<Stmt>implicitCastExprMatcher<ImplicitCastExpr>...
Matches the implicit cast nodes of Clang's AST.

This matches many different places, including function call return value
eliding, as well as any type conversions.
Matcher<Stmt>implicitValueInitExprMatcher<ImplicitValueInitExpr>...
Matches implicit initializers of init list expressions.

Given
  point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
implicitValueInitExpr()
  matches "[0].y" (implicitly)
Matcher<Stmt>initListExprMatcher<InitListExpr>...
Matches init list expressions.

Given
  int a[] = { 1, 2 };
  struct B { int x, y; };
  B b = { 5, 6 };
initListExpr()
  matches "{ 1, 2 }" and "{ 5, 6 }"
Matcher<Stmt>integerLiteralMatcher<IntegerLiteral>...
Matches integer literals of all sizes / encodings, e.g.
1, 1L, 0x1 and 1U.

Does not match character-encoded integers such as L'a'.
Matcher<Stmt>labelStmtMatcher<LabelStmt>...
Matches label statements.

Given
  goto FOO;
  FOO: bar();
labelStmt()
  matches 'FOO:'
Matcher<Stmt>lambdaExprMatcher<LambdaExpr>...
Matches lambda expressions.

Example matches [&](){return 5;}
  [&](){return 5;}
Matcher<Stmt>materializeTemporaryExprMatcher<MaterializeTemporaryExpr>...
Matches nodes where temporaries are materialized.

Example: Given
  struct T {void func();};
  T f();
  void g(T);
materializeTemporaryExpr() matches 'f()' in these statements
  T u(f());
  g(f());
  f().func();
but does not match
  f();
Matcher<Stmt>memberExprMatcher<MemberExpr>...
Matches member expressions.

Given
  class Y {
    void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; }
    int a; static int b;
  };
memberExpr()
  matches this->x, x, y.x, a, this->b
Matcher<Stmt>nullStmtMatcher<NullStmt>...
Matches null statements.

  foo();;
nullStmt()
  matches the second ';'
Matcher<Stmt>objcCatchStmtMatcher<ObjCAtCatchStmt>...
Matches Objective-C @catch statements.

Example matches @catch
  @try {}
  @catch (...) {}
Matcher<Stmt>objcFinallyStmtMatcher<ObjCAtFinallyStmt>...
Matches Objective-C @finally statements.

Example matches @finally
  @try {}
  @finally {}
Matcher<Stmt>objcIvarRefExprMatcher<ObjCIvarRefExpr>...
Matches a reference to an ObjCIvar.

Example: matches "a" in "init" method:
@implementation A {
  NSString *a;
}
- (void) init {
  a = @"hello";
}
Matcher<Stmt>objcMessageExprMatcher<ObjCMessageExpr>...
Matches ObjectiveC Message invocation expressions.

The innermost message send invokes the "alloc" class method on the
NSString class, while the outermost message send invokes the
"initWithString" instance method on the object returned from
NSString's "alloc". This matcher should match both message sends.
  [[NSString alloc] initWithString:@"Hello"]
Matcher<Stmt>objcThrowStmtMatcher<ObjCAtThrowStmt>...
Matches Objective-C statements.

Example matches @throw obj;
Matcher<Stmt>objcTryStmtMatcher<ObjCAtTryStmt>...
Matches Objective-C @try statements.

Example matches @try
  @try {}
  @catch (...) {}
Matcher<Stmt>ompExecutableDirectiveMatcher<OMPExecutableDirective>...
Matches any ``#pragma omp`` executable directive.

Given

  #pragma omp parallel
  #pragma omp parallel default(none)
  #pragma omp taskyield

``ompExecutableDirective()`` matches ``omp parallel``,
``omp parallel default(none)`` and ``omp taskyield``.
Matcher<Stmt>opaqueValueExprMatcher<OpaqueValueExpr>...
Matches opaque value expressions. They are used as helpers
to reference another expressions and can be met
in BinaryConditionalOperators, for example.

Example matches 'a'
  (a ?: c) + 42;
Matcher<Stmt>parenExprMatcher<ParenExpr>...
Matches parentheses used in expressions.

Example matches (foo() + 1)
  int foo() { return 1; }
  int a = (foo() + 1);
Matcher<Stmt>parenListExprMatcher<ParenListExpr>...
Matches paren list expressions.
ParenListExprs don't have a predefined type and are used for late parsing.
In the final AST, they can be met in template declarations.

Given
  template<typename T> class X {
    void f() {
      X x(*this);
      int a = 0, b = 1; int i = (a, b);
    }
  };
parenListExpr() matches "*this" but NOT matches (a, b) because (a, b)
has a predefined type and is a ParenExpr, not a ParenListExpr.
Matcher<Stmt>predefinedExprMatcher<PredefinedExpr>...
Matches predefined identifier expressions [C99 6.4.2.2].

Example: Matches __func__
  printf("%s", __func__);
Matcher<Stmt>returnStmtMatcher<ReturnStmt>...
Matches return statements.

Given
  return 1;
returnStmt()
  matches 'return 1'
Matcher<Stmt>stmtMatcher<Stmt>...
Matches statements.

Given
  { ++a; }
stmt()
  matches both the compound statement '{ ++a; }' and '++a'.
Matcher<Stmt>stmtExprMatcher<StmtExpr>...
Matches statement expression (GNU extension).

Example match: ({ int X = 4; X; })
  int C = ({ int X = 4; X; });
Matcher<Stmt>stringLiteralMatcher<StringLiteral>...
Matches string literals (also matches wide string literals).

Example matches "abcd", L"abcd"
  char *s = "abcd";
  wchar_t *ws = L"abcd";
Matcher<Stmt>substNonTypeTemplateParmExprMatcher<SubstNonTypeTemplateParmExpr>...
Matches substitutions of non-type template parameters.

Given
  template <int N>
  struct A { static const int n = N; };
  struct B : public A<42> {};
substNonTypeTemplateParmExpr()
  matches "N" in the right-hand side of "static const int n = N;"
Matcher<Stmt>switchCaseMatcher<SwitchCase>...
Matches case and default statements inside switch statements.

Given
  switch(a) { case 42: break; default: break; }
switchCase()
  matches 'case 42:' and 'default:'.
Matcher<Stmt>switchStmtMatcher<SwitchStmt>...
Matches switch statements.

Given
  switch(a) { case 42: break; default: break; }
switchStmt()
  matches 'switch(a)'.
Matcher<Stmt>unaryExprOrTypeTraitExprMatcher<UnaryExprOrTypeTraitExpr>...
Matches sizeof (C99), alignof (C++11) and vec_step (OpenCL)

Given
  Foo x = bar;
  int y = sizeof(x) + alignof(x);
unaryExprOrTypeTraitExpr()
  matches sizeof(x) and alignof(x)
Matcher<Stmt>unaryOperatorMatcher<UnaryOperator>...
Matches unary operator expressions.

Example matches !a
  !a || b
Matcher<Stmt>unresolvedLookupExprMatcher<UnresolvedLookupExpr>...
Matches reference to a name that can be looked up during parsing
but could not be resolved to a specific declaration.

Given
  template<typename T>
  T foo() { T a; return a; }
  template<typename T>
  void bar() {
    foo<T>();
  }
unresolvedLookupExpr()
  matches foo<T>() 
Matcher<Stmt>unresolvedMemberExprMatcher<UnresolvedMemberExpr>...
Matches unresolved member expressions.

Given
  struct X {
    template <class T> void f();
    void g();
  };
  template <class T> void h() { X x; x.f<T>(); x.g(); }
unresolvedMemberExpr()
  matches x.f<T>
Matcher<Stmt>userDefinedLiteralMatcher<UserDefinedLiteral>...
Matches user defined literal operator call.

Example match: "foo"_suffix
Matcher<Stmt>whileStmtMatcher<WhileStmt>...
Matches while statements.

Given
  while (true) {}
whileStmt()
  matches 'while (true) {}'.
Matcher<TemplateArgument>templateArgumentMatcher<TemplateArgument>...
Matches template arguments.

Given
  template <typename T> struct C {};
  C<int> c;
templateArgument()
  matches 'int' in C<int>.
Matcher<TemplateName>templateNameMatcher<TemplateName>...
Matches template name.

Given
  template <typename T> class X { };
  X<int> xi;
templateName()
  matches 'X' in X<int>.
Matcher<TypeLoc>typeLocMatcher<TypeLoc>...
Matches TypeLocs in the clang AST.
Matcher<Type>arrayTypeMatcher<ArrayType>...
Matches all kinds of arrays.

Given
  int a[] = { 2, 3 };
  int b[4];
  void f() { int c[a[0]]; }
arrayType()
  matches "int a[]", "int b[4]" and "int c[a[0]]";
Matcher<Type>atomicTypeMatcher<AtomicType>...
Matches atomic types.

Given
  _Atomic(int) i;
atomicType()
  matches "_Atomic(int) i"
Matcher<Type>autoTypeMatcher<AutoType>...
Matches types nodes representing C++11 auto types.

Given:
  auto n = 4;
  int v[] = { 2, 3 }
  for (auto i : v) { }
autoType()
  matches "auto n" and "auto i"
Matcher<Type>blockPointerTypeMatcher<BlockPointerType>...
Matches block pointer types, i.e. types syntactically represented as
"void (^)(int)".

The pointee is always required to be a FunctionType.
Matcher<Type>builtinTypeMatcher<BuiltinType>...
Matches builtin Types.

Given
  struct A {};
  A a;
  int b;
  float c;
  bool d;
builtinType()
  matches "int b", "float c" and "bool d"
Matcher<Type>complexTypeMatcher<ComplexType>...
Matches C99 complex types.

Given
  _Complex float f;
complexType()
  matches "_Complex float f"
Matcher<Type>constantArrayTypeMatcher<ConstantArrayType>...
Matches C arrays with a specified constant size.

Given
  void() {
    int a[2];
    int b[] = { 2, 3 };
    int c[b[0]];
  }
constantArrayType()
  matches "int a[2]"
Matcher<Type>decayedTypeMatcher<DecayedType>...
Matches decayed type
Example matches i[] in declaration of f.
    (matcher = valueDecl(hasType(decayedType(hasDecayedType(pointerType())))))
Example matches i[1].
    (matcher = expr(hasType(decayedType(hasDecayedType(pointerType())))))
  void f(int i[]) {
    i[1] = 0;
  }
Matcher<Type>decltypeTypeMatcher<DecltypeType>...
Matches types nodes representing C++11 decltype(<expr>) types.

Given:
  short i = 1;
  int j = 42;
  decltype(i + j) result = i + j;
decltypeType()
  matches "decltype(i + j)"
Matcher<Type>dependentSizedArrayTypeMatcher<DependentSizedArrayType>...
Matches C++ arrays whose size is a value-dependent expression.

Given
  template<typename T, int Size>
  class array {
    T data[Size];
  };
dependentSizedArrayType
  matches "T data[Size]"
Matcher<Type>elaboratedTypeMatcher<ElaboratedType>...
Matches types specified with an elaborated type keyword or with a
qualified name.

Given
  namespace N {
    namespace M {
      class D {};
    }
  }
  class C {};

  class C c;
  N::M::D d;

elaboratedType() matches the type of the variable declarations of both
c and d.
Matcher<Type>enumTypeMatcher<EnumType>...
Matches enum types.

Given
  enum C { Green };
  enum class S { Red };

  C c;
  S s;

enumType() matches the type of the variable declarations of both c and
s.
Matcher<Type>functionProtoTypeMatcher<FunctionProtoType>...
Matches FunctionProtoType nodes.

Given
  int (*f)(int);
  void g();
functionProtoType()
  matches "int (*f)(int)" and the type of "g" in C++ mode.
  In C mode, "g" is not matched because it does not contain a prototype.
Matcher<Type>functionTypeMatcher<FunctionType>...
Matches FunctionType nodes.

Given
  int (*f)(int);
  void g();
functionType()
  matches "int (*f)(int)" and the type of "g".
Matcher<Type>incompleteArrayTypeMatcher<IncompleteArrayType>...
Matches C arrays with unspecified size.

Given
  int a[] = { 2, 3 };
  int b[42];
  void f(int c[]) { int d[a[0]]; };
incompleteArrayType()
  matches "int a[]" and "int c[]"
Matcher<Type>injectedClassNameTypeMatcher<InjectedClassNameType>...
Matches injected class name types.

Example matches S s, but not S<T> s.
    (matcher = parmVarDecl(hasType(injectedClassNameType())))
  template <typename T> struct S {
    void f(S s);
    void g(S<T> s);
  };
Matcher<Type>lValueReferenceTypeMatcher<LValueReferenceType>...
Matches lvalue reference types.

Given:
  int *a;
  int &b = *a;
  int &&c = 1;
  auto &d = b;
  auto &&e = c;
  auto &&f = 2;
  int g = 5;

lValueReferenceType() matches the types of b, d, and e. e is
matched since the type is deduced as int& by reference collapsing rules.
Matcher<Type>memberPointerTypeMatcher<MemberPointerType>...
Matches member pointer types.
Given
  struct A { int i; }
  A::* ptr = A::i;
memberPointerType()
  matches "A::* ptr"
Matcher<Type>objcObjectPointerTypeMatcher<ObjCObjectPointerType>...
Matches an Objective-C object pointer type, which is different from
a pointer type, despite being syntactically similar.

Given
  int *a;

  @interface Foo
  @end
  Foo *f;
pointerType()
  matches "Foo *f", but does not match "int *a".
Matcher<Type>parenTypeMatcher<ParenType>...
Matches ParenType nodes.

Given
  int (*ptr_to_array)[4];
  int *array_of_ptrs[4];

varDecl(hasType(pointsTo(parenType()))) matches ptr_to_array but not
array_of_ptrs.
Matcher<Type>pointerTypeMatcher<PointerType>...
Matches pointer types, but does not match Objective-C object pointer
types.

Given
  int *a;
  int &b = *a;
  int c = 5;

  @interface Foo
  @end
  Foo *f;
pointerType()
  matches "int *a", but does not match "Foo *f".
Matcher<Type>rValueReferenceTypeMatcher<RValueReferenceType>...
Matches rvalue reference types.

Given:
  int *a;
  int &b = *a;
  int &&c = 1;
  auto &d = b;
  auto &&e = c;
  auto &&f = 2;
  int g = 5;

rValueReferenceType() matches the types of c and f. e is not
matched as it is deduced to int& by reference collapsing rules.
Matcher<Type>recordTypeMatcher<RecordType>...
Matches record types (e.g. structs, classes).

Given
  class C {};
  struct S {};

  C c;
  S s;

recordType() matches the type of the variable declarations of both c
and s.
Matcher<Type>referenceTypeMatcher<ReferenceType>...
Matches both lvalue and rvalue reference types.

Given
  int *a;
  int &b = *a;
  int &&c = 1;
  auto &d = b;
  auto &&e = c;
  auto &&f = 2;
  int g = 5;

referenceType() matches the types of b, c, d, e, and f.
Matcher<Type>substTemplateTypeParmTypeMatcher<SubstTemplateTypeParmType>...
Matches types that represent the result of substituting a type for a
template type parameter.

Given
  template <typename T>
  void F(T t) {
    int i = 1 + t;
  }

substTemplateTypeParmType() matches the type of 't' but not '1'
Matcher<Type>tagTypeMatcher<TagType>...
Matches tag types (record and enum types).

Given
  enum E {};
  class C {};

  E e;
  C c;

tagType() matches the type of the variable declarations of both e
and c.
Matcher<Type>templateSpecializationTypeMatcher<TemplateSpecializationType>...
Matches template specialization types.

Given
  template <typename T>
  class C { };

  template class C<int>;  // A
  C<char> var;            // B

templateSpecializationType() matches the type of the explicit
instantiation in A and the type of the variable declaration in B.
Matcher<Type>templateTypeParmTypeMatcher<TemplateTypeParmType>...
Matches template type parameter types.

Example matches T, but not int.
    (matcher = templateTypeParmType())
  template <typename T> void f(int i);
Matcher<Type>typeMatcher<Type>...
Matches Types in the clang AST.
Matcher<Type>typedefTypeMatcher<TypedefType>...
Matches typedef types.

Given
  typedef int X;
typedefType()
  matches "typedef int X"
Matcher<Type>unaryTransformTypeMatcher<UnaryTransformType>...
Matches types nodes representing unary type transformations.

Given:
  typedef __underlying_type(T) type;
unaryTransformType()
  matches "__underlying_type(T)"
Matcher<Type>variableArrayTypeMatcher<VariableArrayType>...
Matches C arrays with a specified size that is not an
integer-constant-expression.

Given
  void f() {
    int a[] = { 2, 3 }
    int b[42];
    int c[a[0]];
  }
variableArrayType()
  matches "int c[a[0]]"

Narrowing Matchers

Narrowing matchers match certain attributes on the current node, thus narrowing down the set of nodes of the current type to match on.

There are special logical narrowing matchers (allOf, anyOf, anything and unless) which allow users to create more powerful match expressions.

Return typeNameParameters
Matcher<*>allOfMatcher<*>, ..., Matcher<*>
Matches if all given matchers match.

Usable as: Any Matcher
Matcher<*>anyOfMatcher<*>, ..., Matcher<*>
Matches if any of the given matchers matches.

Usable as: Any Matcher
Matcher<*>anything
Matches any node.

Useful when another matcher requires a child matcher, but there's no
additional constraint. This will often be used with an explicit conversion
to an internal::Matcher<> type such as TypeMatcher.

Example: DeclarationMatcher(anything()) matches all declarations, e.g.,
"int* p" and "void f()" in
  int* p;
  void f();

Usable as: Any Matcher
Matcher<*>unlessMatcher<*>
Matches if the provided matcher does not match.

Example matches Y (matcher = cxxRecordDecl(unless(hasName("X"))))
  class X {};
  class Y {};

Usable as: Any Matcher
Matcher<BinaryOperator>hasOperatorNamestd::string Name
Matches the operator Name of operator expressions (binary or
unary).

Example matches a || b (matcher = binaryOperator(hasOperatorName("||")))
  !(a || b)
Matcher<BinaryOperator>isAssignmentOperator
Matches all kinds of assignment operators.

Example 1: matches a += b (matcher = binaryOperator(isAssignmentOperator()))
  if (a == b)
    a += b;

Example 2: matches s1 = s2
           (matcher = cxxOperatorCallExpr(isAssignmentOperator()))
  struct S { S& operator=(const S&); };
  void x() { S s1, s2; s1 = s2; })
Matcher<CXXBoolLiteralExpr>equalsbool Value
Matcher<CXXBoolLiteralExpr>equalsconst ValueT Value
Matches literals that are equal to the given value of type ValueT.

Given
  f('false, 3.14, 42);
characterLiteral(equals(0))
  matches 'cxxBoolLiteral(equals(false)) and cxxBoolLiteral(equals(0))
  match false
floatLiteral(equals(3.14)) and floatLiteral(equals(314e-2))
  match 3.14
integerLiteral(equals(42))
  matches 42

Note that you cannot directly match a negative numeric literal because the
minus sign is not part of the literal: It is a unary operator whose operand
is the positive numeric literal. Instead, you must use a unaryOperator()
matcher to match the minus sign:

unaryOperator(hasOperatorName("-"),
              hasUnaryOperand(integerLiteral(equals(13))))

Usable as: Matcher<CharacterLiteral>, Matcher<CXXBoolLiteralExpr>,
           Matcher<FloatingLiteral>, Matcher<IntegerLiteral>
Matcher<CXXBoolLiteralExpr>equalsdouble Value
Matcher<CXXBoolLiteralExpr>equalsunsigned Value
Matcher<CXXCatchStmt>isCatchAll
Matches a C++ catch statement that has a catch-all handler.

Given
  try {
    // ...
  } catch (int) {
    // ...
  } catch (...) {
    // ...
  }
cxxCatchStmt(isCatchAll()) matches catch(...) but not catch(int).
Matcher<CXXConstructExpr>argumentCountIsunsigned N
Checks that a call expression or a constructor call expression has
a specific number of arguments (including absent default arguments).

Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2)))
  void f(int x, int y);
  f(0, 0);
Matcher<CXXConstructExpr>isListInitialization
Matches a constructor call expression which uses list initialization.
Matcher<CXXConstructExpr>requiresZeroInitialization
Matches a constructor call expression which requires
zero initialization.

Given
void foo() {
  struct point { double x; double y; };
  point pt[2] = { { 1.0, 2.0 } };
}
initListExpr(has(cxxConstructExpr(requiresZeroInitialization()))
will match the implicit array filler for pt[1].
Matcher<CXXConstructorDecl>isCopyConstructor
Matches constructor declarations that are copy constructors.

Given
  struct S {
    S(); // #1
    S(const S &); // #2
    S(S &&); // #3
  };
cxxConstructorDecl(isCopyConstructor()) will match #2, but not #1 or #3.
Matcher<CXXConstructorDecl>isDefaultConstructor
Matches constructor declarations that are default constructors.

Given
  struct S {
    S(); // #1
    S(const S &); // #2
    S(S &&); // #3
  };
cxxConstructorDecl(isDefaultConstructor()) will match #1, but not #2 or #3.
Matcher<CXXConstructorDecl>isDelegatingConstructor
Matches constructors that delegate to another constructor.

Given
  struct S {
    S(); // #1
    S(int) {} // #2
    S(S &&) : S() {} // #3
  };
  S::S() : S(0) {} // #4
cxxConstructorDecl(isDelegatingConstructor()) will match #3 and #4, but not
#1 or #2.
Matcher<CXXConstructorDecl>isExplicit
Matches constructor, conversion function, and deduction guide declarations
that have an explicit specifier if this explicit specifier is resolved to
true.

Given
  template<bool b>
  struct S {
    S(int); // #1
    explicit S(double); // #2
    operator int(); // #3
    explicit operator bool(); // #4
    explicit(false) S(bool) // # 7
    explicit(true) S(char) // # 8
    explicit(b) S(S) // # 9
  };
  S(int) -> S<true> // #5
  explicit S(double) -> S<false> // #6
cxxConstructorDecl(isExplicit()) will match #2 and #8, but not #1, #7 or #9.
cxxConversionDecl(isExplicit()) will match #4, but not #3.
cxxDeductionGuideDecl(isExplicit()) will match #6, but not #5.
Matcher<CXXConstructorDecl>isMoveConstructor
Matches constructor declarations that are move constructors.

Given
  struct S {
    S(); // #1
    S(const S &); // #2
    S(S &&); // #3
  };
cxxConstructorDecl(isMoveConstructor()) will match #3, but not #1 or #2.
Matcher<CXXConversionDecl>isExplicit
Matches constructor, conversion function, and deduction guide declarations
that have an explicit specifier if this explicit specifier is resolved to
true.

Given
  template<bool b>
  struct S {
    S(int); // #1
    explicit S(double); // #2
    operator int(); // #3
    explicit operator bool(); // #4
    explicit(false) S(bool) // # 7
    explicit(true) S(char) // # 8
    explicit(b) S(S) // # 9
  };
  S(int) -> S<true> // #5
  explicit S(double) -> S<false> // #6
cxxConstructorDecl(isExplicit()) will match #2 and #8, but not #1, #7 or #9.
cxxConversionDecl(isExplicit()) will match #4, but not #3.
cxxDeductionGuideDecl(isExplicit()) will match #6, but not #5.
Matcher<CXXCtorInitializer>isBaseInitializer
Matches a constructor initializer if it is initializing a base, as
opposed to a member.

Given
  struct B {};
  struct D : B {
    int I;
    D(int i) : I(i) {}
  };
  struct E : B {
    E() : B() {}
  };
cxxConstructorDecl(hasAnyConstructorInitializer(isBaseInitializer()))
  will match E(), but not match D(int).
Matcher<CXXCtorInitializer>isMemberInitializer
Matches a constructor initializer if it is initializing a member, as
opposed to a base.

Given
  struct B {};
  struct D : B {
    int I;
    D(int i) : I(i) {}
  };
  struct E : B {
    E() : B() {}
  };
cxxConstructorDecl(hasAnyConstructorInitializer(isMemberInitializer()))
  will match D(int), but not match E().
Matcher<CXXCtorInitializer>isWritten
Matches a constructor initializer if it is explicitly written in
code (as opposed to implicitly added by the compiler).

Given
  struct Foo {
    Foo() { }
    Foo(int) : foo_("A") { }
    string foo_;
  };
cxxConstructorDecl(hasAnyConstructorInitializer(isWritten()))
  will match Foo(int), but not Foo()
Matcher<CXXDeductionGuideDecl>isExplicit
Matches constructor, conversion function, and deduction guide declarations
that have an explicit specifier if this explicit specifier is resolved to
true.

Given
  template<bool b>
  struct S {
    S(int); // #1
    explicit S(double); // #2
    operator int(); // #3
    explicit operator bool(); // #4
    explicit(false) S(bool) // # 7
    explicit(true) S(char) // # 8
    explicit(b) S(S) // # 9
  };
  S(int) -> S<true> // #5
  explicit S(double) -> S<false> // #6
cxxConstructorDecl(isExplicit()) will match #2 and #8, but not #1, #7 or #9.
cxxConversionDecl(isExplicit()) will match #4, but not #3.
cxxDeductionGuideDecl(isExplicit()) will match #6, but not #5.
Matcher<CXXDependentScopeMemberExpr>isArrow
Matches member expressions that are called with '->' as opposed
to '.'.

Member calls on the implicit this pointer match as called with '->'.

Given
  class Y {
    void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; }
    template <class T> void f() { this->f<T>(); f<T>(); }
    int a;
    static int b;
  };
  template <class T>
  class Z {
    void x() { this->m; }
  };
memberExpr(isArrow())
  matches this->x, x, y.x, a, this->b
cxxDependentScopeMemberExpr(isArrow())
  matches this->m
unresolvedMemberExpr(isArrow())
  matches this->f<T>, f<T>
Matcher<CXXMethodDecl>isConst
Matches if the given method declaration is const.

Given
struct A {
  void foo() const;
  void bar();
};

cxxMethodDecl(isConst()) matches A::foo() but not A::bar()
Matcher<CXXMethodDecl>isCopyAssignmentOperator
Matches if the given method declaration declares a copy assignment
operator.

Given
struct A {
  A &operator=(const A &);
  A &operator=(A &&);
};

cxxMethodDecl(isCopyAssignmentOperator()) matches the first method but not
the second one.
Matcher<CXXMethodDecl>isFinal
Matches if the given method or class declaration is final.

Given:
  class A final {};

  struct B {
    virtual void f();
  };

  struct C : B {
    void f() final;
  };
matches A and C::f, but not B, C, or B::f
Matcher<CXXMethodDecl>isMoveAssignmentOperator
Matches if the given method declaration declares a move assignment
operator.

Given
struct A {
  A &operator=(const A &);
  A &operator=(A &&);
};

cxxMethodDecl(isMoveAssignmentOperator()) matches the second method but not
the first one.
Matcher<CXXMethodDecl>isOverride
Matches if the given method declaration overrides another method.

Given
  class A {
   public:
    virtual void x();
  };
  class B : public A {
   public:
    virtual void x();
  };
  matches B::x
Matcher<CXXMethodDecl>isPure
Matches if the given method declaration is pure.

Given
  class A {
   public:
    virtual void x() = 0;
  };
  matches A::x
Matcher<CXXMethodDecl>isUserProvided
Matches method declarations that are user-provided.

Given
  struct S {
    S(); // #1
    S(const S &) = default; // #2
    S(S &&) = delete; // #3
  };
cxxConstructorDecl(isUserProvided()) will match #1, but not #2 or #3.
Matcher<CXXMethodDecl>isVirtual
Matches if the given method declaration is virtual.

Given
  class A {
   public:
    virtual void x();
  };
  matches A::x
Matcher<CXXMethodDecl>isVirtualAsWritten
Matches if the given method declaration has an explicit "virtual".

Given
  class A {
   public:
    virtual void x();
  };
  class B : public A {
   public:
    void x();
  };
  matches A::x but not B::x
Matcher<CXXNewExpr>isArray
Matches array new expressions.

Given:
  MyClass *p1 = new MyClass[10];
cxxNewExpr(isArray())
  matches the expression 'new MyClass[10]'.
Matcher<CXXOperatorCallExpr>hasOverloadedOperatorNameStringRef Name
Matches overloaded operator names.

Matches overloaded operator names specified in strings without the
"operator" prefix: e.g. "<<".

Given:
  class A { int operator*(); };
  const A &operator<<(const A &a, const A &b);
  A a;
  a << a;   // <-- This matches

cxxOperatorCallExpr(hasOverloadedOperatorName("<<"))) matches the
specified line and
cxxRecordDecl(hasMethod(hasOverloadedOperatorName("*")))
matches the declaration of A.

Usable as: Matcher<CXXOperatorCallExpr>, Matcher<FunctionDecl>
Matcher<CXXOperatorCallExpr>isAssignmentOperator
Matches all kinds of assignment operators.

Example 1: matches a += b (matcher = binaryOperator(isAssignmentOperator()))
  if (a == b)
    a += b;

Example 2: matches s1 = s2
           (matcher = cxxOperatorCallExpr(isAssignmentOperator()))
  struct S { S& operator=(const S&); };
  void x() { S s1, s2; s1 = s2; })
Matcher<CXXRecordDecl>hasDefinition
Matches a class declaration that is defined.

Example matches x (matcher = cxxRecordDecl(hasDefinition()))
class x {};
class y;
Matcher<CXXRecordDecl>isDerivedFromstd::string BaseName
Overloaded method as shortcut for isDerivedFrom(hasName(...)).
Matcher<CXXRecordDecl>isExplicitTemplateSpecialization
Matches explicit template specializations of function, class, or
static member variable template instantiations.

Given
  template<typename T> void A(T t) { }
  template<> void A(int N) { }
functionDecl(isExplicitTemplateSpecialization())
  matches the specialization A<int>().

Usable as: Matcher<FunctionDecl>, Matcher<VarDecl>, Matcher<CXXRecordDecl>
Matcher<CXXRecordDecl>isFinal
Matches if the given method or class declaration is final.

Given:
  class A final {};

  struct B {
    virtual void f();
  };

  struct C : B {
    void f() final;
  };
matches A and C::f, but not B, C, or B::f
Matcher<CXXRecordDecl>isLambda
Matches the generated class of lambda expressions.

Given:
  auto x = []{};

cxxRecordDecl(isLambda()) matches the implicit class declaration of
decltype(x)
Matcher<CXXRecordDecl>isSameOrDerivedFromstd::string BaseName
Overloaded method as shortcut for
isSameOrDerivedFrom(hasName(...)).
Matcher<CXXRecordDecl>isTemplateInstantiation
Matches template instantiations of function, class, or static
member variable template instantiations.

Given
  template <typename T> class X {}; class A {}; X<A> x;
or
  template <typename T> class X {}; class A {}; template class X<A>;
or
  template <typename T> class X {}; class A {}; extern template class X<A>;
cxxRecordDecl(hasName("::X"), isTemplateInstantiation())
  matches the template instantiation of X<A>.

But given
  template <typename T>  class X {}; class A {};
  template <> class X<A> {}; X<A> x;
cxxRecordDecl(hasName("::X"), isTemplateInstantiation())
  does not match, as X<A> is an explicit template specialization.

Usable as: Matcher<FunctionDecl>, Matcher<VarDecl>, Matcher<CXXRecordDecl>
Matcher<CallExpr>argumentCountIsunsigned N
Checks that a call expression or a constructor call expression has
a specific number of arguments (including absent default arguments).

Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2)))
  void f(int x, int y);
  f(0, 0);
Matcher<CallExpr>usesADL
Matches call expressions which were resolved using ADL.

Example matches y(x) but not y(42) or NS::y(x).
  namespace NS {
    struct X {};
    void y(X);
  }

  void y(...);

  void test() {
    NS::X x;
    y(x); // Matches
    NS::y(x); // Doesn't match
    y(42); // Doesn't match
    using NS::y;
    y(x); // Found by both unqualified lookup and ADL, doesn't match
   }
Matcher<CastExpr>hasCastKindCastKind Kind
Matches casts that has a given cast kind.

Example: matches the implicit cast around 0
(matcher = castExpr(hasCastKind(CK_NullToPointer)))
  int *p = 0;

If the matcher is use from clang-query, CastKind parameter
should be passed as a quoted string. e.g., ofKind("CK_NullToPointer").
Matcher<CharacterLiteral>equalsbool Value
Matcher<CharacterLiteral>equalsconst ValueT Value
Matches literals that are equal to the given value of type ValueT.

Given
  f('false, 3.14, 42);
characterLiteral(equals(0))
  matches 'cxxBoolLiteral(equals(false)) and cxxBoolLiteral(equals(0))
  match false
floatLiteral(equals(3.14)) and floatLiteral(equals(314e-2))
  match 3.14
integerLiteral(equals(42))
  matches 42

Note that you cannot directly match a negative numeric literal because the
minus sign is not part of the literal: It is a unary operator whose operand
is the positive numeric literal. Instead, you must use a unaryOperator()
matcher to match the minus sign:

unaryOperator(hasOperatorName("-"),
              hasUnaryOperand(integerLiteral(equals(13))))

Usable as: Matcher<CharacterLiteral>, Matcher<CXXBoolLiteralExpr>,
           Matcher<FloatingLiteral>, Matcher<IntegerLiteral>
Matcher<CharacterLiteral>equalsdouble Value
Matcher<CharacterLiteral>equalsunsigned Value
Matcher<ClassTemplateSpecializationDecl>templateArgumentCountIsunsigned N
Matches if the number of template arguments equals N.

Given
  template<typename T> struct C {};
  C<int> c;
classTemplateSpecializationDecl(templateArgumentCountIs(1))
  matches C<int>.
Matcher<CompoundStmt>statementCountIsunsigned N
Checks that a compound statement contains a specific number of
child statements.

Example: Given
  { for (;;) {} }
compoundStmt(statementCountIs(0)))
  matches '{}'
  but does not match the outer compound statement.
Matcher<ConstantArrayType>hasSizeunsigned N
Matches nodes that have the specified size.

Given
  int a[42];
  int b[2 * 21];
  int c[41], d[43];
  char *s = "abcd";
  wchar_t *ws = L"abcd";
  char *w = "a";
constantArrayType(hasSize(42))
  matches "int a[42]" and "int b[2 * 21]"
stringLiteral(hasSize(4))
  matches "abcd", L"abcd"
Matcher<DeclStmt>declCountIsunsigned N
Matches declaration statements that contain a specific number of
declarations.

Example: Given
  int a, b;
  int c;
  int d = 2, e;
declCountIs(2)
  matches 'int a, b;' and 'int d = 2, e;', but not 'int c;'.
Matcher<Decl>equalsBoundNodestd::string ID
Matches if a node equals a previously bound node.

Matches a node if it equals the node previously bound to ID.

Given
  class X { int a; int b; };
cxxRecordDecl(
    has(fieldDecl(hasName("a"), hasType(type().bind("t")))),
    has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t"))))))
  matches the class X, as a and b have the same type.

Note that when multiple matches are involved via forEach* matchers,
equalsBoundNodes acts as a filter.
For example:
compoundStmt(
    forEachDescendant(varDecl().bind("d")),
    forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d"))))))
will trigger a match for each combination of variable declaration
and reference to that variable declaration within a compound statement.
Matcher<Decl>equalsNodeconst Decl* Other
Matches if a node equals another node.

Decl has pointer identity in the AST.
Matcher<Decl>hasAttrattr::Kind AttrKind
Matches declaration that has a given attribute.

Given
  __attribute__((device)) void f() { ... }
decl(hasAttr(clang::attr::CUDADevice)) matches the function declaration of
f. If the matcher is used from clang-query, attr::Kind parameter should be
passed as a quoted string. e.g., hasAttr("attr::CUDADevice").
Matcher<Decl>isExpansionInFileMatchingstd::string RegExp
Matches AST nodes that were expanded within files whose name is
partially matching a given regex.

Example matches Y but not X
    (matcher = cxxRecordDecl(isExpansionInFileMatching("AST.*"))
  #include "ASTMatcher.h"
  class X {};
ASTMatcher.h:
  class Y {};

Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
Matcher<Decl>isExpansionInMainFile
Matches AST nodes that were expanded within the main-file.

Example matches X but not Y
  (matcher = cxxRecordDecl(isExpansionInMainFile())
  #include <Y.h>
  class X {};
Y.h:
  class Y {};

Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
Matcher<Decl>isExpansionInSystemHeader
Matches AST nodes that were expanded within system-header-files.

Example matches Y but not X
    (matcher = cxxRecordDecl(isExpansionInSystemHeader())
  #include <SystemHeader.h>
  class X {};
SystemHeader.h:
  class Y {};

Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
Matcher<Decl>isImplicit
Matches a declaration that has been implicitly added
by the compiler (eg. implicit default/copy constructors).
Matcher<Decl>isInStdNamespace
Matches declarations in the namespace `std`, but not in nested namespaces.

Given
  class vector {};
  namespace foo {
    class vector {};
    namespace std {
      class vector {};
    }
  }
  namespace std {
    inline namespace __1 {
      class vector {}; // #1
      namespace experimental {
        class vector {};
      }
    }
  }
cxxRecordDecl(hasName("vector"), isInStdNamespace()) will match only #1.
Matcher<Decl>isPrivate
Matches private C++ declarations.

Given
  class C {
  public:    int a;
  protected: int b;
  private:   int c;
  };
fieldDecl(isPrivate())
  matches 'int c;'
Matcher<Decl>isProtected
Matches protected C++ declarations.

Given
  class C {
  public:    int a;
  protected: int b;
  private:   int c;
  };
fieldDecl(isProtected())
  matches 'int b;'
Matcher<Decl>isPublic
Matches public C++ declarations.

Given
  class C {
  public:    int a;
  protected: int b;
  private:   int c;
  };
fieldDecl(isPublic())
  matches 'int a;'
Matcher<DesignatedInitExpr>designatorCountIsunsigned N
Matches designated initializer expressions that contain
a specific number of designators.

Example: Given
  point ptarray[10] = { [2].y = 1.0, [0].x = 1.0 };
  point ptarray2[10] = { [2].y = 1.0, [2].x = 0.0, [0].x = 1.0 };
designatorCountIs(2)
  matches '{ [2].y = 1.0, [0].x = 1.0 }',
  but not '{ [2].y = 1.0, [2].x = 0.0, [0].x = 1.0 }'.
Matcher<EnumDecl>isScoped
Matches C++11 scoped enum declaration.

Example matches Y (matcher = enumDecl(isScoped()))
enum X {};
enum class Y {};
Matcher<Expr>isInstantiationDependent
Matches expressions that are instantiation-dependent even if it is
neither type- nor value-dependent.

In the following example, the expression sizeof(sizeof(T() + T()))
is instantiation-dependent (since it involves a template parameter T),
but is neither type- nor value-dependent, since the type of the inner
sizeof is known (std::size_t) and therefore the size of the outer
sizeof is known.
  template<typename T>
  void f(T x, T y) { sizeof(sizeof(T() + T()); }
expr(isInstantiationDependent()) matches sizeof(sizeof(T() + T())
Matcher<Expr>isTypeDependent
Matches expressions that are type-dependent because the template type
is not yet instantiated.

For example, the expressions "x" and "x + y" are type-dependent in
the following code, but "y" is not type-dependent:
  template<typename T>
  void add(T x, int y) {
    x + y;
  }
expr(isTypeDependent()) matches x + y
Matcher<Expr>isValueDependent
Matches expression that are value-dependent because they contain a
non-type template parameter.

For example, the array bound of "Chars" in the following example is
value-dependent.
  template<int Size> int f() { return Size; }
expr(isValueDependent()) matches return Size
Matcher<FieldDecl>hasBitWidthunsigned Width
Matches non-static data members that are bit-fields of the specified
bit width.

Given
  class C {
    int a : 2;
    int b : 4;
    int c : 2;
  };
fieldDecl(hasBitWidth(2))
  matches 'int a;' and 'int c;' but not 'int b;'.
Matcher<FieldDecl>isBitField
Matches non-static data members that are bit-fields.

Given
  class C {
    int a : 2;
    int b;
  };
fieldDecl(isBitField())
  matches 'int a;' but not 'int b;'.
Matcher<FloatingLiteral>equalsconst ValueT Value
Matches literals that are equal to the given value of type ValueT.

Given
  f('false, 3.14, 42);
characterLiteral(equals(0))
  matches 'cxxBoolLiteral(equals(false)) and cxxBoolLiteral(equals(0))
  match false
floatLiteral(equals(3.14)) and floatLiteral(equals(314e-2))
  match 3.14
integerLiteral(equals(42))
  matches 42

Note that you cannot directly match a negative numeric literal because the
minus sign is not part of the literal: It is a unary operator whose operand
is the positive numeric literal. Instead, you must use a unaryOperator()
matcher to match the minus sign:

unaryOperator(hasOperatorName("-"),
              hasUnaryOperand(integerLiteral(equals(13))))

Usable as: Matcher<CharacterLiteral>, Matcher<CXXBoolLiteralExpr>,
           Matcher<FloatingLiteral>, Matcher<IntegerLiteral>
Matcher<FloatingLiteral>equalsdouble Value
Matcher<FunctionDecl>hasDynamicExceptionSpec
Matches functions that have a dynamic exception specification.

Given:
  void f();
  void g() noexcept;
  void h() noexcept(true);
  void i() noexcept(false);
  void j() throw();
  void k() throw(int);
  void l() throw(...);
functionDecl(hasDynamicExceptionSpec()) and
  functionProtoType(hasDynamicExceptionSpec())
  match the declarations of j, k, and l, but not f, g, h, or i.
Matcher<FunctionDecl>hasOverloadedOperatorNameStringRef Name
Matches overloaded operator names.

Matches overloaded operator names specified in strings without the
"operator" prefix: e.g. "<<".

Given:
  class A { int operator*(); };
  const A &operator<<(const A &a, const A &b);
  A a;
  a << a;   // <-- This matches

cxxOperatorCallExpr(hasOverloadedOperatorName("<<"))) matches the
specified line and
cxxRecordDecl(hasMethod(hasOverloadedOperatorName("*")))
matches the declaration of A.

Usable as: Matcher<CXXOperatorCallExpr>, Matcher<FunctionDecl>
Matcher<FunctionDecl>hasTrailingReturn
Matches a function declared with a trailing return type.

Example matches Y (matcher = functionDecl(hasTrailingReturn()))
int X() {}
auto Y() -> int {}
Matcher<FunctionDecl>isConstexpr
Matches constexpr variable and function declarations,
       and if constexpr.

Given:
  constexpr int foo = 42;
  constexpr int bar();
  void baz() { if constexpr(1 > 0) {} }
varDecl(isConstexpr())
  matches the declaration of foo.
functionDecl(isConstexpr())
  matches the declaration of bar.
ifStmt(isConstexpr())
  matches the if statement in baz.
Matcher<FunctionDecl>isDefaulted
Matches defaulted function declarations.

Given:
  class A { ~A(); };
  class B { ~B() = default; };
functionDecl(isDefaulted())
  matches the declaration of ~B, but not ~A.
Matcher<FunctionDecl>isDefinition
Matches if a declaration has a body attached.

Example matches A, va, fa
  class A {};
  class B;  // Doesn't match, as it has no body.
  int va;
  extern int vb;  // Doesn't match, as it doesn't define the variable.
  void fa() {}
  void fb();  // Doesn't match, as it has no body.
  @interface X
  - (void)ma; // Doesn't match, interface is declaration.
  @end
  @implementation X
  - (void)ma {}
  @end

Usable as: Matcher<TagDecl>, Matcher<VarDecl>, Matcher<FunctionDecl>,
  Matcher<ObjCMethodDecl>
Matcher<FunctionDecl>isDeleted
Matches deleted function declarations.

Given:
  void Func();
  void DeletedFunc() = delete;
functionDecl(isDeleted())
  matches the declaration of DeletedFunc, but not Func.
Matcher<FunctionDecl>isExplicitTemplateSpecialization
Matches explicit template specializations of function, class, or
static member variable template instantiations.

Given
  template<typename T> void A(T t) { }
  template<> void A(int N) { }
functionDecl(isExplicitTemplateSpecialization())
  matches the specialization A<int>().

Usable as: Matcher<FunctionDecl>, Matcher<VarDecl>, Matcher<CXXRecordDecl>
Matcher<FunctionDecl>isExternC
Matches extern "C" function or variable declarations.

Given:
  extern "C" void f() {}
  extern "C" { void g() {} }
  void h() {}
  extern "C" int x = 1;
  extern "C" int y = 2;
  int z = 3;
functionDecl(isExternC())
  matches the declaration of f and g, but not the declaration of h.
varDecl(isExternC())
  matches the declaration of x and y, but not the declaration of z.
Matcher<FunctionDecl>isInline
Matches function and namespace declarations that are marked with
the inline keyword.

Given
  inline void f();
  void g();
  namespace n {
  inline namespace m {}
  }
functionDecl(isInline()) will match ::f().
namespaceDecl(isInline()) will match n::m.
Matcher<FunctionDecl>isMain
Determines whether the function is "main", which is the entry point
into an executable program.
Matcher<FunctionDecl>isNoReturn
Matches FunctionDecls that have a noreturn attribute.

Given
  void nope();
  [[noreturn]] void a();
  __attribute__((noreturn)) void b();
  struct c { [[noreturn]] c(); };
functionDecl(isNoReturn())
  matches all of those except
  void nope();
Matcher<FunctionDecl>isNoThrow
Matches functions that have a non-throwing exception specification.

Given:
  void f();
  void g() noexcept;
  void h() throw();
  void i() throw(int);
  void j() noexcept(false);
functionDecl(isNoThrow()) and functionProtoType(isNoThrow())
  match the declarations of g, and h, but not f, i or j.
Matcher<FunctionDecl>isStaticStorageClass
Matches variable/function declarations that have "static" storage
class specifier ("static" keyword) written in the source.

Given:
  static void f() {}
  static int i = 0;
  extern int j;
  int k;
functionDecl(isStaticStorageClass())
  matches the function declaration f.
varDecl(isStaticStorageClass())
  matches the variable declaration i.
Matcher<FunctionDecl>isTemplateInstantiation
Matches template instantiations of function, class, or static
member variable template instantiations.

Given
  template <typename T> class X {}; class A {}; X<A> x;
or
  template <typename T> class X {}; class A {}; template class X<A>;
or
  template <typename T> class X {}; class A {}; extern template class X<A>;
cxxRecordDecl(hasName("::X"), isTemplateInstantiation())
  matches the template instantiation of X<A>.

But given
  template <typename T>  class X {}; class A {};
  template <> class X<A> {}; X<A> x;
cxxRecordDecl(hasName("::X"), isTemplateInstantiation())
  does not match, as X<A> is an explicit template specialization.

Usable as: Matcher<FunctionDecl>, Matcher<VarDecl>, Matcher<CXXRecordDecl>
Matcher<FunctionDecl>isVariadic
Matches if a function declaration is variadic.

Example matches f, but not g or h. The function i will not match, even when
compiled in C mode.
  void f(...);
  void g(int);
  template <typename... Ts> void h(Ts...);
  void i();
Matcher<FunctionDecl>parameterCountIsunsigned N
Matches FunctionDecls and FunctionProtoTypes that have a
specific parameter count.

Given
  void f(int i) {}
  void g(int i, int j) {}
  void h(int i, int j);
  void j(int i);
  void k(int x, int y, int z, ...);
functionDecl(parameterCountIs(2))
  matches g and h
functionProtoType(parameterCountIs(2))
  matches g and h
functionProtoType(parameterCountIs(3))
  matches k
Matcher<FunctionProtoType>hasDynamicExceptionSpec
Matches functions that have a dynamic exception specification.

Given:
  void f();
  void g() noexcept;
  void h() noexcept(true);
  void i() noexcept(false);
  void j() throw();
  void k() throw(int);
  void l() throw(...);
functionDecl(hasDynamicExceptionSpec()) and
  functionProtoType(hasDynamicExceptionSpec())
  match the declarations of j, k, and l, but not f, g, h, or i.
Matcher<FunctionProtoType>isNoThrow
Matches functions that have a non-throwing exception specification.

Given:
  void f();
  void g() noexcept;
  void h() throw();
  void i() throw(int);
  void j() noexcept(false);
functionDecl(isNoThrow()) and functionProtoType(isNoThrow())
  match the declarations of g, and h, but not f, i or j.
Matcher<FunctionProtoType>parameterCountIsunsigned N
Matches FunctionDecls and FunctionProtoTypes that have a
specific parameter count.

Given
  void f(int i) {}
  void g(int i, int j) {}
  void h(int i, int j);
  void j(int i);
  void k(int x, int y, int z, ...);
functionDecl(parameterCountIs(2))
  matches g and h
functionProtoType(parameterCountIs(2))
  matches g and h
functionProtoType(parameterCountIs(3))
  matches k
Matcher<IfStmt>isConstexpr
Matches constexpr variable and function declarations,
       and if constexpr.

Given:
  constexpr int foo = 42;
  constexpr int bar();
  void baz() { if constexpr(1 > 0) {} }
varDecl(isConstexpr())
  matches the declaration of foo.
functionDecl(isConstexpr())
  matches the declaration of bar.
ifStmt(isConstexpr())
  matches the if statement in baz.
Matcher<IntegerLiteral>equalsbool Value
Matcher<IntegerLiteral>equalsconst ValueT Value
Matches literals that are equal to the given value of type ValueT.

Given
  f('false, 3.14, 42);
characterLiteral(equals(0))
  matches 'cxxBoolLiteral(equals(false)) and cxxBoolLiteral(equals(0))
  match false
floatLiteral(equals(3.14)) and floatLiteral(equals(314e-2))
  match 3.14
integerLiteral(equals(42))
  matches 42

Note that you cannot directly match a negative numeric literal because the
minus sign is not part of the literal: It is a unary operator whose operand
is the positive numeric literal. Instead, you must use a unaryOperator()
matcher to match the minus sign:

unaryOperator(hasOperatorName("-"),
              hasUnaryOperand(integerLiteral(equals(13))))

Usable as: Matcher<CharacterLiteral>, Matcher<CXXBoolLiteralExpr>,
           Matcher<FloatingLiteral>, Matcher<IntegerLiteral>
Matcher<IntegerLiteral>equalsdouble Value
Matcher<IntegerLiteral>equalsunsigned Value
Matcher<MemberExpr>isArrow
Matches member expressions that are called with '->' as opposed
to '.'.

Member calls on the implicit this pointer match as called with '->'.

Given
  class Y {
    void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; }
    template <class T> void f() { this->f<T>(); f<T>(); }
    int a;
    static int b;
  };
  template <class T>
  class Z {
    void x() { this->m; }
  };
memberExpr(isArrow())
  matches this->x, x, y.x, a, this->b
cxxDependentScopeMemberExpr(isArrow())
  matches this->m
unresolvedMemberExpr(isArrow())
  matches this->f<T>, f<T>
Matcher<NamedDecl>hasExternalFormalLinkage
Matches a declaration that has external formal linkage.

Example matches only z (matcher = varDecl(hasExternalFormalLinkage()))
void f() {
  int x;
  static int y;
}
int z;

Example matches f() because it has external formal linkage despite being
unique to the translation unit as though it has internal likage
(matcher = functionDecl(hasExternalFormalLinkage()))

namespace {
void f() {}
}
Matcher<NamedDecl>hasNameconst std::string Name
Matches NamedDecl nodes that have the specified name.

Supports specifying enclosing namespaces or classes by prefixing the name
with '<enclosing>::'.
Does not match typedefs of an underlying type with the given name.

Example matches X (Name == "X")
  class X;

Example matches X (Name is one of "::a::b::X", "a::b::X", "b::X", "X")
  namespace a { namespace b { class X; } }
Matcher<NamedDecl>matchesNamestd::string RegExp
Matches NamedDecl nodes whose fully qualified names contain
a substring matched by the given RegExp.

Supports specifying enclosing namespaces or classes by
prefixing the name with '<enclosing>::'.  Does not match typedefs
of an underlying type with the given name.

Example matches X (regexp == "::X")
  class X;

Example matches X (regexp is one of "::X", "^foo::.*X", among others)
  namespace foo { namespace bar { class X; } }
Matcher<NamespaceDecl>isAnonymous
Matches anonymous namespace declarations.

Given
  namespace n {
  namespace {} // #1
  }
namespaceDecl(isAnonymous()) will match #1 but not ::n.
Matcher<NamespaceDecl>isInline
Matches function and namespace declarations that are marked with
the inline keyword.

Given
  inline void f();
  void g();
  namespace n {
  inline namespace m {}
  }
functionDecl(isInline()) will match ::f().
namespaceDecl(isInline()) will match n::m.
Matcher<OMPDefaultClause>isNoneKind
Matches if the OpenMP ``default`` clause has ``none`` kind specified.

Given

  #pragma omp parallel
  #pragma omp parallel default(none)
  #pragma omp parallel default(shared)

``ompDefaultClause(isNoneKind())`` matches only ``default(none)``.
Matcher<OMPDefaultClause>isSharedKind
Matches if the OpenMP ``default`` clause has ``shared`` kind specified.

Given

  #pragma omp parallel
  #pragma omp parallel default(none)
  #pragma omp parallel default(shared)

``ompDefaultClause(isSharedKind())`` matches only ``default(shared)``.
Matcher<OMPExecutableDirective>isAllowedToContainClauseKindOpenMPClauseKind CKind
Matches if the OpenMP directive is allowed to contain the specified OpenMP
clause kind.

Given

  #pragma omp parallel
  #pragma omp parallel for
  #pragma omp          for

`ompExecutableDirective(isAllowedToContainClause(OMPC_default))`` matches
``omp parallel`` and ``omp parallel for``.

If the matcher is use from clang-query, ``OpenMPClauseKind`` parameter
should be passed as a quoted string. e.g.,
``isAllowedToContainClauseKind("OMPC_default").``
Matcher<OMPExecutableDirective>isStandaloneDirective
Matches standalone OpenMP directives,
i.e., directives that can't have a structured block.

Given

  #pragma omp parallel
  {}
  #pragma omp taskyield

``ompExecutableDirective(isStandaloneDirective()))`` matches
``omp taskyield``.
Matcher<ObjCMessageExpr>argumentCountIsunsigned N
Checks that a call expression or a constructor call expression has
a specific number of arguments (including absent default arguments).

Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2)))
  void f(int x, int y);
  f(0, 0);
Matcher<ObjCMessageExpr>hasKeywordSelector
Matches when the selector is a keyword selector

objCMessageExpr(hasKeywordSelector()) matches the generated setFrame
message expression in

  UIWebView *webView = ...;
  CGRect bodyFrame = webView.frame;
  bodyFrame.size.height = self.bodyContentHeight;
  webView.frame = bodyFrame;
  //     ^---- matches here
Matcher<ObjCMessageExpr>hasNullSelector
Matches when the selector is the empty selector

Matches only when the selector of the objCMessageExpr is NULL. This may
represent an error condition in the tree!
Matcher<ObjCMessageExpr>hasSelectorstd::string BaseName
Matches when BaseName == Selector.getAsString()

 matcher = objCMessageExpr(hasSelector("loadHTMLString:baseURL:"));
 matches the outer message expr in the code below, but NOT the message
 invocation for self.bodyView.
    [self.bodyView loadHTMLString:html baseURL:NULL];
Matcher<ObjCMessageExpr>hasUnarySelector
Matches when the selector is a Unary Selector

 matcher = objCMessageExpr(matchesSelector(hasUnarySelector());
 matches self.bodyView in the code below, but NOT the outer message
 invocation of "loadHTMLString:baseURL:".
    [self.bodyView loadHTMLString:html baseURL:NULL];
Matcher<ObjCMessageExpr>isClassMessage
Returns true when the Objective-C message is sent to a class.

Example
matcher = objcMessageExpr(isClassMessage())
matches
  [NSString stringWithFormat:@"format"];
but not
  NSString *x = @"hello";
  [x containsString:@"h"];
Matcher<ObjCMessageExpr>isInstanceMessage
Returns true when the Objective-C message is sent to an instance.

Example
matcher = objcMessageExpr(isInstanceMessage())
matches
  NSString *x = @"hello";
  [x containsString:@"h"];
but not
  [NSString stringWithFormat:@"format"];
Matcher<ObjCMessageExpr>matchesSelectorstd::string RegExp
Matches ObjC selectors whose name contains
a substring matched by the given RegExp.
 matcher = objCMessageExpr(matchesSelector("loadHTMLStringmatches the outer message expr in the code below, but NOT the message
 invocation for self.bodyView.
    [self.bodyView loadHTMLString:html baseURL:NULL];
Matcher<ObjCMessageExpr>numSelectorArgsunsigned N
Matches when the selector has the specified number of arguments

 matcher = objCMessageExpr(numSelectorArgs(0));
 matches self.bodyView in the code below

 matcher = objCMessageExpr(numSelectorArgs(2));
 matches the invocation of "loadHTMLString:baseURL:" but not that
 of self.bodyView
    [self.bodyView loadHTMLString:html baseURL:NULL];
Matcher<ObjCMethodDecl>isClassMethod
Returns true when the Objective-C method declaration is a class method.

Example
matcher = objcMethodDecl(isClassMethod())
matches
@interface I + (void)foo; @end
but not
@interface I - (void)bar; @end
Matcher<ObjCMethodDecl>isDefinition
Matches if a declaration has a body attached.

E