10908 lines · html
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"2 "http://www.w3.org/TR/html4/strict.dtd">3<html>4<head>5<title>AST Matcher Reference</title>6<link type="text/css" rel="stylesheet" href="../menu.css" />7<link type="text/css" rel="stylesheet" href="../content.css" />8<style type="text/css">9td {10 padding: .33em;11}12td.doc {13 display: none;14 border-bottom: 1px solid black;15}16td.name:hover {17 color: blue;18 cursor: pointer;19}20span.mono { font-family: monospace; }21 22.traverse_compare, .traverse_compare td, .traverse_compare th {23 border: 1px solid black;24 border-collapse: collapse;25}26</style>27<script type="text/javascript">28function toggle(id) {29 if (!id) return;30 row = document.getElementById(id);31 if (row.style.display != 'table-cell')32 row.style.display = 'table-cell';33 else34 row.style.display = 'none';35}36</script>37</head>38<body onLoad="toggle(location.hash.substring(1, location.hash.length - 6))">39 40<!--#include virtual="../menu.html.incl"-->41 42<div id="content">43 44<h1>AST Matcher Reference</h1>45 46<p>This document shows all currently implemented matchers. The matchers are grouped47by category and node type they match. You can click on matcher names to show the48matcher's source documentation.</p>49 50<p>There are three different basic categories of matchers:51<ul>52<li><a href="#decl-matchers">Node Matchers:</a> Matchers that match a specific type of AST node.</li>53<li><a href="#narrowing-matchers">Narrowing Matchers:</a> Matchers that match attributes on AST nodes.</li>54<li><a href="#traversal-matchers">Traversal Matchers:</a> Matchers that allow traversal between AST nodes.</li>55</ul>56</p>57 58<p>Within each category the matchers are ordered by node type they match on.59Note that if a matcher can match multiple node types, it will appear60multiple times. This means that by searching for Matcher<Stmt> you can61find all matchers that can be used to match on Stmt nodes.</p>62 63<p>The exception to that rule are matchers that can match on any node. Those64are marked with a * and are listed in the beginning of each category.</p>65 66<p>Note that the categorization of matchers is a great help when you combine67them into matcher expressions. You will usually want to form matcher expressions68that read like english sentences by alternating between node matchers and69narrowing or traversal matchers, like this:70<pre>71recordDecl(hasDescendant(72 ifStmt(hasTrueExpression(73 expr(hasDescendant(74 ifStmt()))))))75</pre>76</p>77 78<!-- ======================================================================= -->79<h2 id="traverse-mode">Traverse Mode</h2>80<!-- ======================================================================= -->81 82<p>The default mode of operation of AST Matchers visits all nodes in the AST,83even if they are not spelled in the source. This is84<span class="mono">AsIs</span> mode. This mode requires writing AST matchers85that explicitly traverse or ignore implicit nodes, such as parentheses86surrounding an expression or expressions with cleanups. These implicit87nodes are not always obvious from the syntax of the source code, and so this88mode requires careful consideration and testing to get the desired behavior89from an AST matcher.90</p>91 92<p>In addition, because template instantiations are matched in the default mode,93transformations can be accidentally made to template declarations. Finally,94because implicit nodes are matched by default, transformations can be made on95entirely incorrect places in the code.</p>96 97<p>For these reasons, it is possible to ignore AST nodes which are not spelled98in the source using the <span class="mono">IgnoreUnlessSpelledInSource</span>99mode. This is likely to be far less error-prone for users who are not already100very familiar with where implicit nodes appear in the AST. It is also likely101to be less error-prone for experienced AST users, as difficult cases do not102need to be encountered and matcher expressions adjusted for these cases.</p>103 104<p>In clang-query, the mode can be changed with105<pre>106set traversal IgnoreUnlessSpelledInSource107</pre>108</p>109This affects both matchers and AST dump output in results.110 111<p>When using the C++ API such as in clang-tidy checks, the112<span class="mono">traverse()</span> matcher is used to set the mode:113<pre>114Finder->addMatcher(traverse(TK_IgnoreUnlessSpelledInSource,115 returnStmt(hasReturnValue(integerLiteral(equals(0))))116 ), this);117</pre>118</p>119<p>The following table compares the <span class="mono">AsIs</span> mode with120the <span class="mono">IgnoreUnlessSpelledInSource</span> mode:</p>121 122<table class="traverse_compare">123<tr>124<th></th>125<th><span class="mono">AsIs</span></th>126<th><span class="mono">IgnoreUnlessSpelledInSource</span></th>127</tr>128<tr>129 <td>AST dump of <span class="mono">func1</span>:130<pre>131struct B {132 B(int);133};134 135B func1() { return 42; }136</pre>137 138 </td>139 <td>140C++98 dialect:141<pre>142FunctionDecl143`-CompoundStmt144 `-ReturnStmt145 `-ExprWithCleanups146 `-CXXConstructExpr147 `-MaterializeTemporaryExpr148 `-ImplicitCastExpr149 `-ImplicitCastExpr150 `-CXXConstructExpr151 `-IntegerLiteral 'int' 42152</pre>153C++11, C++14 dialect:154<pre>155FunctionDecl156`-CompoundStmt157 `-ReturnStmt158 `-ExprWithCleanups159 `-CXXConstructExpr160 `-MaterializeTemporaryExpr161 `-ImplicitCastExpr162 `-CXXConstructExpr163 `-IntegerLiteral 'int' 42164</pre>165C++17, C++20 dialect:166<pre>167FunctionDecl168`-CompoundStmt169 `-ReturnStmt170 `-ImplicitCastExpr171 `-CXXConstructExpr172 `-IntegerLiteral 'int' 42173</pre>174</td>175 <td>176All dialects:177 <pre>178FunctionDecl179`-CompoundStmt180 `-ReturnStmt181 `-IntegerLiteral 'int' 42182</pre></td>183</tr>184 185<tr>186<td>Matcher for returned <span class="mono">42</span>:187<pre>188struct B {189 B(int);190};191 192B func1() { return 42; }193</pre>194 195 </td>196 <td>197All dialects:198<pre>199returnStmt(hasReturnValue(200 ignoringImplicit(201 ignoringElidableConstructorCall(202 ignoringImplicit(203 cxxConstructExpr(hasArgument(0,204 ignoringImplicit(205 integerLiteral().bind("returnVal")206 )207 ))208 )209 )210 )211 ))212</pre></td>213 <td>214All dialects:215<pre>216returnStmt(hasReturnValue(217 integerLiteral().bind("returnVal")218))219</pre></td>220</tr>221<tr>222<td>Match result for223<pre>implicitCastExpr()</pre>224given:225<pre>226struct B {227 B(int);228};229 230B func1() { return 42; }231</pre>232 233</td>234<td>235Match found.</td>236 <td>237No match.</td>238</tr>239<tr>240 <td>Match result for:241<pre>242cxxConstructorDecl(243 isCopyConstructor()244 ).bind("prepend_explicit")245</pre>246given:247<pre>248struct Other {};249struct Copyable {250 Other m_o;251 Copyable();252};253</pre>254</td>255<td>256Match found. Insertion produces incorrect output:257<pre>258struct Other {};259struct explicit Copyable {260 Other m_o;261 Copyable();262};263</pre>264</td>265<td>266No match found. Incorrect replacement not possible.267</td>268</tr>269<tr>270 <td>Replacement of <span class="mono">begin()</span>271 with <span class="mono">cbegin()</span>:272<pre>273cxxMemberCallExpr(274 on(ConstContainerExpr),275 callee(cxxMethodDecl(hasName("begin")))276 ).bind("replace_with_cbegin")277</pre>278given:279<pre>280void foo() {281 const Container c;282 c.begin();283 284 for (auto i : c) {285 }286}287</pre>288</td>289<td>2902 matches found. Replacement produces incorrect output:291<pre>292void foo() {293 const Container c;294 c.cbegin();295 296 for (auto i :.cbegin() c) {297 }298}299</pre>300</td>301<td>3021 match found. Replacement produces correct output:303<pre>304void foo() {305 const Container c;306 c.cbegin();307 308 for (auto i : c) {309 }310}311</pre>312</td>313</tr>314<tr>315 <td>Replacement of <span class="mono">int</span> member316 with <span class="mono">safe_int</span>:317<pre>318fieldDecl(319 hasType(asString("int"))320 ).bind("use_safe_int")321</pre>322given:323<pre>324struct S {325 int m_i;326};327 328template <typename T> struct TemplStruct {329 TemplStruct() {}330 ~TemplStruct() {}331 332private:333 T m_t;334};335 336void instantiate() { TemplStruct<int> ti; }337</pre>338</td>339<td>3402 matches found. Replacement produces incorrect output:341<pre>342struct S {343 safe_int m_i;344};345 346template <typename T> struct TemplStruct {347 TemplStruct() {}348 ~TemplStruct() {}349 350private:351 safe_int m_t;352};353 354void instantiate() { TemplStruct<int> ti; }355</pre>356</td>357<td>3581 match found. Replacement produces correct output:359<pre>360struct S {361 safe_int m_i;362};363 364template <typename T> struct TemplStruct {365 TemplStruct() {}366 ~TemplStruct() {}367 368private:369 T m_t;370};371 372void instantiate() { TemplStruct<int> ti; }373</pre>374</td>375</tr>376<tr>377 <td>Add prefix to member initializer378<pre>379cxxCtorInitializer(380 forField(fieldDecl())381 ).bind("add_prefix")382</pre>383given:384<pre>385struct Simple {};386 387struct Record {388 Record() : i(42) {}389private:390 int i;391 Simple s;392};393</pre>394</td>395<td>3962 matches found. Replacement produces incorrect output:397<pre>398struct Simple {};399 400struct Record {401 m_Record() : m_i(42) {}402private:403 int i;404 Simple s;405};406</pre>407</td>408<td>4091 match found. Replacement produces correct output:410<pre>411struct Simple {};412 413struct Record {414 Record() : m_i(42) {}415private:416 int i;417 Simple s;418};419</pre>420</td>421</tr>422<tr>423 <td>Ignored default arguments424<pre>425callExpr(426 callee(functionDecl(427 hasName("hasDefaultArg")428 )),429 argumentCountIs(1)430 ).bind("add_prefix")431</pre>432given:433<pre>434void hasDefaultArg(int i, int j = 0) {}435void callDefaultArg() { hasDefaultArg(42); }436</pre>437</td>438<td>439No match.440</td>441<td>4421 match found.443</td>444</tr>445<tr>446 <td>Lambda fields447<pre>448fieldDecl(449 hasType(asString("int"))450 ).bind("make_safe")451</pre>452given:453<pre>454struct S {455 int m_i;456};457 458void func() {459 int a = 0;460 int c = 0;461 462 auto l = [a, b = c](int d) { int e = d; };463 l(43);464}465</pre>466</td>467<td>4682 matches found. Replacement produces incorrect output:469<pre>470struct S {471 safe_int m_i;472};473 474void func() {475 int a = 0;476 int c = 0;477 478 auto l = [safe_a, safe_b = c](int d) { int e = d; };479 l(43);480}481</pre>482</td>483<td>4841 match found. Replacement produces correct output:485<pre>486struct S {487 safe_int m_i;488};489 490void func() {491 int a = 0;492 int c = 0;493 494 auto l = [a, b = c](int d) { int e = d; };495 l(43);496}497</pre>498</td>499 500</tr>501 502 503 504 505 506<tr>507 <td>Rewritten binary operators508<pre>509binaryOperator(510 hasOperatorName("<"),511 hasRHS(hasDescendant(integerLiteral(equals(0))))512 )513</pre>514given:515<pre>516#include <compare>517 518class HasSpaceship {519public:520 int x;521 bool operator==(const HasSpaceship&) const = default;522 std::strong_ordering operator<=>(const HasSpaceship&) const = default;523};524 525bool isLess(const HasSpaceship& a, const HasSpaceship& b) {526 return a < b;527}528</pre>529</td>530<td>5311 match found.532 533<pre>534 return a < b;535 ^~~~~536</pre>537 538</td>539<td>540No match found.541</td>542</tr>543</table>544 545<!-- ======================================================================= -->546<h2 id="decl-matchers">Node Matchers</h2>547<!-- ======================================================================= -->548 549<p>Node matchers are at the core of matcher expressions - they specify the type550of node that is expected. Every match expression starts with a node matcher,551which can then be further refined with a narrowing or traversal matcher. All552traversal matchers take node matchers as their arguments.</p>553 554<p>For convenience, all node matchers take an arbitrary number of arguments555and implicitly act as allOf matchers.</p>556 557<p>Node matchers are the only matchers that support the bind("id") call to558bind the matched node to the given string, to be later retrieved from the559match callback.</p>560 561<p>It is important to remember that the arguments to node matchers are562predicates on the same node, just with additional information about the type.563This is often useful to make matcher expression more readable by inlining bind564calls into redundant node matchers inside another node matcher:565<pre>566// This binds the CXXRecordDecl to "id", as the decl() matcher will stay on567// the same node.568recordDecl(decl().bind("id"), hasName("::MyClass"))569</pre>570</p>571 572<table>573<tr style="text-align:left"><th>Return type</th><th>Name</th><th>Parameters</th></tr>574<!-- START_DECL_MATCHERS -->575 576<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Attr.html">Attr</a>></td><td class="name" onclick="toggle('attr0')"><a name="attr0Anchor">attr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Attr.html">Attr</a>>...</td></tr>577<tr><td colspan="4" class="doc" id="attr0"><pre>Matches attributes.578Attributes may be attached with a variety of different syntaxes (including579keywords, C++11 attributes, GNU ``__attribute``` and MSVC `__declspec``,580and ``#pragma``s). They may also be implicit.581 582Given583 struct [[nodiscard]] Foo{};584 void bar(int * __attribute__((nonnull)) );585 __declspec(noinline) void baz();586 587 #pragma omp declare simd588 int min();589attr()590 matches "nodiscard", "nonnull", "noinline", and the whole "#pragma" line.591</pre></td></tr>592 593 594<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>></td><td class="name" onclick="toggle('cxxBaseSpecifier0')"><a name="cxxBaseSpecifier0Anchor">cxxBaseSpecifier</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>>...</td></tr>595<tr><td colspan="4" class="doc" id="cxxBaseSpecifier0"><pre>Matches class bases.596 597Examples matches public virtual B.598 class B {};599 class C : public virtual B {};600</pre></td></tr>601 602 603<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>></td><td class="name" onclick="toggle('cxxCtorInitializer0')"><a name="cxxCtorInitializer0Anchor">cxxCtorInitializer</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>>...</td></tr>604<tr><td colspan="4" class="doc" id="cxxCtorInitializer0"><pre>Matches constructor initializers.605 606Examples matches i(42).607 class C {608 C() : i(42) {}609 int i;610 };611</pre></td></tr>612 613 614<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('accessSpecDecl0')"><a name="accessSpecDecl0Anchor">accessSpecDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AccessSpecDecl.html">AccessSpecDecl</a>>...</td></tr>615<tr><td colspan="4" class="doc" id="accessSpecDecl0"><pre>Matches C++ access specifier declarations.616 617Given618 class C {619 public:620 int a;621 };622accessSpecDecl()623 matches 'public:'624</pre></td></tr>625 626 627<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('bindingDecl0')"><a name="bindingDecl0Anchor">bindingDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BindingDecl.html">BindingDecl</a>>...</td></tr>628<tr><td colspan="4" class="doc" id="bindingDecl0"><pre>Matches binding declarations629Example matches foo and bar630(matcher = bindingDecl()631 632 auto [foo, bar] = std::make_pair{42, 42};633</pre></td></tr>634 635 636<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('blockDecl0')"><a name="blockDecl0Anchor">blockDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockDecl.html">BlockDecl</a>>...</td></tr>637<tr><td colspan="4" class="doc" id="blockDecl0"><pre>Matches block declarations.638 639Example matches the declaration of the nameless block printing an input640integer.641 642 myFunc(^(int p) {643 printf("%d", p);644 })645</pre></td></tr>646 647 648<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('classTemplateDecl0')"><a name="classTemplateDecl0Anchor">classTemplateDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ClassTemplateDecl.html">ClassTemplateDecl</a>>...</td></tr>649<tr><td colspan="4" class="doc" id="classTemplateDecl0"><pre>Matches C++ class template declarations.650 651Example matches Z652 template<class T> class Z {};653</pre></td></tr>654 655 656<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('classTemplatePartialSpecializationDecl0')"><a name="classTemplatePartialSpecializationDecl0Anchor">classTemplatePartialSpecializationDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ClassTemplatePartialSpecializationDecl.html">ClassTemplatePartialSpecializationDecl</a>>...</td></tr>657<tr><td colspan="4" class="doc" id="classTemplatePartialSpecializationDecl0"><pre>Matches C++ class template partial specializations.658 659Given660 template<class T1, class T2, int I>661 class A {};662 663 template<class T, int I>664 class A<T, T*, I> {};665 666 template<>667 class A<int, int, 1> {};668classTemplatePartialSpecializationDecl()669 matches the specialization A<T,T*,I> but not A<int,int,1>670</pre></td></tr>671 672 673<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('classTemplateSpecializationDecl0')"><a name="classTemplateSpecializationDecl0Anchor">classTemplateSpecializationDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html">ClassTemplateSpecializationDecl</a>>...</td></tr>674<tr><td colspan="4" class="doc" id="classTemplateSpecializationDecl0"><pre>Matches C++ class template specializations.675 676Given677 template<typename T> class A {};678 template<> class A<double> {};679 A<int> a;680classTemplateSpecializationDecl()681 matches the specializations A<int> and A<double>682</pre></td></tr>683 684 685<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('conceptDecl0')"><a name="conceptDecl0Anchor">conceptDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ConceptDecl.html">ConceptDecl</a>>...</td></tr>686<tr><td colspan="4" class="doc" id="conceptDecl0"><pre>Matches concept declarations.687 688Example matches integral689 template<typename T>690 concept integral = std::is_integral_v<T>;691</pre></td></tr>692 693 694<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('cxxConstructorDecl0')"><a name="cxxConstructorDecl0Anchor">cxxConstructorDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html">CXXConstructorDecl</a>>...</td></tr>695<tr><td colspan="4" class="doc" id="cxxConstructorDecl0"><pre>Matches C++ constructor declarations.696 697Example matches Foo::Foo() and Foo::Foo(int)698 class Foo {699 public:700 Foo();701 Foo(int);702 int DoSomething();703 };704</pre></td></tr>705 706 707<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('cxxConversionDecl0')"><a name="cxxConversionDecl0Anchor">cxxConversionDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConversionDecl.html">CXXConversionDecl</a>>...</td></tr>708<tr><td colspan="4" class="doc" id="cxxConversionDecl0"><pre>Matches conversion operator declarations.709 710Example matches the operator.711 class X { operator int() const; };712</pre></td></tr>713 714 715<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('cxxDeductionGuideDecl0')"><a name="cxxDeductionGuideDecl0Anchor">cxxDeductionGuideDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXDeductionGuideDecl.html">CXXDeductionGuideDecl</a>>...</td></tr>716<tr><td colspan="4" class="doc" id="cxxDeductionGuideDecl0"><pre>Matches user-defined and implicitly generated deduction guide.717 718Example matches the deduction guide.719 template<typename T>720 class X { X(int) };721 X(int) -> X<int>;722</pre></td></tr>723 724 725<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('cxxDestructorDecl0')"><a name="cxxDestructorDecl0Anchor">cxxDestructorDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXDestructorDecl.html">CXXDestructorDecl</a>>...</td></tr>726<tr><td colspan="4" class="doc" id="cxxDestructorDecl0"><pre>Matches explicit C++ destructor declarations.727 728Example matches Foo::~Foo()729 class Foo {730 public:731 virtual ~Foo();732 };733</pre></td></tr>734 735 736<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('cxxMethodDecl0')"><a name="cxxMethodDecl0Anchor">cxxMethodDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>>...</td></tr>737<tr><td colspan="4" class="doc" id="cxxMethodDecl0"><pre>Matches method declarations.738 739Example matches y740 class X { void y(); };741</pre></td></tr>742 743 744<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('cxxRecordDecl0')"><a name="cxxRecordDecl0Anchor">cxxRecordDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>>...</td></tr>745<tr><td colspan="4" class="doc" id="cxxRecordDecl0"><pre>Matches C++ class declarations.746 747Example matches X, Z748 class X;749 template<class T> class Z {};750</pre></td></tr>751 752 753<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('decl0')"><a name="decl0Anchor">decl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>...</td></tr>754<tr><td colspan="4" class="doc" id="decl0"><pre>Matches declarations.755 756Examples matches X, C, and the friend declaration inside C;757 void X();758 class C {759 friend X;760 };761</pre></td></tr>762 763 764<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('declaratorDecl0')"><a name="declaratorDecl0Anchor">declaratorDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclaratorDecl.html">DeclaratorDecl</a>>...</td></tr>765<tr><td colspan="4" class="doc" id="declaratorDecl0"><pre>Matches declarator declarations (field, variable, function766and non-type template parameter declarations).767 768Given769 class X { int y; };770declaratorDecl()771 matches int y.772</pre></td></tr>773 774 775<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('decompositionDecl0')"><a name="decompositionDecl0Anchor">decompositionDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DecompositionDecl.html">DecompositionDecl</a>>...</td></tr>776<tr><td colspan="4" class="doc" id="decompositionDecl0"><pre>Matches decomposition-declarations.777 778Examples matches the declaration node with foo and bar, but not779number.780(matcher = declStmt(has(decompositionDecl())))781 782 int number = 42;783 auto [foo, bar] = std::make_pair{42, 42};784</pre></td></tr>785 786 787<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('enumConstantDecl0')"><a name="enumConstantDecl0Anchor">enumConstantDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1EnumConstantDecl.html">EnumConstantDecl</a>>...</td></tr>788<tr><td colspan="4" class="doc" id="enumConstantDecl0"><pre>Matches enum constants.789 790Example matches A, B, C791 enum X {792 A, B, C793 };794</pre></td></tr>795 796 797<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('enumDecl0')"><a name="enumDecl0Anchor">enumDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1EnumDecl.html">EnumDecl</a>>...</td></tr>798<tr><td colspan="4" class="doc" id="enumDecl0"><pre>Matches enum declarations.799 800Example matches X801 enum X {802 A, B, C803 };804</pre></td></tr>805 806 807<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('exportDecl0')"><a name="exportDecl0Anchor">exportDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ExportDecl.html">ExportDecl</a>>...</td></tr>808<tr><td colspan="4" class="doc" id="exportDecl0"><pre>Matches any export declaration.809 810Example matches following declarations.811 export void foo();812 export { void foo(); }813 export namespace { void foo(); }814 export int v;815</pre></td></tr>816 817 818<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('fieldDecl0')"><a name="fieldDecl0Anchor">fieldDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html">FieldDecl</a>>...</td></tr>819<tr><td colspan="4" class="doc" id="fieldDecl0"><pre>Matches field declarations.820 821Given822 class X { int m; };823fieldDecl()824 matches 'm'.825</pre></td></tr>826 827 828<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('fileScopeAsmDecl0')"><a name="fileScopeAsmDecl0Anchor">fileScopeAsmDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FileScopeAsmDecl.html">FileScopeAsmDecl</a>>...</td></tr>829<tr><td colspan="4" class="doc" id="fileScopeAsmDecl0"><pre>Matches top level asm declarations.830 831Given832 __asm("nop");833 void f() {834 __asm("mov al, 2");835 }836fileScopeAsmDecl()837 matches '__asm("nop")',838 but not '__asm("mov al, 2")'.839</pre></td></tr>840 841 842<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('friendDecl0')"><a name="friendDecl0Anchor">friendDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FriendDecl.html">FriendDecl</a>>...</td></tr>843<tr><td colspan="4" class="doc" id="friendDecl0"><pre>Matches friend declarations.844 845Given846 class X { friend void foo(); };847friendDecl()848 matches 'friend void foo()'.849</pre></td></tr>850 851 852<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('functionDecl0')"><a name="functionDecl0Anchor">functionDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>...</td></tr>853<tr><td colspan="4" class="doc" id="functionDecl0"><pre>Matches function declarations.854 855Example matches f856 void f();857</pre></td></tr>858 859 860<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('functionTemplateDecl0')"><a name="functionTemplateDecl0Anchor">functionTemplateDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionTemplateDecl.html">FunctionTemplateDecl</a>>...</td></tr>861<tr><td colspan="4" class="doc" id="functionTemplateDecl0"><pre>Matches C++ function template declarations.862 863Example matches f864 template<class T> void f(T t) {}865</pre></td></tr>866 867 868<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('indirectFieldDecl0')"><a name="indirectFieldDecl0Anchor">indirectFieldDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IndirectFieldDecl.html">IndirectFieldDecl</a>>...</td></tr>869<tr><td colspan="4" class="doc" id="indirectFieldDecl0"><pre>Matches indirect field declarations.870 871Given872 struct X { struct { int a; }; };873indirectFieldDecl()874 matches 'a'.875</pre></td></tr>876 877 878<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('labelDecl0')"><a name="labelDecl0Anchor">labelDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelDecl.html">LabelDecl</a>>...</td></tr>879<tr><td colspan="4" class="doc" id="labelDecl0"><pre>Matches a declaration of label.880 881Given882 goto FOO;883 FOO: bar();884labelDecl()885 matches 'FOO:'886</pre></td></tr>887 888 889<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('linkageSpecDecl0')"><a name="linkageSpecDecl0Anchor">linkageSpecDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LinkageSpecDecl.html">LinkageSpecDecl</a>>...</td></tr>890<tr><td colspan="4" class="doc" id="linkageSpecDecl0"><pre>Matches a declaration of a linkage specification.891 892Given893 extern "C" {}894linkageSpecDecl()895 matches "extern "C" {}"896</pre></td></tr>897 898 899<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('namedDecl0')"><a name="namedDecl0Anchor">namedDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>>...</td></tr>900<tr><td colspan="4" class="doc" id="namedDecl0"><pre>Matches a declaration of anything that could have a name.901 902Example matches X, S, the anonymous union type, i, and U;903 typedef int X;904 struct S {905 union {906 int i;907 } U;908 };909</pre></td></tr>910 911 912<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('namespaceAliasDecl0')"><a name="namespaceAliasDecl0Anchor">namespaceAliasDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamespaceAliasDecl.html">NamespaceAliasDecl</a>>...</td></tr>913<tr><td colspan="4" class="doc" id="namespaceAliasDecl0"><pre>Matches a declaration of a namespace alias.914 915Given916 namespace test {}917 namespace alias = ::test;918namespaceAliasDecl()919 matches "namespace alias" but not "namespace test"920</pre></td></tr>921 922 923<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('namespaceDecl0')"><a name="namespaceDecl0Anchor">namespaceDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamespaceDecl.html">NamespaceDecl</a>>...</td></tr>924<tr><td colspan="4" class="doc" id="namespaceDecl0"><pre>Matches a declaration of a namespace.925 926Given927 namespace {}928 namespace test {}929namespaceDecl()930 matches "namespace {}" and "namespace test {}"931</pre></td></tr>932 933 934<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('nonTypeTemplateParmDecl0')"><a name="nonTypeTemplateParmDecl0Anchor">nonTypeTemplateParmDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NonTypeTemplateParmDecl.html">NonTypeTemplateParmDecl</a>>...</td></tr>935<tr><td colspan="4" class="doc" id="nonTypeTemplateParmDecl0"><pre>Matches non-type template parameter declarations.936 937Given938 template <typename T, int N> struct C {};939nonTypeTemplateParmDecl()940 matches 'N', but not 'T'.941</pre></td></tr>942 943 944<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('objcCategoryDecl0')"><a name="objcCategoryDecl0Anchor">objcCategoryDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCCategoryDecl.html">ObjCCategoryDecl</a>>...</td></tr>945<tr><td colspan="4" class="doc" id="objcCategoryDecl0"><pre>Matches Objective-C category declarations.946 947Example matches Foo (Additions)948 @interface Foo (Additions)949 @end950</pre></td></tr>951 952 953<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('objcCategoryImplDecl0')"><a name="objcCategoryImplDecl0Anchor">objcCategoryImplDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCCategoryImplDecl.html">ObjCCategoryImplDecl</a>>...</td></tr>954<tr><td colspan="4" class="doc" id="objcCategoryImplDecl0"><pre>Matches Objective-C category definitions.955 956Example matches Foo (Additions)957 @implementation Foo (Additions)958 @end959</pre></td></tr>960 961 962<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('objcImplementationDecl0')"><a name="objcImplementationDecl0Anchor">objcImplementationDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCImplementationDecl.html">ObjCImplementationDecl</a>>...</td></tr>963<tr><td colspan="4" class="doc" id="objcImplementationDecl0"><pre>Matches Objective-C implementation declarations.964 965Example matches Foo966 @implementation Foo967 @end968</pre></td></tr>969 970 971<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('objcInterfaceDecl0')"><a name="objcInterfaceDecl0Anchor">objcInterfaceDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCInterfaceDecl.html">ObjCInterfaceDecl</a>>...</td></tr>972<tr><td colspan="4" class="doc" id="objcInterfaceDecl0"><pre>Matches Objective-C interface declarations.973 974Example matches Foo975 @interface Foo976 @end977</pre></td></tr>978 979 980<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('objcIvarDecl0')"><a name="objcIvarDecl0Anchor">objcIvarDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCIvarDecl.html">ObjCIvarDecl</a>>...</td></tr>981<tr><td colspan="4" class="doc" id="objcIvarDecl0"><pre>Matches Objective-C instance variable declarations.982 983Example matches _enabled984 @implementation Foo {985 BOOL _enabled;986 }987 @end988</pre></td></tr>989 990 991<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('objcMethodDecl0')"><a name="objcMethodDecl0Anchor">objcMethodDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html">ObjCMethodDecl</a>>...</td></tr>992<tr><td colspan="4" class="doc" id="objcMethodDecl0"><pre>Matches Objective-C method declarations.993 994Example matches both declaration and definition of -[Foo method]995 @interface Foo996 - (void)method;997 @end998 999 @implementation Foo1000 - (void)method {}1001 @end1002</pre></td></tr>1003 1004 1005<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('objcPropertyDecl0')"><a name="objcPropertyDecl0Anchor">objcPropertyDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCPropertyDecl.html">ObjCPropertyDecl</a>>...</td></tr>1006<tr><td colspan="4" class="doc" id="objcPropertyDecl0"><pre>Matches Objective-C property declarations.1007 1008Example matches enabled1009 @interface Foo1010 @property BOOL enabled;1011 @end1012</pre></td></tr>1013 1014 1015<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('objcProtocolDecl0')"><a name="objcProtocolDecl0Anchor">objcProtocolDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCProtocolDecl.html">ObjCProtocolDecl</a>>...</td></tr>1016<tr><td colspan="4" class="doc" id="objcProtocolDecl0"><pre>Matches Objective-C protocol declarations.1017 1018Example matches FooDelegate1019 @protocol FooDelegate1020 @end1021</pre></td></tr>1022 1023 1024<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('parmVarDecl0')"><a name="parmVarDecl0Anchor">parmVarDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html">ParmVarDecl</a>>...</td></tr>1025<tr><td colspan="4" class="doc" id="parmVarDecl0"><pre>Matches parameter variable declarations.1026 1027Given1028 void f(int x);1029parmVarDecl()1030 matches int x.1031</pre></td></tr>1032 1033 1034<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('recordDecl0')"><a name="recordDecl0Anchor">recordDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1RecordDecl.html">RecordDecl</a>>...</td></tr>1035<tr><td colspan="4" class="doc" id="recordDecl0"><pre>Matches class, struct, and union declarations.1036 1037Example matches X, Z, U, and S1038 class X;1039 template<class T> class Z {};1040 struct S {};1041 union U {};1042</pre></td></tr>1043 1044 1045<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('requiresExprBodyDecl0')"><a name="requiresExprBodyDecl0Anchor">requiresExprBodyDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1RequiresExprBodyDecl.html">RequiresExprBodyDecl</a>>...</td></tr>1046<tr><td colspan="4" class="doc" id="requiresExprBodyDecl0"><pre>Matches concept requirement body declaration.1047 1048Example matches '{ *p; }'1049 template<typename T>1050 concept dereferencable = requires(T p) { *p; }1051</pre></td></tr>1052 1053 1054<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('staticAssertDecl0')"><a name="staticAssertDecl0Anchor">staticAssertDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1StaticAssertDecl.html">StaticAssertDecl</a>>...</td></tr>1055<tr><td colspan="4" class="doc" id="staticAssertDecl0"><pre>Matches a C++ static_assert declaration.1056 1057Example:1058 staticAssertDecl()1059matches1060 static_assert(sizeof(S) == sizeof(int))1061in1062 struct S {1063 int x;1064 };1065 static_assert(sizeof(S) == sizeof(int));1066</pre></td></tr>1067 1068 1069<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('tagDecl0')"><a name="tagDecl0Anchor">tagDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagDecl.html">TagDecl</a>>...</td></tr>1070<tr><td colspan="4" class="doc" id="tagDecl0"><pre>Matches tag declarations.1071 1072Example matches X, Z, U, S, E1073 class X;1074 template<class T> class Z {};1075 struct S {};1076 union U {};1077 enum E {1078 A, B, C1079 };1080</pre></td></tr>1081 1082 1083<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('templateTemplateParmDecl0')"><a name="templateTemplateParmDecl0Anchor">templateTemplateParmDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateTemplateParmDecl.html">TemplateTemplateParmDecl</a>>...</td></tr>1084<tr><td colspan="4" class="doc" id="templateTemplateParmDecl0"><pre>Matches template template parameter declarations.1085 1086Given1087 template <template <typename> class Z, int N> struct C {};1088templateTypeParmDecl()1089 matches 'Z', but not 'N'.1090</pre></td></tr>1091 1092 1093<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('templateTypeParmDecl0')"><a name="templateTypeParmDecl0Anchor">templateTypeParmDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmDecl.html">TemplateTypeParmDecl</a>>...</td></tr>1094<tr><td colspan="4" class="doc" id="templateTypeParmDecl0"><pre>Matches template type parameter declarations.1095 1096Given1097 template <typename T, int N> struct C {};1098templateTypeParmDecl()1099 matches 'T', but not 'N'.1100</pre></td></tr>1101 1102 1103<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('translationUnitDecl0')"><a name="translationUnitDecl0Anchor">translationUnitDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TranslationUnitDecl.html">TranslationUnitDecl</a>>...</td></tr>1104<tr><td colspan="4" class="doc" id="translationUnitDecl0"><pre>Matches the top declaration context.1105 1106Given1107 int X;1108 namespace NS {1109 int Y;1110 } // namespace NS1111decl(hasDeclContext(translationUnitDecl()))1112 matches "int X", but not "int Y".1113</pre></td></tr>1114 1115 1116<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('typeAliasDecl0')"><a name="typeAliasDecl0Anchor">typeAliasDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeAliasDecl.html">TypeAliasDecl</a>>...</td></tr>1117<tr><td colspan="4" class="doc" id="typeAliasDecl0"><pre>Matches type alias declarations.1118 1119Given1120 typedef int X;1121 using Y = int;1122typeAliasDecl()1123 matches "using Y = int", but not "typedef int X"1124</pre></td></tr>1125 1126 1127<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('typeAliasTemplateDecl0')"><a name="typeAliasTemplateDecl0Anchor">typeAliasTemplateDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeAliasTemplateDecl.html">TypeAliasTemplateDecl</a>>...</td></tr>1128<tr><td colspan="4" class="doc" id="typeAliasTemplateDecl0"><pre>Matches type alias template declarations.1129 1130typeAliasTemplateDecl() matches1131 template <typename T>1132 using Y = X<T>;1133</pre></td></tr>1134 1135 1136<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('typedefDecl0')"><a name="typedefDecl0Anchor">typedefDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefDecl.html">TypedefDecl</a>>...</td></tr>1137<tr><td colspan="4" class="doc" id="typedefDecl0"><pre>Matches typedef declarations.1138 1139Given1140 typedef int X;1141 using Y = int;1142typedefDecl()1143 matches "typedef int X", but not "using Y = int"1144</pre></td></tr>1145 1146 1147<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('typedefNameDecl0')"><a name="typedefNameDecl0Anchor">typedefNameDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefNameDecl.html">TypedefNameDecl</a>>...</td></tr>1148<tr><td colspan="4" class="doc" id="typedefNameDecl0"><pre>Matches typedef name declarations.1149 1150Given1151 typedef int X;1152 using Y = int;1153typedefNameDecl()1154 matches "typedef int X" and "using Y = int"1155</pre></td></tr>1156 1157 1158<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('unresolvedUsingTypenameDecl0')"><a name="unresolvedUsingTypenameDecl0Anchor">unresolvedUsingTypenameDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingTypenameDecl.html">UnresolvedUsingTypenameDecl</a>>...</td></tr>1159<tr><td colspan="4" class="doc" id="unresolvedUsingTypenameDecl0"><pre>Matches unresolved using value declarations that involve the1160typename.1161 1162Given1163 template <typename T>1164 struct Base { typedef T Foo; };1165 1166 template<typename T>1167 struct S : private Base<T> {1168 using typename Base<T>::Foo;1169 };1170unresolvedUsingTypenameDecl()1171 matches using Base<T>::Foo </pre></td></tr>1172 1173 1174<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('unresolvedUsingValueDecl0')"><a name="unresolvedUsingValueDecl0Anchor">unresolvedUsingValueDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingValueDecl.html">UnresolvedUsingValueDecl</a>>...</td></tr>1175<tr><td colspan="4" class="doc" id="unresolvedUsingValueDecl0"><pre>Matches unresolved using value declarations.1176 1177Given1178 template<typename X>1179 class C : private X {1180 using X::x;1181 };1182unresolvedUsingValueDecl()1183 matches using X::x </pre></td></tr>1184 1185 1186<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('usingDecl0')"><a name="usingDecl0Anchor">usingDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingDecl.html">UsingDecl</a>>...</td></tr>1187<tr><td colspan="4" class="doc" id="usingDecl0"><pre>Matches using declarations.1188 1189Given1190 namespace X { int x; }1191 using X::x;1192usingDecl()1193 matches using X::x </pre></td></tr>1194 1195 1196<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('usingDirectiveDecl0')"><a name="usingDirectiveDecl0Anchor">usingDirectiveDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingDirectiveDecl.html">UsingDirectiveDecl</a>>...</td></tr>1197<tr><td colspan="4" class="doc" id="usingDirectiveDecl0"><pre>Matches using namespace declarations.1198 1199Given1200 namespace X { int x; }1201 using namespace X;1202usingDirectiveDecl()1203 matches using namespace X </pre></td></tr>1204 1205 1206<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('usingEnumDecl0')"><a name="usingEnumDecl0Anchor">usingEnumDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingEnumDecl.html">UsingEnumDecl</a>>...</td></tr>1207<tr><td colspan="4" class="doc" id="usingEnumDecl0"><pre>Matches using-enum declarations.1208 1209Given1210 namespace X { enum x {...}; }1211 using enum X::x;1212usingEnumDecl()1213 matches using enum X::x </pre></td></tr>1214 1215 1216<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('usingShadowDecl0')"><a name="usingShadowDecl0Anchor">usingShadowDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingShadowDecl.html">UsingShadowDecl</a>>...</td></tr>1217<tr><td colspan="4" class="doc" id="usingShadowDecl0"><pre>Matches shadow declarations introduced into a scope by a1218 (resolved) using declaration.1219 1220Given1221 namespace n { int f; }1222 namespace declToImport { using n::f; }1223usingShadowDecl()1224 matches f </pre></td></tr>1225 1226 1227<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('valueDecl0')"><a name="valueDecl0Anchor">valueDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</a>>...</td></tr>1228<tr><td colspan="4" class="doc" id="valueDecl0"><pre>Matches any value declaration.1229 1230Example matches A, B, C and F1231 enum X { A, B, C };1232 void F();1233</pre></td></tr>1234 1235 1236<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('varDecl0')"><a name="varDecl0Anchor">varDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>...</td></tr>1237<tr><td colspan="4" class="doc" id="varDecl0"><pre>Matches variable declarations.1238 1239Note: this does not match declarations of member variables, which are1240"field" declarations in Clang parlance.1241 1242Example matches a1243 int a;1244</pre></td></tr>1245 1246 1247<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>></td><td class="name" onclick="toggle('requiresExpr0')"><a name="requiresExpr0Anchor">requiresExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1RequiresExpr.html">RequiresExpr</a>>...</td></tr>1248<tr><td colspan="4" class="doc" id="requiresExpr0"><pre>Matches concept requirement.1249 1250Example matches 'requires(T p) { *p; }'1251 template<typename T>1252 concept dereferencable = requires(T p) { *p; }1253</pre></td></tr>1254 1255 1256<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LambdaCapture.html">LambdaCapture</a>></td><td class="name" onclick="toggle('lambdaCapture0')"><a name="lambdaCapture0Anchor">lambdaCapture</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LambdaCapture.html">LambdaCapture</a>>...</td></tr>1257<tr><td colspan="4" class="doc" id="lambdaCapture0"><pre>Matches lambda captures.1258 1259Given1260 int main() {1261 int x;1262 auto f = [x](){};1263 auto g = [x = 1](){};1264 }1265In the matcher `lambdaExpr(hasAnyCapture(lambdaCapture()))`,1266`lambdaCapture()` matches `x` and `x=1`.1267</pre></td></tr>1268 1269 1270<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifierLoc.html">NestedNameSpecifierLoc</a>></td><td class="name" onclick="toggle('nestedNameSpecifierLoc0')"><a name="nestedNameSpecifierLoc0Anchor">nestedNameSpecifierLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifierLoc.html">NestedNameSpecifierLoc</a>>...</td></tr>1271<tr><td colspan="4" class="doc" id="nestedNameSpecifierLoc0"><pre>Same as nestedNameSpecifier but matches NestedNameSpecifierLoc.1272</pre></td></tr>1273 1274 1275<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifier.html">NestedNameSpecifier</a>></td><td class="name" onclick="toggle('nestedNameSpecifier0')"><a name="nestedNameSpecifier0Anchor">nestedNameSpecifier</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifier.html">NestedNameSpecifier</a>>...</td></tr>1276<tr><td colspan="4" class="doc" id="nestedNameSpecifier0"><pre>Matches nested name specifiers.1277 1278Given1279 namespace ns {1280 struct A { static void f(); };1281 void A::f() {}1282 void g() { A::f(); }1283 }1284 ns::A a;1285nestedNameSpecifier()1286 matches "ns::" and both "A::"1287</pre></td></tr>1288 1289 1290<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPClause.html">OMPClause</a>></td><td class="name" onclick="toggle('ompDefaultClause0')"><a name="ompDefaultClause0Anchor">ompDefaultClause</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPDefaultClause.html">OMPDefaultClause</a>>...</td></tr>1291<tr><td colspan="4" class="doc" id="ompDefaultClause0"><pre>Matches OpenMP ``default`` clause.1292 1293Given1294 1295 #pragma omp parallel default(none)1296 #pragma omp parallel default(shared)1297 #pragma omp parallel default(private)1298 #pragma omp parallel default(firstprivate)1299 #pragma omp parallel1300 1301``ompDefaultClause()`` matches ``default(none)``, ``default(shared)``,1302`` default(private)`` and ``default(firstprivate)``1303</pre></td></tr>1304 1305 1306<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('qualType0')"><a name="qualType0Anchor">qualType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>...</td></tr>1307<tr><td colspan="4" class="doc" id="qualType0"><pre>Matches QualTypes in the clang AST.1308</pre></td></tr>1309 1310 1311<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('addrLabelExpr0')"><a name="addrLabelExpr0Anchor">addrLabelExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>...</td></tr>1312<tr><td colspan="4" class="doc" id="addrLabelExpr0"><pre>Matches address of label statements (GNU extension).1313 1314Given1315 FOO: bar();1316 void *ptr = &&FOO;1317 goto *bar;1318addrLabelExpr()1319 matches '&&FOO'1320</pre></td></tr>1321 1322 1323<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('arrayInitIndexExpr0')"><a name="arrayInitIndexExpr0Anchor">arrayInitIndexExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ArrayInitIndexExpr.html">ArrayInitIndexExpr</a>>...</td></tr>1324<tr><td colspan="4" class="doc" id="arrayInitIndexExpr0"><pre>The arrayInitIndexExpr consists of two subexpressions: a common expression1325(the source array) that is evaluated once up-front, and a per-element initializer1326that runs once for each array element. Within the per-element initializer,1327the current index may be obtained via an ArrayInitIndexExpr.1328 1329Given1330 void testStructBinding() {1331 int a[2] = {1, 2};1332 auto [x, y] = a;1333 }1334arrayInitIndexExpr() matches the array index that implicitly iterates1335over the array `a` to copy each element to the anonymous array1336that backs the structured binding `[x, y]` elements of which are1337referred to by their aliases `x` and `y`.1338</pre></td></tr>1339 1340 1341<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('arrayInitLoopExpr0')"><a name="arrayInitLoopExpr0Anchor">arrayInitLoopExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ArrayInitLoopExpr.html">ArrayInitLoopExpr</a>>...</td></tr>1342<tr><td colspan="4" class="doc" id="arrayInitLoopExpr0"><pre>Matches a loop initializing the elements of an array in a number of contexts:1343 * in the implicit copy/move constructor for a class with an array member1344 * when a lambda-expression captures an array by value1345 * when a decomposition declaration decomposes an array1346 1347Given1348 void testLambdaCapture() {1349 int a[10];1350 auto Lam1 = [a]() {1351 return;1352 };1353 }1354arrayInitLoopExpr() matches the implicit loop that initializes each element of1355the implicit array field inside the lambda object, that represents the array `a`1356captured by value.1357</pre></td></tr>1358 1359 1360<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('arraySubscriptExpr0')"><a name="arraySubscriptExpr0Anchor">arraySubscriptExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ArraySubscriptExpr.html">ArraySubscriptExpr</a>>...</td></tr>1361<tr><td colspan="4" class="doc" id="arraySubscriptExpr0"><pre>Matches array subscript expressions.1362 1363Given1364 int i = a[1];1365arraySubscriptExpr()1366 matches "a[1]"1367</pre></td></tr>1368 1369 1370<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('asmStmt0')"><a name="asmStmt0Anchor">asmStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AsmStmt.html">AsmStmt</a>>...</td></tr>1371<tr><td colspan="4" class="doc" id="asmStmt0"><pre>Matches asm statements.1372 1373 int i = 100;1374 __asm("mov al, 2");1375asmStmt()1376 matches '__asm("mov al, 2")'1377</pre></td></tr>1378 1379 1380<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('atomicExpr0')"><a name="atomicExpr0Anchor">atomicExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AtomicExpr.html">AtomicExpr</a>>...</td></tr>1381<tr><td colspan="4" class="doc" id="atomicExpr0"><pre>Matches atomic builtins.1382Example matches __atomic_load_n(ptr, 1)1383 void foo() { int *ptr; __atomic_load_n(ptr, 1); }1384</pre></td></tr>1385 1386 1387<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('autoreleasePoolStmt0')"><a name="autoreleasePoolStmt0Anchor">autoreleasePoolStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCAutoreleasePoolStmt.html">ObjCAutoreleasePoolStmt</a>>...</td></tr>1388<tr><td colspan="4" class="doc" id="autoreleasePoolStmt0"><pre>Matches an Objective-C autorelease pool statement.1389 1390Given1391 @autoreleasepool {1392 int x = 0;1393 }1394autoreleasePoolStmt(stmt()) matches the declaration of "x"1395inside the autorelease pool.1396</pre></td></tr>1397 1398 1399<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('binaryConditionalOperator0')"><a name="binaryConditionalOperator0Anchor">binaryConditionalOperator</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BinaryConditionalOperator.html">BinaryConditionalOperator</a>>...</td></tr>1400<tr><td colspan="4" class="doc" id="binaryConditionalOperator0"><pre>Matches binary conditional operator expressions (GNU extension).1401 1402Example matches a ?: b1403 (a ?: b) + 42;1404</pre></td></tr>1405 1406 1407<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('binaryOperator0')"><a name="binaryOperator0Anchor">binaryOperator</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html">BinaryOperator</a>>...</td></tr>1408<tr><td colspan="4" class="doc" id="binaryOperator0"><pre>Matches binary operator expressions.1409 1410Example matches a || b1411 !(a || b)1412See also the binaryOperation() matcher for more-general matching.1413</pre></td></tr>1414 1415 1416<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('blockExpr0')"><a name="blockExpr0Anchor">blockExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockExpr.html">BlockExpr</a>>...</td></tr>1417<tr><td colspan="4" class="doc" id="blockExpr0"><pre>Matches a reference to a block.1418 1419Example: matches "^{}":1420 void f() { ^{}(); }1421</pre></td></tr>1422 1423 1424<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('breakStmt0')"><a name="breakStmt0Anchor">breakStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BreakStmt.html">BreakStmt</a>>...</td></tr>1425<tr><td colspan="4" class="doc" id="breakStmt0"><pre>Matches break statements.1426 1427Given1428 while (true) { break; }1429breakStmt()1430 matches 'break'1431</pre></td></tr>1432 1433 1434<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cStyleCastExpr0')"><a name="cStyleCastExpr0Anchor">cStyleCastExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CStyleCastExpr.html">CStyleCastExpr</a>>...</td></tr>1435<tr><td colspan="4" class="doc" id="cStyleCastExpr0"><pre>Matches a C-style cast expression.1436 1437Example: Matches (int) 2.2f in1438 int i = (int) 2.2f;1439</pre></td></tr>1440 1441 1442<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('callExpr0')"><a name="callExpr0Anchor">callExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>...</td></tr>1443<tr><td colspan="4" class="doc" id="callExpr0"><pre>Matches call expressions.1444 1445Example matches x.y() and y()1446 X x;1447 x.y();1448 y();1449</pre></td></tr>1450 1451 1452<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('caseStmt0')"><a name="caseStmt0Anchor">caseStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CaseStmt.html">CaseStmt</a>>...</td></tr>1453<tr><td colspan="4" class="doc" id="caseStmt0"><pre>Matches case statements inside switch statements.1454 1455Given1456 switch(a) { case 42: break; default: break; }1457caseStmt()1458 matches 'case 42:'.1459</pre></td></tr>1460 1461 1462<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('castExpr0')"><a name="castExpr0Anchor">castExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CastExpr.html">CastExpr</a>>...</td></tr>1463<tr><td colspan="4" class="doc" id="castExpr0"><pre>Matches any cast nodes of Clang's AST.1464 1465Example: castExpr() matches each of the following:1466 (int) 3;1467 const_cast<Expr *>(SubExpr);1468 char c = 0;1469but does not match1470 int i = (0);1471 int k = 0;1472</pre></td></tr>1473 1474 1475<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('characterLiteral0')"><a name="characterLiteral0Anchor">characterLiteral</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>>...</td></tr>1476<tr><td colspan="4" class="doc" id="characterLiteral0"><pre>Matches character literals (also matches wchar_t).1477 1478Not matching Hex-encoded chars (e.g. 0x1234, which is a IntegerLiteral),1479though.1480 1481Example matches 'a', L'a'1482 char ch = 'a';1483 wchar_t chw = L'a';1484</pre></td></tr>1485 1486 1487<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('chooseExpr0')"><a name="chooseExpr0Anchor">chooseExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ChooseExpr.html">ChooseExpr</a>>...</td></tr>1488<tr><td colspan="4" class="doc" id="chooseExpr0"><pre>Matches GNU __builtin_choose_expr.1489</pre></td></tr>1490 1491 1492<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('coawaitExpr0')"><a name="coawaitExpr0Anchor">coawaitExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CoawaitExpr.html">CoawaitExpr</a>>...</td></tr>1493<tr><td colspan="4" class="doc" id="coawaitExpr0"><pre>Matches co_await expressions.1494 1495Given1496 co_await 1;1497coawaitExpr()1498 matches 'co_await 1'1499</pre></td></tr>1500 1501 1502<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('compoundLiteralExpr0')"><a name="compoundLiteralExpr0Anchor">compoundLiteralExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CompoundLiteralExpr.html">CompoundLiteralExpr</a>>...</td></tr>1503<tr><td colspan="4" class="doc" id="compoundLiteralExpr0"><pre>Matches compound (i.e. non-scalar) literals1504 1505Example match: {1}, (1, 2)1506 int array[4] = {1};1507 vector int myvec = (vector int)(1, 2);1508</pre></td></tr>1509 1510 1511<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('compoundStmt0')"><a name="compoundStmt0Anchor">compoundStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CompoundStmt.html">CompoundStmt</a>>...</td></tr>1512<tr><td colspan="4" class="doc" id="compoundStmt0"><pre>Matches compound statements.1513 1514Example matches '{}' and '{{}}' in 'for (;;) {{}}'1515 for (;;) {{}}1516</pre></td></tr>1517 1518 1519<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('conditionalOperator0')"><a name="conditionalOperator0Anchor">conditionalOperator</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ConditionalOperator.html">ConditionalOperator</a>>...</td></tr>1520<tr><td colspan="4" class="doc" id="conditionalOperator0"><pre>Matches conditional operator expressions.1521 1522Example matches a ? b : c1523 (a ? b : c) + 421524</pre></td></tr>1525 1526 1527<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('constantExpr0')"><a name="constantExpr0Anchor">constantExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ConstantExpr.html">ConstantExpr</a>>...</td></tr>1528<tr><td colspan="4" class="doc" id="constantExpr0"><pre>Matches a constant expression wrapper.1529 1530Example matches the constant in the case statement:1531 (matcher = constantExpr())1532 switch (a) {1533 case 37: break;1534 }1535</pre></td></tr>1536 1537 1538<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('continueStmt0')"><a name="continueStmt0Anchor">continueStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ContinueStmt.html">ContinueStmt</a>>...</td></tr>1539<tr><td colspan="4" class="doc" id="continueStmt0"><pre>Matches continue statements.1540 1541Given1542 while (true) { continue; }1543continueStmt()1544 matches 'continue'1545</pre></td></tr>1546 1547 1548<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('convertVectorExpr0')"><a name="convertVectorExpr0Anchor">convertVectorExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ConvertVectorExpr.html">ConvertVectorExpr</a>>...</td></tr>1549<tr><td colspan="4" class="doc" id="convertVectorExpr0"><pre>Matches builtin function __builtin_convertvector.1550</pre></td></tr>1551 1552 1553<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('coreturnStmt0')"><a name="coreturnStmt0Anchor">coreturnStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CoreturnStmt.html">CoreturnStmt</a>>...</td></tr>1554<tr><td colspan="4" class="doc" id="coreturnStmt0"><pre>Matches co_return statements.1555 1556Given1557 while (true) { co_return; }1558coreturnStmt()1559 matches 'co_return'1560</pre></td></tr>1561 1562 1563<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('coroutineBodyStmt0')"><a name="coroutineBodyStmt0Anchor">coroutineBodyStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CoroutineBodyStmt.html">CoroutineBodyStmt</a>>...</td></tr>1564<tr><td colspan="4" class="doc" id="coroutineBodyStmt0"><pre>Matches coroutine body statements.1565 1566coroutineBodyStmt() matches the coroutine below1567 generator<int> gen() {1568 co_return;1569 }1570</pre></td></tr>1571 1572 1573<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('coyieldExpr0')"><a name="coyieldExpr0Anchor">coyieldExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CoyieldExpr.html">CoyieldExpr</a>>...</td></tr>1574<tr><td colspan="4" class="doc" id="coyieldExpr0"><pre>Matches co_yield expressions.1575 1576Given1577 co_yield 1;1578coyieldExpr()1579 matches 'co_yield 1'1580</pre></td></tr>1581 1582 1583<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cudaKernelCallExpr0')"><a name="cudaKernelCallExpr0Anchor">cudaKernelCallExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CUDAKernelCallExpr.html">CUDAKernelCallExpr</a>>...</td></tr>1584<tr><td colspan="4" class="doc" id="cudaKernelCallExpr0"><pre>Matches CUDA kernel call expression.1585 1586Example matches,1587 kernel<<<i,j>>>();1588</pre></td></tr>1589 1590 1591<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxBindTemporaryExpr0')"><a name="cxxBindTemporaryExpr0Anchor">cxxBindTemporaryExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBindTemporaryExpr.html">CXXBindTemporaryExpr</a>>...</td></tr>1592<tr><td colspan="4" class="doc" id="cxxBindTemporaryExpr0"><pre>Matches nodes where temporaries are created.1593 1594Example matches FunctionTakesString(GetStringByValue())1595 (matcher = cxxBindTemporaryExpr())1596 FunctionTakesString(GetStringByValue());1597 FunctionTakesStringByPointer(GetStringPointer());1598</pre></td></tr>1599 1600 1601<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxBoolLiteral0')"><a name="cxxBoolLiteral0Anchor">cxxBoolLiteral</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBoolLiteralExpr.html">CXXBoolLiteralExpr</a>>...</td></tr>1602<tr><td colspan="4" class="doc" id="cxxBoolLiteral0"><pre>Matches bool literals.1603 1604Example matches true1605 true1606</pre></td></tr>1607 1608 1609<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxCatchStmt0')"><a name="cxxCatchStmt0Anchor">cxxCatchStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCatchStmt.html">CXXCatchStmt</a>>...</td></tr>1610<tr><td colspan="4" class="doc" id="cxxCatchStmt0"><pre>Matches catch statements.1611 1612 try {} catch(int i) {}1613cxxCatchStmt()1614 matches 'catch(int i)'1615</pre></td></tr>1616 1617 1618<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxConstCastExpr0')"><a name="cxxConstCastExpr0Anchor">cxxConstCastExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstCastExpr.html">CXXConstCastExpr</a>>...</td></tr>1619<tr><td colspan="4" class="doc" id="cxxConstCastExpr0"><pre>Matches a const_cast expression.1620 1621Example: Matches const_cast<int*>(&r) in1622 int n = 42;1623 const int &r(n);1624 int* p = const_cast<int*>(&r);1625</pre></td></tr>1626 1627 1628<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxConstructExpr0')"><a name="cxxConstructExpr0Anchor">cxxConstructExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>...</td></tr>1629<tr><td colspan="4" class="doc" id="cxxConstructExpr0"><pre>Matches constructor call expressions (including implicit ones).1630 1631Example matches string(ptr, n) and ptr within arguments of f1632 (matcher = cxxConstructExpr())1633 void f(const string &a, const string &b);1634 char *ptr;1635 int n;1636 f(string(ptr, n), ptr);1637</pre></td></tr>1638 1639 1640<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxDefaultArgExpr0')"><a name="cxxDefaultArgExpr0Anchor">cxxDefaultArgExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXDefaultArgExpr.html">CXXDefaultArgExpr</a>>...</td></tr>1641<tr><td colspan="4" class="doc" id="cxxDefaultArgExpr0"><pre>Matches the value of a default argument at the call site.1642 1643Example matches the CXXDefaultArgExpr placeholder inserted for the1644 default value of the second parameter in the call expression f(42)1645 (matcher = cxxDefaultArgExpr())1646 void f(int x, int y = 0);1647 f(42);1648</pre></td></tr>1649 1650 1651<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxDeleteExpr0')"><a name="cxxDeleteExpr0Anchor">cxxDeleteExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXDeleteExpr.html">CXXDeleteExpr</a>>...</td></tr>1652<tr><td colspan="4" class="doc" id="cxxDeleteExpr0"><pre>Matches delete expressions.1653 1654Given1655 delete X;1656cxxDeleteExpr()1657 matches 'delete X'.1658</pre></td></tr>1659 1660 1661<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxDependentScopeMemberExpr0')"><a name="cxxDependentScopeMemberExpr0Anchor">cxxDependentScopeMemberExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXDependentScopeMemberExpr.html">CXXDependentScopeMemberExpr</a>>...</td></tr>1662<tr><td colspan="4" class="doc" id="cxxDependentScopeMemberExpr0"><pre>Matches member expressions where the actual member referenced could not be1663resolved because the base expression or the member name was dependent.1664 1665Given1666 template <class T> void f() { T t; t.g(); }1667cxxDependentScopeMemberExpr()1668 matches t.g1669</pre></td></tr>1670 1671 1672<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxDynamicCastExpr0')"><a name="cxxDynamicCastExpr0Anchor">cxxDynamicCastExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXDynamicCastExpr.html">CXXDynamicCastExpr</a>>...</td></tr>1673<tr><td colspan="4" class="doc" id="cxxDynamicCastExpr0"><pre>Matches a dynamic_cast expression.1674 1675Example:1676 cxxDynamicCastExpr()1677matches1678 dynamic_cast<D*>(&b);1679in1680 struct B { virtual ~B() {} }; struct D : B {};1681 B b;1682 D* p = dynamic_cast<D*>(&b);1683</pre></td></tr>1684 1685 1686<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxFoldExpr0')"><a name="cxxFoldExpr0Anchor">cxxFoldExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFoldExpr.html">CXXFoldExpr</a>>...</td></tr>1687<tr><td colspan="4" class="doc" id="cxxFoldExpr0"><pre>Matches C++17 fold expressions.1688 1689Example matches `(0 + ... + args)`:1690 template <typename... Args>1691 auto sum(Args... args) {1692 return (0 + ... + args);1693 }1694</pre></td></tr>1695 1696 1697<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxForRangeStmt0')"><a name="cxxForRangeStmt0Anchor">cxxForRangeStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXForRangeStmt.html">CXXForRangeStmt</a>>...</td></tr>1698<tr><td colspan="4" class="doc" id="cxxForRangeStmt0"><pre>Matches range-based for statements.1699 1700cxxForRangeStmt() matches 'for (auto a : i)'1701 int i[] = {1, 2, 3}; for (auto a : i);1702 for(int j = 0; j < 5; ++j);1703</pre></td></tr>1704 1705 1706<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxFunctionalCastExpr0')"><a name="cxxFunctionalCastExpr0Anchor">cxxFunctionalCastExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFunctionalCastExpr.html">CXXFunctionalCastExpr</a>>...</td></tr>1707<tr><td colspan="4" class="doc" id="cxxFunctionalCastExpr0"><pre>Matches functional cast expressions1708 1709Example: Matches Foo(bar);1710 Foo f = bar;1711 Foo g = (Foo) bar;1712 Foo h = Foo(bar);1713</pre></td></tr>1714 1715 1716<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxMemberCallExpr0')"><a name="cxxMemberCallExpr0Anchor">cxxMemberCallExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMemberCallExpr.html">CXXMemberCallExpr</a>>...</td></tr>1717<tr><td colspan="4" class="doc" id="cxxMemberCallExpr0"><pre>Matches member call expressions.1718 1719Example matches x.y()1720 X x;1721 x.y();1722</pre></td></tr>1723 1724 1725<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxNamedCastExpr0')"><a name="cxxNamedCastExpr0Anchor">cxxNamedCastExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNamedCastExpr.html">CXXNamedCastExpr</a>>...</td></tr>1726<tr><td colspan="4" class="doc" id="cxxNamedCastExpr0"><pre>Matches any named cast expression.1727 1728Example: Matches all four of the casts in1729 struct S { virtual void f(); };1730 S* p = nullptr;1731 S* ptr1 = static_cast<S*>(p);1732 S* ptr2 = reinterpret_cast<S*>(p);1733 S* ptr3 = dynamic_cast<S*>(p);1734 S* ptr4 = const_cast<S*>(p);1735</pre></td></tr>1736 1737 1738<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxNewExpr0')"><a name="cxxNewExpr0Anchor">cxxNewExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>...</td></tr>1739<tr><td colspan="4" class="doc" id="cxxNewExpr0"><pre>Matches new expressions.1740 1741Given1742 new X;1743cxxNewExpr()1744 matches 'new X'.1745</pre></td></tr>1746 1747 1748<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxNoexceptExpr0')"><a name="cxxNoexceptExpr0Anchor">cxxNoexceptExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNoexceptExpr.html">CXXNoexceptExpr</a>>...</td></tr>1749<tr><td colspan="4" class="doc" id="cxxNoexceptExpr0"><pre>Matches noexcept expressions.1750 1751Given1752 bool a() noexcept;1753 bool b() noexcept(true);1754 bool c() noexcept(false);1755 bool d() noexcept(noexcept(a()));1756 bool e = noexcept(b()) || noexcept(c());1757cxxNoexceptExpr()1758 matches `noexcept(a())`, `noexcept(b())` and `noexcept(c())`.1759 doesn't match the noexcept specifier in the declarations a, b, c or d.1760</pre></td></tr>1761 1762 1763<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxNullPtrLiteralExpr0')"><a name="cxxNullPtrLiteralExpr0Anchor">cxxNullPtrLiteralExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNullPtrLiteralExpr.html">CXXNullPtrLiteralExpr</a>>...</td></tr>1764<tr><td colspan="4" class="doc" id="cxxNullPtrLiteralExpr0"><pre>Matches nullptr literal.1765</pre></td></tr>1766 1767 1768<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxOperatorCallExpr0')"><a name="cxxOperatorCallExpr0Anchor">cxxOperatorCallExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>>...</td></tr>1769<tr><td colspan="4" class="doc" id="cxxOperatorCallExpr0"><pre>Matches overloaded operator calls.1770 1771Note that if an operator isn't overloaded, it won't match. Instead, use1772binaryOperator matcher.1773Currently it does not match operators such as new delete.1774FIXME: figure out why these do not match?1775 1776Example matches both operator<<((o << b), c) and operator<<(o, b)1777 (matcher = cxxOperatorCallExpr())1778 ostream &operator<< (ostream &out, int i) { };1779 ostream &o; int b = 1, c = 1;1780 o << b << c;1781See also the binaryOperation() matcher for more-general matching of binary1782uses of this AST node.1783</pre></td></tr>1784 1785 1786<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxReinterpretCastExpr0')"><a name="cxxReinterpretCastExpr0Anchor">cxxReinterpretCastExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXReinterpretCastExpr.html">CXXReinterpretCastExpr</a>>...</td></tr>1787<tr><td colspan="4" class="doc" id="cxxReinterpretCastExpr0"><pre>Matches a reinterpret_cast expression.1788 1789Either the source expression or the destination type can be matched1790using has(), but hasDestinationType() is more specific and can be1791more readable.1792 1793Example matches reinterpret_cast<char*>(&p) in1794 void* p = reinterpret_cast<char*>(&p);1795</pre></td></tr>1796 1797 1798<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxRewrittenBinaryOperator0')"><a name="cxxRewrittenBinaryOperator0Anchor">cxxRewrittenBinaryOperator</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRewrittenBinaryOperator.html">CXXRewrittenBinaryOperator</a>>...</td></tr>1799<tr><td colspan="4" class="doc" id="cxxRewrittenBinaryOperator0"><pre>Matches rewritten binary operators1800 1801Example matches use of "<":1802 #include <compare>1803 struct HasSpaceshipMem {1804 int a;1805 constexpr auto operator<=>(const HasSpaceshipMem&) const = default;1806 };1807 void compare() {1808 HasSpaceshipMem hs1, hs2;1809 if (hs1 < hs2)1810 return;1811 }1812See also the binaryOperation() matcher for more-general matching1813of this AST node.1814</pre></td></tr>1815 1816 1817<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxStaticCastExpr0')"><a name="cxxStaticCastExpr0Anchor">cxxStaticCastExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXStaticCastExpr.html">CXXStaticCastExpr</a>>...</td></tr>1818<tr><td colspan="4" class="doc" id="cxxStaticCastExpr0"><pre>Matches a C++ static_cast expression.1819 1820See also: hasDestinationType1821See also: reinterpretCast1822 1823Example:1824 cxxStaticCastExpr()1825matches1826 static_cast<long>(8)1827in1828 long eight(static_cast<long>(8));1829</pre></td></tr>1830 1831 1832<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxStdInitializerListExpr0')"><a name="cxxStdInitializerListExpr0Anchor">cxxStdInitializerListExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXStdInitializerListExpr.html">CXXStdInitializerListExpr</a>>...</td></tr>1833<tr><td colspan="4" class="doc" id="cxxStdInitializerListExpr0"><pre>Matches C++ initializer list expressions.1834 1835Given1836 std::vector<int> a({ 1, 2, 3 });1837 std::vector<int> b = { 4, 5 };1838 int c[] = { 6, 7 };1839 std::pair<int, int> d = { 8, 9 };1840cxxStdInitializerListExpr()1841 matches "{ 1, 2, 3 }" and "{ 4, 5 }"1842</pre></td></tr>1843 1844 1845<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxTemporaryObjectExpr0')"><a name="cxxTemporaryObjectExpr0Anchor">cxxTemporaryObjectExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXTemporaryObjectExpr.html">CXXTemporaryObjectExpr</a>>...</td></tr>1846<tr><td colspan="4" class="doc" id="cxxTemporaryObjectExpr0"><pre>Matches functional cast expressions having N != 1 arguments1847 1848Example: Matches Foo(bar, bar)1849 Foo h = Foo(bar, bar);1850</pre></td></tr>1851 1852 1853<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxThisExpr0')"><a name="cxxThisExpr0Anchor">cxxThisExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXThisExpr.html">CXXThisExpr</a>>...</td></tr>1854<tr><td colspan="4" class="doc" id="cxxThisExpr0"><pre>Matches implicit and explicit this expressions.1855 1856Example matches the implicit this expression in "return i".1857 (matcher = cxxThisExpr())1858struct foo {1859 int i;1860 int f() { return i; }1861};1862</pre></td></tr>1863 1864 1865<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxThrowExpr0')"><a name="cxxThrowExpr0Anchor">cxxThrowExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXThrowExpr.html">CXXThrowExpr</a>>...</td></tr>1866<tr><td colspan="4" class="doc" id="cxxThrowExpr0"><pre>Matches throw expressions.1867 1868 try { throw 5; } catch(int i) {}1869cxxThrowExpr()1870 matches 'throw 5'1871</pre></td></tr>1872 1873 1874<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxTryStmt0')"><a name="cxxTryStmt0Anchor">cxxTryStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXTryStmt.html">CXXTryStmt</a>>...</td></tr>1875<tr><td colspan="4" class="doc" id="cxxTryStmt0"><pre>Matches try statements.1876 1877 try {} catch(int i) {}1878cxxTryStmt()1879 matches 'try {}'1880</pre></td></tr>1881 1882 1883<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxUnresolvedConstructExpr0')"><a name="cxxUnresolvedConstructExpr0Anchor">cxxUnresolvedConstructExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXUnresolvedConstructExpr.html">CXXUnresolvedConstructExpr</a>>...</td></tr>1884<tr><td colspan="4" class="doc" id="cxxUnresolvedConstructExpr0"><pre>Matches unresolved constructor call expressions.1885 1886Example matches T(t) in return statement of f1887 (matcher = cxxUnresolvedConstructExpr())1888 template <typename T>1889 void f(const T& t) { return T(t); }1890</pre></td></tr>1891 1892 1893<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('declRefExpr0')"><a name="declRefExpr0Anchor">declRefExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>...</td></tr>1894<tr><td colspan="4" class="doc" id="declRefExpr0"><pre>Matches expressions that refer to declarations.1895 1896Example matches x in if (x)1897 bool x;1898 if (x) {}1899</pre></td></tr>1900 1901 1902<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('declStmt0')"><a name="declStmt0Anchor">declStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html">DeclStmt</a>>...</td></tr>1903<tr><td colspan="4" class="doc" id="declStmt0"><pre>Matches declaration statements.1904 1905Given1906 int a;1907declStmt()1908 matches 'int a'.1909</pre></td></tr>1910 1911 1912<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('defaultStmt0')"><a name="defaultStmt0Anchor">defaultStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DefaultStmt.html">DefaultStmt</a>>...</td></tr>1913<tr><td colspan="4" class="doc" id="defaultStmt0"><pre>Matches default statements inside switch statements.1914 1915Given1916 switch(a) { case 42: break; default: break; }1917defaultStmt()1918 matches 'default:'.1919</pre></td></tr>1920 1921 1922<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('dependentCoawaitExpr0')"><a name="dependentCoawaitExpr0Anchor">dependentCoawaitExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DependentCoawaitExpr.html">DependentCoawaitExpr</a>>...</td></tr>1923<tr><td colspan="4" class="doc" id="dependentCoawaitExpr0"><pre>Matches co_await expressions where the type of the promise is dependent1924</pre></td></tr>1925 1926 1927<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('dependentScopeDeclRefExpr0')"><a name="dependentScopeDeclRefExpr0Anchor">dependentScopeDeclRefExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DependentScopeDeclRefExpr.html">DependentScopeDeclRefExpr</a>>...</td></tr>1928<tr><td colspan="4" class="doc" id="dependentScopeDeclRefExpr0"><pre>Matches expressions that refer to dependent scope declarations.1929 1930example matches T::v;1931 template <class T> class X : T { void f() { T::v; } };1932</pre></td></tr>1933 1934 1935<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('designatedInitExpr0')"><a name="designatedInitExpr0Anchor">designatedInitExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DesignatedInitExpr.html">DesignatedInitExpr</a>>...</td></tr>1936<tr><td colspan="4" class="doc" id="designatedInitExpr0"><pre>Matches C99 designated initializer expressions [C99 6.7.8].1937 1938Example: Matches { [2].y = 1.0, [0].x = 1.0 }1939 point ptarray[10] = { [2].y = 1.0, [0].x = 1.0 };1940</pre></td></tr>1941 1942 1943<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('doStmt0')"><a name="doStmt0Anchor">doStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DoStmt.html">DoStmt</a>>...</td></tr>1944<tr><td colspan="4" class="doc" id="doStmt0"><pre>Matches do statements.1945 1946Given1947 do {} while (true);1948doStmt()1949 matches 'do {} while(true)'1950</pre></td></tr>1951 1952 1953<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('explicitCastExpr0')"><a name="explicitCastExpr0Anchor">explicitCastExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ExplicitCastExpr.html">ExplicitCastExpr</a>>...</td></tr>1954<tr><td colspan="4" class="doc" id="explicitCastExpr0"><pre>Matches explicit cast expressions.1955 1956Matches any cast expression written in user code, whether it be a1957C-style cast, a functional-style cast, or a keyword cast.1958 1959Does not match implicit conversions.1960 1961Note: the name "explicitCast" is chosen to match Clang's terminology, as1962Clang uses the term "cast" to apply to implicit conversions as well as to1963actual cast expressions.1964 1965See also: hasDestinationType.1966 1967Example: matches all five of the casts in1968 int((int)(reinterpret_cast<int>(static_cast<int>(const_cast<int>(42)))))1969but does not match the implicit conversion in1970 long ell = 42;1971</pre></td></tr>1972 1973 1974<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('expr0')"><a name="expr0Anchor">expr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>>...</td></tr>1975<tr><td colspan="4" class="doc" id="expr0"><pre>Matches expressions.1976 1977Example matches x()1978 void f() { x(); }1979</pre></td></tr>1980 1981 1982<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('exprWithCleanups0')"><a name="exprWithCleanups0Anchor">exprWithCleanups</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ExprWithCleanups.html">ExprWithCleanups</a>>...</td></tr>1983<tr><td colspan="4" class="doc" id="exprWithCleanups0"><pre>Matches expressions that introduce cleanups to be run at the end1984of the sub-expression's evaluation.1985 1986Example matches std::string()1987 const std::string str = std::string();1988</pre></td></tr>1989 1990 1991<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('fixedPointLiteral0')"><a name="fixedPointLiteral0Anchor">fixedPointLiteral</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FixedPointLiteral.html">FixedPointLiteral</a>>...</td></tr>1992<tr><td colspan="4" class="doc" id="fixedPointLiteral0"><pre>Matches fixed-point literals eg.19930.5r, 0.5hr, 0.5lr, 0.5uhr, 0.5ur, 0.5ulr19941.0k, 1.0hk, 1.0lk, 1.0uhk, 1.0uk, 1.0ulk1995Exponents 1.0e10k1996Hexadecimal numbers 0x0.2p2r1997 1998Does not match implicit conversions such as first two lines:1999 short _Accum sa = 2;2000 _Accum a = 12.5;2001 _Accum b = 1.25hk;2002 _Fract c = 0.25hr;2003 _Fract v = 0.35uhr;2004 _Accum g = 1.45uhk;2005 _Accum decexp1 = 1.575e1k;2006 2007The matcher matches2008but does not2009match and from the code block.2010</pre></td></tr>2011 2012 2013<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('floatLiteral0')"><a name="floatLiteral0Anchor">floatLiteral</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>>...</td></tr>2014<tr><td colspan="4" class="doc" id="floatLiteral0"><pre>Matches float literals of all sizes / encodings, e.g.20151.0, 1.0f, 1.0L and 1e10.2016 2017Does not match implicit conversions such as2018 float a = 10;2019</pre></td></tr>2020 2021 2022<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('forStmt0')"><a name="forStmt0Anchor">forStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ForStmt.html">ForStmt</a>>...</td></tr>2023<tr><td colspan="4" class="doc" id="forStmt0"><pre>Matches for statements.2024 2025Example matches 'for (;;) {}'2026 for (;;) {}2027 int i[] = {1, 2, 3}; for (auto a : i);2028</pre></td></tr>2029 2030 2031<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('genericSelectionExpr0')"><a name="genericSelectionExpr0Anchor">genericSelectionExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1GenericSelectionExpr.html">GenericSelectionExpr</a>>...</td></tr>2032<tr><td colspan="4" class="doc" id="genericSelectionExpr0"><pre>Matches C11 _Generic expression.2033</pre></td></tr>2034 2035 2036<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('gnuNullExpr0')"><a name="gnuNullExpr0Anchor">gnuNullExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1GNUNullExpr.html">GNUNullExpr</a>>...</td></tr>2037<tr><td colspan="4" class="doc" id="gnuNullExpr0"><pre>Matches GNU __null expression.2038</pre></td></tr>2039 2040 2041<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('gotoStmt0')"><a name="gotoStmt0Anchor">gotoStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1GotoStmt.html">GotoStmt</a>>...</td></tr>2042<tr><td colspan="4" class="doc" id="gotoStmt0"><pre>Matches goto statements.2043 2044Given2045 goto FOO;2046 FOO: bar();2047gotoStmt()2048 matches 'goto FOO'2049</pre></td></tr>2050 2051 2052<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('ifStmt0')"><a name="ifStmt0Anchor">ifStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IfStmt.html">IfStmt</a>>...</td></tr>2053<tr><td colspan="4" class="doc" id="ifStmt0"><pre>Matches if statements.2054 2055Example matches 'if (x) {}'2056 if (x) {}2057</pre></td></tr>2058 2059 2060<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('imaginaryLiteral0')"><a name="imaginaryLiteral0Anchor">imaginaryLiteral</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ImaginaryLiteral.html">ImaginaryLiteral</a>>...</td></tr>2061<tr><td colspan="4" class="doc" id="imaginaryLiteral0"><pre>Matches imaginary literals, which are based on integer and floating2062point literals e.g.: 1i, 1.0i2063</pre></td></tr>2064 2065 2066<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('implicitCastExpr0')"><a name="implicitCastExpr0Anchor">implicitCastExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ImplicitCastExpr.html">ImplicitCastExpr</a>>...</td></tr>2067<tr><td colspan="4" class="doc" id="implicitCastExpr0"><pre>Matches the implicit cast nodes of Clang's AST.2068 2069This matches many different places, including function call return value2070eliding, as well as any type conversions.2071</pre></td></tr>2072 2073 2074<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('implicitValueInitExpr0')"><a name="implicitValueInitExpr0Anchor">implicitValueInitExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ImplicitValueInitExpr.html">ImplicitValueInitExpr</a>>...</td></tr>2075<tr><td colspan="4" class="doc" id="implicitValueInitExpr0"><pre>Matches implicit initializers of init list expressions.2076 2077Given2078 point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };2079implicitValueInitExpr()2080 matches "[0].y" (implicitly)2081</pre></td></tr>2082 2083 2084<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('initListExpr0')"><a name="initListExpr0Anchor">initListExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1InitListExpr.html">InitListExpr</a>>...</td></tr>2085<tr><td colspan="4" class="doc" id="initListExpr0"><pre>Matches init list expressions.2086 2087Given2088 int a[] = { 1, 2 };2089 struct B { int x, y; };2090 B b = { 5, 6 };2091initListExpr()2092 matches "{ 1, 2 }" and "{ 5, 6 }"2093</pre></td></tr>2094 2095 2096<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('integerLiteral0')"><a name="integerLiteral0Anchor">integerLiteral</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>>...</td></tr>2097<tr><td colspan="4" class="doc" id="integerLiteral0"><pre>Matches integer literals of all sizes / encodings, e.g.20981, 1L, 0x1 and 1U.2099 2100Does not match character-encoded integers such as L'a'.2101</pre></td></tr>2102 2103 2104<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('labelStmt0')"><a name="labelStmt0Anchor">labelStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>...</td></tr>2105<tr><td colspan="4" class="doc" id="labelStmt0"><pre>Matches label statements.2106 2107Given2108 goto FOO;2109 FOO: bar();2110labelStmt()2111 matches 'FOO:'2112</pre></td></tr>2113 2114 2115<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('lambdaExpr0')"><a name="lambdaExpr0Anchor">lambdaExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LambdaExpr.html">LambdaExpr</a>>...</td></tr>2116<tr><td colspan="4" class="doc" id="lambdaExpr0"><pre>Matches lambda expressions.2117 2118Example matches [&](){return 5;}2119 [&](){return 5;}2120</pre></td></tr>2121 2122 2123<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('materializeTemporaryExpr0')"><a name="materializeTemporaryExpr0Anchor">materializeTemporaryExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MaterializeTemporaryExpr.html">MaterializeTemporaryExpr</a>>...</td></tr>2124<tr><td colspan="4" class="doc" id="materializeTemporaryExpr0"><pre>Matches nodes where temporaries are materialized.2125 2126Example: Given2127 struct T {void func();};2128 T f();2129 void g(T);2130materializeTemporaryExpr() matches 'f()' in these statements2131 T u(f());2132 g(f());2133 f().func();2134but does not match2135 f();2136</pre></td></tr>2137 2138 2139<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('memberExpr0')"><a name="memberExpr0Anchor">memberExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>...</td></tr>2140<tr><td colspan="4" class="doc" id="memberExpr0"><pre>Matches member expressions.2141 2142Given2143 class Y {2144 void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; }2145 int a; static int b;2146 };2147memberExpr()2148 matches this->x, x, y.x, a, this->b2149</pre></td></tr>2150 2151 2152<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('nullStmt0')"><a name="nullStmt0Anchor">nullStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NullStmt.html">NullStmt</a>>...</td></tr>2153<tr><td colspan="4" class="doc" id="nullStmt0"><pre>Matches null statements.2154 2155 foo();;2156nullStmt()2157 matches the second ';'2158</pre></td></tr>2159 2160 2161<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('objcCatchStmt0')"><a name="objcCatchStmt0Anchor">objcCatchStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCAtCatchStmt.html">ObjCAtCatchStmt</a>>...</td></tr>2162<tr><td colspan="4" class="doc" id="objcCatchStmt0"><pre>Matches Objective-C @catch statements.2163 2164Example matches @catch2165 @try {}2166 @catch (...) {}2167</pre></td></tr>2168 2169 2170<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('objcFinallyStmt0')"><a name="objcFinallyStmt0Anchor">objcFinallyStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCAtFinallyStmt.html">ObjCAtFinallyStmt</a>>...</td></tr>2171<tr><td colspan="4" class="doc" id="objcFinallyStmt0"><pre>Matches Objective-C @finally statements.2172 2173Example matches @finally2174 @try {}2175 @finally {}2176</pre></td></tr>2177 2178 2179<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('objcIvarRefExpr0')"><a name="objcIvarRefExpr0Anchor">objcIvarRefExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCIvarRefExpr.html">ObjCIvarRefExpr</a>>...</td></tr>2180<tr><td colspan="4" class="doc" id="objcIvarRefExpr0"><pre>Matches a reference to an ObjCIvar.2181 2182Example: matches "a" in "init" method:2183@implementation A {2184 NSString *a;2185}2186- (void) init {2187 a = @"hello";2188}2189</pre></td></tr>2190 2191 2192<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('objcMessageExpr0')"><a name="objcMessageExpr0Anchor">objcMessageExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>>...</td></tr>2193<tr><td colspan="4" class="doc" id="objcMessageExpr0"><pre>Matches ObjectiveC Message invocation expressions.2194 2195The innermost message send invokes the "alloc" class method on the2196NSString class, while the outermost message send invokes the2197"initWithString" instance method on the object returned from2198NSString's "alloc". This matcher should match both message sends.2199 [[NSString alloc] initWithString:@"Hello"]2200</pre></td></tr>2201 2202 2203<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('objcStringLiteral0')"><a name="objcStringLiteral0Anchor">objcStringLiteral</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCStringLiteral.html">ObjCStringLiteral</a>>...</td></tr>2204<tr><td colspan="4" class="doc" id="objcStringLiteral0"><pre>Matches ObjectiveC String literal expressions.2205 2206Example matches @"abcd"2207 NSString *s = @"abcd";2208</pre></td></tr>2209 2210 2211<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('objcThrowStmt0')"><a name="objcThrowStmt0Anchor">objcThrowStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCAtThrowStmt.html">ObjCAtThrowStmt</a>>...</td></tr>2212<tr><td colspan="4" class="doc" id="objcThrowStmt0"><pre>Matches Objective-C statements.2213 2214Example matches @throw obj;2215</pre></td></tr>2216 2217 2218<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('objcTryStmt0')"><a name="objcTryStmt0Anchor">objcTryStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCAtTryStmt.html">ObjCAtTryStmt</a>>...</td></tr>2219<tr><td colspan="4" class="doc" id="objcTryStmt0"><pre>Matches Objective-C @try statements.2220 2221Example matches @try2222 @try {}2223 @catch (...) {}2224</pre></td></tr>2225 2226 2227<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('ompExecutableDirective0')"><a name="ompExecutableDirective0Anchor">ompExecutableDirective</a></td><td>Matcher<OMPExecutableDirective>...</td></tr>2228<tr><td colspan="4" class="doc" id="ompExecutableDirective0"><pre>Matches any ``#pragma omp`` executable directive.2229 2230Given2231 2232 #pragma omp parallel2233 #pragma omp parallel default(none)2234 #pragma omp taskyield2235 2236``ompExecutableDirective()`` matches ``omp parallel``,2237``omp parallel default(none)`` and ``omp taskyield``.2238</pre></td></tr>2239 2240 2241<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('opaqueValueExpr0')"><a name="opaqueValueExpr0Anchor">opaqueValueExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OpaqueValueExpr.html">OpaqueValueExpr</a>>...</td></tr>2242<tr><td colspan="4" class="doc" id="opaqueValueExpr0"><pre>Matches opaque value expressions. They are used as helpers2243to reference another expressions and can be met2244in BinaryConditionalOperators, for example.2245 2246Example matches 'a'2247 (a ?: c) + 42;2248</pre></td></tr>2249 2250 2251<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('parenExpr0')"><a name="parenExpr0Anchor">parenExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ParenExpr.html">ParenExpr</a>>...</td></tr>2252<tr><td colspan="4" class="doc" id="parenExpr0"><pre>Matches parentheses used in expressions.2253 2254Example matches (foo() + 1)2255 int foo() { return 1; }2256 int a = (foo() + 1);2257</pre></td></tr>2258 2259 2260<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('parenListExpr0')"><a name="parenListExpr0Anchor">parenListExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ParenListExpr.html">ParenListExpr</a>>...</td></tr>2261<tr><td colspan="4" class="doc" id="parenListExpr0"><pre>Matches paren list expressions.2262ParenListExprs don't have a predefined type and are used for late parsing.2263In the final AST, they can be met in template declarations.2264 2265Given2266 template<typename T> class X {2267 void f() {2268 X x(*this);2269 int a = 0, b = 1; int i = (a, b);2270 }2271 };2272parenListExpr() matches "*this" but NOT matches (a, b) because (a, b)2273has a predefined type and is a ParenExpr, not a ParenListExpr.2274</pre></td></tr>2275 2276 2277<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('predefinedExpr0')"><a name="predefinedExpr0Anchor">predefinedExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1PredefinedExpr.html">PredefinedExpr</a>>...</td></tr>2278<tr><td colspan="4" class="doc" id="predefinedExpr0"><pre>Matches predefined identifier expressions [C99 6.4.2.2].2279 2280Example: Matches __func__2281 printf("%s", __func__);2282</pre></td></tr>2283 2284 2285<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('returnStmt0')"><a name="returnStmt0Anchor">returnStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ReturnStmt.html">ReturnStmt</a>>...</td></tr>2286<tr><td colspan="4" class="doc" id="returnStmt0"><pre>Matches return statements.2287 2288Given2289 return 1;2290returnStmt()2291 matches 'return 1'2292</pre></td></tr>2293 2294 2295<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('stmt0')"><a name="stmt0Anchor">stmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>>...</td></tr>2296<tr><td colspan="4" class="doc" id="stmt0"><pre>Matches statements.2297 2298Given2299 { ++a; }2300stmt()2301 matches both the compound statement '{ ++a; }' and '++a'.2302</pre></td></tr>2303 2304 2305<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('stmtExpr0')"><a name="stmtExpr0Anchor">stmtExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1StmtExpr.html">StmtExpr</a>>...</td></tr>2306<tr><td colspan="4" class="doc" id="stmtExpr0"><pre>Matches statement expression (GNU extension).2307 2308Example match: ({ int X = 4; X; })2309 int C = ({ int X = 4; X; });2310</pre></td></tr>2311 2312 2313<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('stringLiteral0')"><a name="stringLiteral0Anchor">stringLiteral</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1StringLiteral.html">StringLiteral</a>>...</td></tr>2314<tr><td colspan="4" class="doc" id="stringLiteral0"><pre>Matches string literals (also matches wide string literals).2315 2316Example matches "abcd", L"abcd"2317 char *s = "abcd";2318 wchar_t *ws = L"abcd";2319</pre></td></tr>2320 2321 2322<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('substNonTypeTemplateParmExpr0')"><a name="substNonTypeTemplateParmExpr0Anchor">substNonTypeTemplateParmExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1SubstNonTypeTemplateParmExpr.html">SubstNonTypeTemplateParmExpr</a>>...</td></tr>2323<tr><td colspan="4" class="doc" id="substNonTypeTemplateParmExpr0"><pre>Matches substitutions of non-type template parameters.2324 2325Given2326 template <int N>2327 struct A { static const int n = N; };2328 struct B : public A<42> {};2329substNonTypeTemplateParmExpr()2330 matches "N" in the right-hand side of "static const int n = N;"2331</pre></td></tr>2332 2333 2334<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('switchCase0')"><a name="switchCase0Anchor">switchCase</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1SwitchCase.html">SwitchCase</a>>...</td></tr>2335<tr><td colspan="4" class="doc" id="switchCase0"><pre>Matches case and default statements inside switch statements.2336 2337Given2338 switch(a) { case 42: break; default: break; }2339switchCase()2340 matches 'case 42:' and 'default:'.2341</pre></td></tr>2342 2343 2344<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('switchStmt0')"><a name="switchStmt0Anchor">switchStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1SwitchStmt.html">SwitchStmt</a>>...</td></tr>2345<tr><td colspan="4" class="doc" id="switchStmt0"><pre>Matches switch statements.2346 2347Given2348 switch(a) { case 42: break; default: break; }2349switchStmt()2350 matches 'switch(a)'.2351</pre></td></tr>2352 2353 2354<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('unaryExprOrTypeTraitExpr0')"><a name="unaryExprOrTypeTraitExpr0Anchor">unaryExprOrTypeTraitExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html">UnaryExprOrTypeTraitExpr</a>>...</td></tr>2355<tr><td colspan="4" class="doc" id="unaryExprOrTypeTraitExpr0"><pre>Matches sizeof (C99), alignof (C++11) and vec_step (OpenCL)2356 2357Given2358 Foo x = bar;2359 int y = sizeof(x) + alignof(x);2360unaryExprOrTypeTraitExpr()2361 matches sizeof(x) and alignof(x)2362</pre></td></tr>2363 2364 2365<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('unaryOperator0')"><a name="unaryOperator0Anchor">unaryOperator</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnaryOperator.html">UnaryOperator</a>>...</td></tr>2366<tr><td colspan="4" class="doc" id="unaryOperator0"><pre>Matches unary operator expressions.2367 2368Example matches !a2369 !a || b2370</pre></td></tr>2371 2372 2373<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('unresolvedLookupExpr0')"><a name="unresolvedLookupExpr0Anchor">unresolvedLookupExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedLookupExpr.html">UnresolvedLookupExpr</a>>...</td></tr>2374<tr><td colspan="4" class="doc" id="unresolvedLookupExpr0"><pre>Matches reference to a name that can be looked up during parsing2375but could not be resolved to a specific declaration.2376 2377Given2378 template<typename T>2379 T foo() { T a; return a; }2380 template<typename T>2381 void bar() {2382 foo<T>();2383 }2384unresolvedLookupExpr()2385 matches foo<T>() </pre></td></tr>2386 2387 2388<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('unresolvedMemberExpr0')"><a name="unresolvedMemberExpr0Anchor">unresolvedMemberExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedMemberExpr.html">UnresolvedMemberExpr</a>>...</td></tr>2389<tr><td colspan="4" class="doc" id="unresolvedMemberExpr0"><pre>Matches unresolved member expressions.2390 2391Given2392 struct X {2393 template <class T> void f();2394 void g();2395 };2396 template <class T> void h() { X x; x.f<T>(); x.g(); }2397unresolvedMemberExpr()2398 matches x.f<T>2399</pre></td></tr>2400 2401 2402<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('userDefinedLiteral0')"><a name="userDefinedLiteral0Anchor">userDefinedLiteral</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UserDefinedLiteral.html">UserDefinedLiteral</a>>...</td></tr>2403<tr><td colspan="4" class="doc" id="userDefinedLiteral0"><pre>Matches user defined literal operator call.2404 2405Example match: "foo"_suffix2406</pre></td></tr>2407 2408 2409<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('whileStmt0')"><a name="whileStmt0Anchor">whileStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1WhileStmt.html">WhileStmt</a>>...</td></tr>2410<tr><td colspan="4" class="doc" id="whileStmt0"><pre>Matches while statements.2411 2412Given2413 while (true) {}2414whileStmt()2415 matches 'while (true) {}'.2416</pre></td></tr>2417 2418 2419<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgumentLoc.html">TemplateArgumentLoc</a>></td><td class="name" onclick="toggle('templateArgumentLoc0')"><a name="templateArgumentLoc0Anchor">templateArgumentLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgumentLoc.html">TemplateArgumentLoc</a>>...</td></tr>2420<tr><td colspan="4" class="doc" id="templateArgumentLoc0"><pre>Matches template arguments (with location info).2421 2422Given2423 template <typename T> struct C {};2424 C<int> c;2425templateArgumentLoc()2426 matches 'int' in C<int>.2427</pre></td></tr>2428 2429 2430<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>></td><td class="name" onclick="toggle('templateArgument0')"><a name="templateArgument0Anchor">templateArgument</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>>...</td></tr>2431<tr><td colspan="4" class="doc" id="templateArgument0"><pre>Matches template arguments.2432 2433Given2434 template <typename T> struct C {};2435 C<int> c;2436templateArgument()2437 matches 'int' in C<int>.2438</pre></td></tr>2439 2440 2441<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateName.html">TemplateName</a>></td><td class="name" onclick="toggle('templateName0')"><a name="templateName0Anchor">templateName</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateName.html">TemplateName</a>>...</td></tr>2442<tr><td colspan="4" class="doc" id="templateName0"><pre>Matches template name.2443 2444Given2445 template <typename T> class X { };2446 X<int> xi;2447templateName()2448 matches 'X' in X<int>.2449</pre></td></tr>2450 2451 2452<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td><td class="name" onclick="toggle('arrayTypeLoc0')"><a name="arrayTypeLoc0Anchor">arrayTypeLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ArrayTypeLoc.html">ArrayTypeLoc</a>>...</td></tr>2453<tr><td colspan="4" class="doc" id="arrayTypeLoc0"><pre>Matches `ArrayTypeLoc`s.2454 2455Given2456 int a[] = {1, 2};2457 int b[3];2458 void f() { int c[a[0]]; }2459arrayTypeLoc()2460 matches "int a[]", "int b[3]" and "int c[a[0]]".2461</pre></td></tr>2462 2463 2464<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td><td class="name" onclick="toggle('pointerTypeLoc0')"><a name="pointerTypeLoc0Anchor">pointerTypeLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1PointerTypeLoc.html">PointerTypeLoc</a>>...</td></tr>2465<tr><td colspan="4" class="doc" id="pointerTypeLoc0"><pre>Matches pointer `TypeLoc`s.2466 2467Given2468 int* x;2469pointerTypeLoc()2470 matches `int*`.2471</pre></td></tr>2472 2473 2474<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td><td class="name" onclick="toggle('qualifiedTypeLoc0')"><a name="qualifiedTypeLoc0Anchor">qualifiedTypeLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualifiedTypeLoc.html">QualifiedTypeLoc</a>>...</td></tr>2475<tr><td colspan="4" class="doc" id="qualifiedTypeLoc0"><pre>Matches `QualifiedTypeLoc`s in the clang AST.2476 2477Given2478 const int x = 0;2479qualifiedTypeLoc()2480 matches `const int`.2481</pre></td></tr>2482 2483 2484<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td><td class="name" onclick="toggle('referenceTypeLoc0')"><a name="referenceTypeLoc0Anchor">referenceTypeLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ReferenceTypeLoc.html">ReferenceTypeLoc</a>>...</td></tr>2485<tr><td colspan="4" class="doc" id="referenceTypeLoc0"><pre>Matches reference `TypeLoc`s.2486 2487Given2488 int x = 3;2489 int& l = x;2490 int&& r = 3;2491referenceTypeLoc()2492 matches `int&` and `int&&`.2493</pre></td></tr>2494 2495 2496<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td><td class="name" onclick="toggle('templateSpecializationTypeLoc0')"><a name="templateSpecializationTypeLoc0Anchor">templateSpecializationTypeLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationTypeLoc.html">TemplateSpecializationTypeLoc</a>>...</td></tr>2497<tr><td colspan="4" class="doc" id="templateSpecializationTypeLoc0"><pre>Matches template specialization `TypeLoc`s.2498 2499Given2500 template <typename T> class C {};2501 C<char> var;2502varDecl(hasTypeLoc(templateSpecializationTypeLoc(typeLoc())))2503 matches `C<char> var`.2504</pre></td></tr>2505 2506 2507<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td><td class="name" onclick="toggle('typeLoc0')"><a name="typeLoc0Anchor">typeLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>>...</td></tr>2508<tr><td colspan="4" class="doc" id="typeLoc0"><pre>Matches TypeLocs in the clang AST.2509</pre></td></tr>2510 2511 2512<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('arrayType0')"><a name="arrayType0Anchor">arrayType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ArrayType.html">ArrayType</a>>...</td></tr>2513<tr><td colspan="4" class="doc" id="arrayType0"><pre>Matches all kinds of arrays.2514 2515Given2516 int a[] = { 2, 3 };2517 int b[4];2518 void f() { int c[a[0]]; }2519arrayType()2520 matches "int a[]", "int b[4]" and "int c[a[0]]";2521</pre></td></tr>2522 2523 2524<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('atomicType0')"><a name="atomicType0Anchor">atomicType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AtomicType.html">AtomicType</a>>...</td></tr>2525<tr><td colspan="4" class="doc" id="atomicType0"><pre>Matches atomic types.2526 2527Given2528 _Atomic(int) i;2529atomicType()2530 matches "_Atomic(int) i"2531</pre></td></tr>2532 2533 2534<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('autoType0')"><a name="autoType0Anchor">autoType</a></td><td>Matcher<AutoType>...</td></tr>2535<tr><td colspan="4" class="doc" id="autoType0"><pre>Matches types nodes representing C++11 auto types.2536 2537Given:2538 auto n = 4;2539 int v[] = { 2, 3 }2540 for (auto i : v) { }2541autoType()2542 matches "auto n" and "auto i"2543</pre></td></tr>2544 2545 2546<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('blockPointerType0')"><a name="blockPointerType0Anchor">blockPointerType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockPointerType.html">BlockPointerType</a>>...</td></tr>2547<tr><td colspan="4" class="doc" id="blockPointerType0"><pre>Matches block pointer types, i.e. types syntactically represented as2548"void (^)(int)".2549 2550The pointee is always required to be a FunctionType.2551</pre></td></tr>2552 2553 2554<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('builtinType0')"><a name="builtinType0Anchor">builtinType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BuiltinType.html">BuiltinType</a>>...</td></tr>2555<tr><td colspan="4" class="doc" id="builtinType0"><pre>Matches builtin Types.2556 2557Given2558 struct A {};2559 A a;2560 int b;2561 float c;2562 bool d;2563builtinType()2564 matches "int b", "float c" and "bool d"2565</pre></td></tr>2566 2567 2568<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('complexType0')"><a name="complexType0Anchor">complexType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ComplexType.html">ComplexType</a>>...</td></tr>2569<tr><td colspan="4" class="doc" id="complexType0"><pre>Matches C99 complex types.2570 2571Given2572 _Complex float f;2573complexType()2574 matches "_Complex float f"2575</pre></td></tr>2576 2577 2578<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('constantArrayType0')"><a name="constantArrayType0Anchor">constantArrayType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ConstantArrayType.html">ConstantArrayType</a>>...</td></tr>2579<tr><td colspan="4" class="doc" id="constantArrayType0"><pre>Matches C arrays with a specified constant size.2580 2581Given2582 void() {2583 int a[2];2584 int b[] = { 2, 3 };2585 int c[b[0]];2586 }2587constantArrayType()2588 matches "int a[2]"2589</pre></td></tr>2590 2591 2592<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('decayedType0')"><a name="decayedType0Anchor">decayedType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DecayedType.html">DecayedType</a>>...</td></tr>2593<tr><td colspan="4" class="doc" id="decayedType0"><pre>Matches decayed type2594Example matches i[] in declaration of f.2595 (matcher = valueDecl(hasType(decayedType(hasDecayedType(pointerType())))))2596Example matches i[1].2597 (matcher = expr(hasType(decayedType(hasDecayedType(pointerType())))))2598 void f(int i[]) {2599 i[1] = 0;2600 }2601</pre></td></tr>2602 2603 2604<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('decltypeType0')"><a name="decltypeType0Anchor">decltypeType</a></td><td>Matcher<DecltypeType>...</td></tr>2605<tr><td colspan="4" class="doc" id="decltypeType0"><pre>Matches types nodes representing C++11 decltype(<expr>) types.2606 2607Given:2608 short i = 1;2609 int j = 42;2610 decltype(i + j) result = i + j;2611decltypeType()2612 matches "decltype(i + j)"2613</pre></td></tr>2614 2615 2616<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('deducedTemplateSpecializationType0')"><a name="deducedTemplateSpecializationType0Anchor">deducedTemplateSpecializationType</a></td><td>Matcher<DeducedTemplateSpecializationType>...</td></tr>2617<tr><td colspan="4" class="doc" id="deducedTemplateSpecializationType0"><pre>Matches C++17 deduced template specialization types, e.g. deduced class2618template types.2619 2620Given2621 template <typename T>2622 class C { public: C(T); };2623 2624 C c(123);2625deducedTemplateSpecializationType() matches the type in the declaration2626of the variable c.2627</pre></td></tr>2628 2629 2630<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('dependentNameType0')"><a name="dependentNameType0Anchor">dependentNameType</a></td><td>Matcher<DependentNameType>...</td></tr>2631<tr><td colspan="4" class="doc" id="dependentNameType0"><pre>Matches a dependent name type2632 2633Example matches T::type2634 template <typename T> struct declToImport {2635 typedef typename T::type dependent_name;2636 };2637</pre></td></tr>2638 2639 2640<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('dependentSizedArrayType0')"><a name="dependentSizedArrayType0Anchor">dependentSizedArrayType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DependentSizedArrayType.html">DependentSizedArrayType</a>>...</td></tr>2641<tr><td colspan="4" class="doc" id="dependentSizedArrayType0"><pre>Matches C++ arrays whose size is a value-dependent expression.2642 2643Given2644 template<typename T, int Size>2645 class array {2646 T data[Size];2647 };2648dependentSizedArrayType()2649 matches "T data[Size]"2650</pre></td></tr>2651 2652 2653<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('dependentSizedExtVectorType0')"><a name="dependentSizedExtVectorType0Anchor">dependentSizedExtVectorType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DependentSizedExtVectorType.html">DependentSizedExtVectorType</a>>...</td></tr>2654<tr><td colspan="4" class="doc" id="dependentSizedExtVectorType0"><pre>Matches C++ extended vector type where either the type or size is2655dependent.2656 2657Given2658 template<typename T, int Size>2659 class vector {2660 typedef T __attribute__((ext_vector_type(Size))) type;2661 };2662dependentSizedExtVectorType()2663 matches "T __attribute__((ext_vector_type(Size)))"2664</pre></td></tr>2665 2666 2667<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('enumType0')"><a name="enumType0Anchor">enumType</a></td><td>Matcher<EnumType>...</td></tr>2668<tr><td colspan="4" class="doc" id="enumType0"><pre>Matches enum types.2669 2670Given2671 enum C { Green };2672 enum class S { Red };2673 2674 C c;2675 S s;2676 2677enumType() matches the type of the variable declarations of both c and2678s.2679</pre></td></tr>2680 2681 2682<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('functionProtoType0')"><a name="functionProtoType0Anchor">functionProtoType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionProtoType.html">FunctionProtoType</a>>...</td></tr>2683<tr><td colspan="4" class="doc" id="functionProtoType0"><pre>Matches FunctionProtoType nodes.2684 2685Given2686 int (*f)(int);2687 void g();2688functionProtoType()2689 matches "int (*f)(int)" and the type of "g" in C++ mode.2690 In C mode, "g" is not matched because it does not contain a prototype.2691</pre></td></tr>2692 2693 2694<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('functionType0')"><a name="functionType0Anchor">functionType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionType.html">FunctionType</a>>...</td></tr>2695<tr><td colspan="4" class="doc" id="functionType0"><pre>Matches FunctionType nodes.2696 2697Given2698 int (*f)(int);2699 void g();2700functionType()2701 matches "int (*f)(int)" and the type of "g".2702</pre></td></tr>2703 2704 2705<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('incompleteArrayType0')"><a name="incompleteArrayType0Anchor">incompleteArrayType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IncompleteArrayType.html">IncompleteArrayType</a>>...</td></tr>2706<tr><td colspan="4" class="doc" id="incompleteArrayType0"><pre>Matches C arrays with unspecified size.2707 2708Given2709 int a[] = { 2, 3 };2710 int b[42];2711 void f(int c[]) { int d[a[0]]; };2712incompleteArrayType()2713 matches "int a[]" and "int c[]"2714</pre></td></tr>2715 2716 2717<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('injectedClassNameType0')"><a name="injectedClassNameType0Anchor">injectedClassNameType</a></td><td>Matcher<InjectedClassNameType>...</td></tr>2718<tr><td colspan="4" class="doc" id="injectedClassNameType0"><pre>Matches injected class name types.2719 2720Example matches S s, but not S<T> s.2721 (matcher = parmVarDecl(hasType(injectedClassNameType())))2722 template <typename T> struct S {2723 void f(S s);2724 void g(S<T> s);2725 };2726</pre></td></tr>2727 2728 2729<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('lValueReferenceType0')"><a name="lValueReferenceType0Anchor">lValueReferenceType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LValueReferenceType.html">LValueReferenceType</a>>...</td></tr>2730<tr><td colspan="4" class="doc" id="lValueReferenceType0"><pre>Matches lvalue reference types.2731 2732Given:2733 int *a;2734 int &b = *a;2735 int &&c = 1;2736 auto &d = b;2737 auto &&e = c;2738 auto &&f = 2;2739 int g = 5;2740 2741lValueReferenceType() matches the types of b, d, and e. e is2742matched since the type is deduced as int& by reference collapsing rules.2743</pre></td></tr>2744 2745 2746<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('macroQualifiedType0')"><a name="macroQualifiedType0Anchor">macroQualifiedType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MacroQualifiedType.html">MacroQualifiedType</a>>...</td></tr>2747<tr><td colspan="4" class="doc" id="macroQualifiedType0"><pre>Matches qualified types when the qualifier is applied via a macro.2748 2749Given2750 #define CDECL __attribute__((cdecl))2751 typedef void (CDECL *X)();2752 typedef void (__attribute__((cdecl)) *Y)();2753macroQualifiedType()2754 matches the type of the typedef declaration of X but not Y.2755</pre></td></tr>2756 2757 2758<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('memberPointerType0')"><a name="memberPointerType0Anchor">memberPointerType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberPointerType.html">MemberPointerType</a>>...</td></tr>2759<tr><td colspan="4" class="doc" id="memberPointerType0"><pre>Matches member pointer types.2760Given2761 struct A { int i; }2762 A::* ptr = A::i;2763memberPointerType()2764 matches "A::* ptr"2765</pre></td></tr>2766 2767 2768<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('objcObjectPointerType0')"><a name="objcObjectPointerType0Anchor">objcObjectPointerType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCObjectPointerType.html">ObjCObjectPointerType</a>>...</td></tr>2769<tr><td colspan="4" class="doc" id="objcObjectPointerType0"><pre>Matches an Objective-C object pointer type, which is different from2770a pointer type, despite being syntactically similar.2771 2772Given2773 int *a;2774 2775 @interface Foo2776 @end2777 Foo *f;2778pointerType()2779 matches "Foo *f", but does not match "int *a".2780</pre></td></tr>2781 2782 2783<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('parenType0')"><a name="parenType0Anchor">parenType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ParenType.html">ParenType</a>>...</td></tr>2784<tr><td colspan="4" class="doc" id="parenType0"><pre>Matches ParenType nodes.2785 2786Given2787 int (*ptr_to_array)[4];2788 int *array_of_ptrs[4];2789 2790varDecl(hasType(pointsTo(parenType()))) matches ptr_to_array but not2791array_of_ptrs.2792</pre></td></tr>2793 2794 2795<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('pointerType0')"><a name="pointerType0Anchor">pointerType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1PointerType.html">PointerType</a>>...</td></tr>2796<tr><td colspan="4" class="doc" id="pointerType0"><pre>Matches pointer types, but does not match Objective-C object pointer2797types.2798 2799Given2800 int *a;2801 int &b = *a;2802 int c = 5;2803 2804 @interface Foo2805 @end2806 Foo *f;2807pointerType()2808 matches "int *a", but does not match "Foo *f".2809</pre></td></tr>2810 2811 2812<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('rValueReferenceType0')"><a name="rValueReferenceType0Anchor">rValueReferenceType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1RValueReferenceType.html">RValueReferenceType</a>>...</td></tr>2813<tr><td colspan="4" class="doc" id="rValueReferenceType0"><pre>Matches rvalue reference types.2814 2815Given:2816 int *a;2817 int &b = *a;2818 int &&c = 1;2819 auto &d = b;2820 auto &&e = c;2821 auto &&f = 2;2822 int g = 5;2823 2824rValueReferenceType() matches the types of c and f. e is not2825matched as it is deduced to int& by reference collapsing rules.2826</pre></td></tr>2827 2828 2829<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('recordType0')"><a name="recordType0Anchor">recordType</a></td><td>Matcher<RecordType>...</td></tr>2830<tr><td colspan="4" class="doc" id="recordType0"><pre>Matches record types (e.g. structs, classes).2831 2832Given2833 class C {};2834 struct S {};2835 2836 C c;2837 S s;2838 2839recordType() matches the type of the variable declarations of both c2840and s.2841</pre></td></tr>2842 2843 2844<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('referenceType0')"><a name="referenceType0Anchor">referenceType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ReferenceType.html">ReferenceType</a>>...</td></tr>2845<tr><td colspan="4" class="doc" id="referenceType0"><pre>Matches both lvalue and rvalue reference types.2846 2847Given2848 int *a;2849 int &b = *a;2850 int &&c = 1;2851 auto &d = b;2852 auto &&e = c;2853 auto &&f = 2;2854 int g = 5;2855 2856referenceType() matches the types of b, c, d, e, and f.2857</pre></td></tr>2858 2859 2860<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('substTemplateTypeParmType0')"><a name="substTemplateTypeParmType0Anchor">substTemplateTypeParmType</a></td><td>Matcher<SubstTemplateTypeParmType>...</td></tr>2861<tr><td colspan="4" class="doc" id="substTemplateTypeParmType0"><pre>Matches types that represent the result of substituting a type for a2862template type parameter.2863 2864Given2865 template <typename T>2866 void F(T t) {2867 int i = 1 + t;2868 }2869 2870substTemplateTypeParmType() matches the type of 't' but not '1'2871</pre></td></tr>2872 2873 2874<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('tagType0')"><a name="tagType0Anchor">tagType</a></td><td>Matcher<TagType>...</td></tr>2875<tr><td colspan="4" class="doc" id="tagType0"><pre>Matches tag types (record and enum types).2876 2877Given2878 enum E {};2879 class C {};2880 2881 E e;2882 C c;2883 2884tagType() matches the type of the variable declarations of both e2885and c.2886</pre></td></tr>2887 2888 2889<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('templateSpecializationType0')"><a name="templateSpecializationType0Anchor">templateSpecializationType</a></td><td>Matcher<TemplateSpecializationType>...</td></tr>2890<tr><td colspan="4" class="doc" id="templateSpecializationType0"><pre>Matches template specialization types.2891 2892Given2893 template <typename T>2894 class C { };2895 2896 template class C<int>; // A2897 C<char> var; // B2898 2899templateSpecializationType() matches the type of the explicit2900instantiation in A and the type of the variable declaration in B.2901</pre></td></tr>2902 2903 2904<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('templateTypeParmType0')"><a name="templateTypeParmType0Anchor">templateTypeParmType</a></td><td>Matcher<TemplateTypeParmType>...</td></tr>2905<tr><td colspan="4" class="doc" id="templateTypeParmType0"><pre>Matches template type parameter types.2906 2907Example matches T, but not int.2908 (matcher = templateTypeParmType())2909 template <typename T> void f(int i);2910</pre></td></tr>2911 2912 2913<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('type0')"><a name="type0Anchor">type</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>>...</td></tr>2914<tr><td colspan="4" class="doc" id="type0"><pre>Matches Types in the clang AST.2915</pre></td></tr>2916 2917 2918<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('typedefType0')"><a name="typedefType0Anchor">typedefType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>...</td></tr>2919<tr><td colspan="4" class="doc" id="typedefType0"><pre>Matches typedef types.2920 2921Given2922 typedef int X;2923typedefType()2924 matches "typedef int X"2925</pre></td></tr>2926 2927 2928<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('unaryTransformType0')"><a name="unaryTransformType0Anchor">unaryTransformType</a></td><td>Matcher<UnaryTransformType>...</td></tr>2929<tr><td colspan="4" class="doc" id="unaryTransformType0"><pre>Matches types nodes representing unary type transformations.2930 2931Given:2932 typedef __underlying_type(T) type;2933unaryTransformType()2934 matches "__underlying_type(T)"2935</pre></td></tr>2936 2937 2938<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('usingType0')"><a name="usingType0Anchor">usingType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingType.html">UsingType</a>>...</td></tr>2939<tr><td colspan="4" class="doc" id="usingType0"><pre>Matches types specified through a using declaration.2940 2941Given2942 namespace a { struct S {}; }2943 using a::S;2944 S s;2945 2946usingType() matches the type of the variable declaration of s.2947</pre></td></tr>2948 2949 2950<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('variableArrayType0')"><a name="variableArrayType0Anchor">variableArrayType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VariableArrayType.html">VariableArrayType</a>>...</td></tr>2951<tr><td colspan="4" class="doc" id="variableArrayType0"><pre>Matches C arrays with a specified size that is not an2952integer-constant-expression.2953 2954Given2955 void f() {2956 int a[] = { 2, 3 }2957 int b[42];2958 int c[a[0]];2959 }2960variableArrayType()2961 matches "int c[a[0]]"2962</pre></td></tr>2963 2964<!--END_DECL_MATCHERS -->2965</table>2966 2967<!-- ======================================================================= -->2968<h2 id="narrowing-matchers">Narrowing Matchers</h2>2969<!-- ======================================================================= -->2970 2971<p>Narrowing matchers match certain attributes on the current node, thus2972narrowing down the set of nodes of the current type to match on.</p>2973 2974<p>There are special logical narrowing matchers (allOf, anyOf, anything and unless)2975which allow users to create more powerful match expressions.</p>2976 2977<table>2978<tr style="text-align:left"><th>Return type</th><th>Name</th><th>Parameters</th></tr>2979<!-- START_NARROWING_MATCHERS -->2980 2981<tr><td>Matcher<*></td><td class="name" onclick="toggle('allOf0')"><a name="allOf0Anchor">allOf</a></td><td>Matcher<*>, ..., Matcher<*></td></tr>2982<tr><td colspan="4" class="doc" id="allOf0"><pre>Matches if all given matchers match.2983 2984Usable as: Any Matcher2985</pre></td></tr>2986 2987 2988<tr><td>Matcher<*></td><td class="name" onclick="toggle('anyOf0')"><a name="anyOf0Anchor">anyOf</a></td><td>Matcher<*>, ..., Matcher<*></td></tr>2989<tr><td colspan="4" class="doc" id="anyOf0"><pre>Matches if any of the given matchers matches.2990 2991Usable as: Any Matcher2992</pre></td></tr>2993 2994 2995<tr><td>Matcher<*></td><td class="name" onclick="toggle('anything0')"><a name="anything0Anchor">anything</a></td><td></td></tr>2996<tr><td colspan="4" class="doc" id="anything0"><pre>Matches any node.2997 2998Useful when another matcher requires a child matcher, but there's no2999additional constraint. This will often be used with an explicit conversion3000to an internal::Matcher<> type such as TypeMatcher.3001 3002Example: DeclarationMatcher(anything()) matches all declarations, e.g.,3003"int* p" and "void f()" in3004 int* p;3005 void f();3006 3007Usable as: Any Matcher3008</pre></td></tr>3009 3010 3011<tr><td><em>unspecified</em></td><td class="name" onclick="toggle('mapAnyOf0')"><a name="mapAnyOf0Anchor">mapAnyOf</a></td><td>nodeMatcherFunction...</td></tr>3012<tr><td colspan="4" class="doc" id="mapAnyOf0"><pre>Matches any of the NodeMatchers with InnerMatchers nested within3013 3014Given3015 if (true);3016 for (; true; );3017with the matcher3018 mapAnyOf(ifStmt, forStmt).with(3019 hasCondition(cxxBoolLiteralExpr(equals(true)))3020 ).bind("trueCond")3021matches the if and the for. It is equivalent to:3022 auto trueCond = hasCondition(cxxBoolLiteralExpr(equals(true)));3023 anyOf(3024 ifStmt(trueCond).bind("trueCond"),3025 forStmt(trueCond).bind("trueCond")3026 );3027 3028The with() chain-call accepts zero or more matchers which are combined3029as-if with allOf() in each of the node matchers.3030Usable as: Any Matcher3031</pre></td></tr>3032 3033 3034<tr><td>Matcher<*></td><td class="name" onclick="toggle('unless0')"><a name="unless0Anchor">unless</a></td><td>Matcher<*></td></tr>3035<tr><td colspan="4" class="doc" id="unless0"><pre>Matches if the provided matcher does not match.3036 3037Example matches Y (matcher = cxxRecordDecl(unless(hasName("X"))))3038 class X {};3039 class Y {};3040 3041Usable as: Any Matcher3042</pre></td></tr>3043 3044 3045<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Attr.html">Attr</a>></td><td class="name" onclick="toggle('isImplicit1')"><a name="isImplicit1Anchor">isImplicit</a></td><td></td></tr>3046<tr><td colspan="4" class="doc" id="isImplicit1"><pre>Matches an entity that has been implicitly added by the compiler (e.g.3047implicit default/copy constructors).3048</pre></td></tr>3049 3050 3051<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html">BinaryOperator</a>></td><td class="name" onclick="toggle('hasAnyOperatorName0')"><a name="hasAnyOperatorName0Anchor">hasAnyOperatorName</a></td><td>StringRef, ..., StringRef</td></tr>3052<tr><td colspan="4" class="doc" id="hasAnyOperatorName0"><pre>Matches operator expressions (binary or unary) that have any of the3053specified names.3054 3055 hasAnyOperatorName("+", "-")3056 Is equivalent to3057 anyOf(hasOperatorName("+"), hasOperatorName("-"))3058</pre></td></tr>3059 3060 3061<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html">BinaryOperator</a>></td><td class="name" onclick="toggle('hasOperatorName0')"><a name="hasOperatorName0Anchor">hasOperatorName</a></td><td>std::string Name</td></tr>3062<tr><td colspan="4" class="doc" id="hasOperatorName0"><pre>Matches the operator Name of operator expressions and fold expressions3063(binary or unary).3064 3065Example matches a || b (matcher = binaryOperator(hasOperatorName("||")))3066 !(a || b)3067 3068Example matches `(0 + ... + args)`3069 (matcher = cxxFoldExpr(hasOperatorName("+")))3070 template <typename... Args>3071 auto sum(Args... args) {3072 return (0 + ... + args);3073 }3074</pre></td></tr>3075 3076 3077<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html">BinaryOperator</a>></td><td class="name" onclick="toggle('isAssignmentOperator0')"><a name="isAssignmentOperator0Anchor">isAssignmentOperator</a></td><td></td></tr>3078<tr><td colspan="4" class="doc" id="isAssignmentOperator0"><pre>Matches all kinds of assignment operators.3079 3080Example 1: matches a += b (matcher = binaryOperator(isAssignmentOperator()))3081 if (a == b)3082 a += b;3083 3084Example 2: matches s1 = s23085 (matcher = cxxOperatorCallExpr(isAssignmentOperator()))3086 struct S { S& operator=(const S&); };3087 void x() { S s1, s2; s1 = s2; }3088</pre></td></tr>3089 3090 3091<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html">BinaryOperator</a>></td><td class="name" onclick="toggle('isComparisonOperator0')"><a name="isComparisonOperator0Anchor">isComparisonOperator</a></td><td></td></tr>3092<tr><td colspan="4" class="doc" id="isComparisonOperator0"><pre>Matches comparison operators.3093 3094Example 1: matches a == b (matcher = binaryOperator(isComparisonOperator()))3095 if (a == b)3096 a += b;3097 3098Example 2: matches s1 < s23099 (matcher = cxxOperatorCallExpr(isComparisonOperator()))3100 struct S { bool operator<(const S& other); };3101 void x(S s1, S s2) { bool b1 = s1 < s2; }3102</pre></td></tr>3103 3104 3105<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>></td><td class="name" onclick="toggle('isPrivate1')"><a name="isPrivate1Anchor">isPrivate</a></td><td></td></tr>3106<tr><td colspan="4" class="doc" id="isPrivate1"><pre>Matches private C++ declarations and C++ base specifiers that specify3107private inheritance.3108 3109Examples:3110 class C {3111 public: int a;3112 protected: int b;3113 private: int c; // fieldDecl(isPrivate()) matches 'c'3114 };3115 3116 struct Base {};3117 struct Derived1 : private Base {}; // matches 'Base'3118 class Derived2 : Base {}; // matches 'Base'3119</pre></td></tr>3120 3121 3122<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>></td><td class="name" onclick="toggle('isProtected1')"><a name="isProtected1Anchor">isProtected</a></td><td></td></tr>3123<tr><td colspan="4" class="doc" id="isProtected1"><pre>Matches protected C++ declarations and C++ base specifiers that specify3124protected inheritance.3125 3126Examples:3127 class C {3128 public: int a;3129 protected: int b; // fieldDecl(isProtected()) matches 'b'3130 private: int c;3131 };3132 3133 class Base {};3134 class Derived : protected Base {}; // matches 'Base'3135</pre></td></tr>3136 3137 3138<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>></td><td class="name" onclick="toggle('isPublic1')"><a name="isPublic1Anchor">isPublic</a></td><td></td></tr>3139<tr><td colspan="4" class="doc" id="isPublic1"><pre>Matches public C++ declarations and C++ base specifiers that specify public3140inheritance.3141 3142Examples:3143 class C {3144 public: int a; // fieldDecl(isPublic()) matches 'a'3145 protected: int b;3146 private: int c;3147 };3148 3149 class Base {};3150 class Derived1 : public Base {}; // matches 'Base'3151 struct Derived2 : Base {}; // matches 'Base'3152</pre></td></tr>3153 3154 3155<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>></td><td class="name" onclick="toggle('isVirtual1')"><a name="isVirtual1Anchor">isVirtual</a></td><td></td></tr>3156<tr><td colspan="4" class="doc" id="isVirtual1"><pre>Matches declarations of virtual methods and C++ base specifiers that specify3157virtual inheritance.3158 3159Example:3160 class A {3161 public:3162 virtual void x(); // matches x3163 };3164 3165Example:3166 class Base {};3167 class DirectlyDerived : virtual Base {}; // matches Base3168 class IndirectlyDerived : DirectlyDerived, Base {}; // matches Base3169 3170Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>>3171</pre></td></tr>3172 3173 3174<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBoolLiteralExpr.html">CXXBoolLiteralExpr</a>></td><td class="name" onclick="toggle('equals5')"><a name="equals5Anchor">equals</a></td><td>bool Value</td></tr>3175<tr><td colspan="4" class="doc" id="equals5"><pre></pre></td></tr>3176 3177 3178<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBoolLiteralExpr.html">CXXBoolLiteralExpr</a>></td><td class="name" onclick="toggle('equals2')"><a name="equals2Anchor">equals</a></td><td>const ValueT Value</td></tr>3179<tr><td colspan="4" class="doc" id="equals2"><pre>Matches literals that are equal to the given value of type ValueT.3180 3181Given3182 f('false, 3.14, 42);3183characterLiteral(equals(0))3184 matches 'cxxBoolLiteral(equals(false)) and cxxBoolLiteral(equals(0))3185 match false3186floatLiteral(equals(3.14)) and floatLiteral(equals(314e-2))3187 match 3.143188integerLiteral(equals(42))3189 matches 423190 3191Note that you cannot directly match a negative numeric literal because the3192minus sign is not part of the literal: It is a unary operator whose operand3193is the positive numeric literal. Instead, you must use a unaryOperator()3194matcher to match the minus sign:3195 3196unaryOperator(hasOperatorName("-"),3197 hasUnaryOperand(integerLiteral(equals(13))))3198 3199Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBoolLiteralExpr.html">CXXBoolLiteralExpr</a>>,3200 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>>3201</pre></td></tr>3202 3203 3204<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBoolLiteralExpr.html">CXXBoolLiteralExpr</a>></td><td class="name" onclick="toggle('equals11')"><a name="equals11Anchor">equals</a></td><td>double Value</td></tr>3205<tr><td colspan="4" class="doc" id="equals11"><pre></pre></td></tr>3206 3207 3208<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBoolLiteralExpr.html">CXXBoolLiteralExpr</a>></td><td class="name" onclick="toggle('equals8')"><a name="equals8Anchor">equals</a></td><td>unsigned Value</td></tr>3209<tr><td colspan="4" class="doc" id="equals8"><pre></pre></td></tr>3210 3211 3212<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCatchStmt.html">CXXCatchStmt</a>></td><td class="name" onclick="toggle('isCatchAll0')"><a name="isCatchAll0Anchor">isCatchAll</a></td><td></td></tr>3213<tr><td colspan="4" class="doc" id="isCatchAll0"><pre>Matches a C++ catch statement that has a catch-all handler.3214 3215Given3216 try {3217 // ...3218 } catch (int) {3219 // ...3220 } catch (...) {3221 // ...3222 }3223cxxCatchStmt(isCatchAll()) matches catch(...) but not catch(int).3224</pre></td></tr>3225 3226 3227<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>></td><td class="name" onclick="toggle('argumentCountAtLeast1')"><a name="argumentCountAtLeast1Anchor">argumentCountAtLeast</a></td><td>unsigned N</td></tr>3228<tr><td colspan="4" class="doc" id="argumentCountAtLeast1"><pre>Checks that a call expression or a constructor call expression has at least3229the specified number of arguments (including absent default arguments).3230 3231Example matches f(0, 0) and g(0, 0, 0)3232(matcher = callExpr(argumentCountAtLeast(2)))3233 void f(int x, int y);3234 void g(int x, int y, int z);3235 f(0, 0);3236 g(0, 0, 0);3237</pre></td></tr>3238 3239 3240<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>></td><td class="name" onclick="toggle('argumentCountIs1')"><a name="argumentCountIs1Anchor">argumentCountIs</a></td><td>unsigned N</td></tr>3241<tr><td colspan="4" class="doc" id="argumentCountIs1"><pre>Checks that a call expression or a constructor call expression has3242a specific number of arguments (including absent default arguments).3243 3244Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2)))3245 void f(int x, int y);3246 f(0, 0);3247</pre></td></tr>3248 3249 3250<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>></td><td class="name" onclick="toggle('isListInitialization0')"><a name="isListInitialization0Anchor">isListInitialization</a></td><td></td></tr>3251<tr><td colspan="4" class="doc" id="isListInitialization0"><pre>Matches a constructor call expression which uses list initialization.3252</pre></td></tr>3253 3254 3255<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>></td><td class="name" onclick="toggle('requiresZeroInitialization0')"><a name="requiresZeroInitialization0Anchor">requiresZeroInitialization</a></td><td></td></tr>3256<tr><td colspan="4" class="doc" id="requiresZeroInitialization0"><pre>Matches a constructor call expression which requires3257zero initialization.3258 3259Given3260void foo() {3261 struct point { double x; double y; };3262 point pt[2] = { { 1.0, 2.0 } };3263}3264initListExpr(has(cxxConstructExpr(requiresZeroInitialization()))3265will match the implicit array filler for pt[1].3266</pre></td></tr>3267 3268 3269<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html">CXXConstructorDecl</a>></td><td class="name" onclick="toggle('isCopyConstructor0')"><a name="isCopyConstructor0Anchor">isCopyConstructor</a></td><td></td></tr>3270<tr><td colspan="4" class="doc" id="isCopyConstructor0"><pre>Matches constructor declarations that are copy constructors.3271 3272Given3273 struct S {3274 S(); // #13275 S(const S &); // #23276 S(S &&); // #33277 };3278cxxConstructorDecl(isCopyConstructor()) will match #2, but not #1 or #3.3279</pre></td></tr>3280 3281 3282<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html">CXXConstructorDecl</a>></td><td class="name" onclick="toggle('isDefaultConstructor0')"><a name="isDefaultConstructor0Anchor">isDefaultConstructor</a></td><td></td></tr>3283<tr><td colspan="4" class="doc" id="isDefaultConstructor0"><pre>Matches constructor declarations that are default constructors.3284 3285Given3286 struct S {3287 S(); // #13288 S(const S &); // #23289 S(S &&); // #33290 };3291cxxConstructorDecl(isDefaultConstructor()) will match #1, but not #2 or #3.3292</pre></td></tr>3293 3294 3295<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html">CXXConstructorDecl</a>></td><td class="name" onclick="toggle('isDelegatingConstructor0')"><a name="isDelegatingConstructor0Anchor">isDelegatingConstructor</a></td><td></td></tr>3296<tr><td colspan="4" class="doc" id="isDelegatingConstructor0"><pre>Matches constructors that delegate to another constructor.3297 3298Given3299 struct S {3300 S(); // #13301 S(int) {} // #23302 S(S &&) : S() {} // #33303 };3304 S::S() : S(0) {} // #43305cxxConstructorDecl(isDelegatingConstructor()) will match #3 and #4, but not3306#1 or #2.3307</pre></td></tr>3308 3309 3310<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html">CXXConstructorDecl</a>></td><td class="name" onclick="toggle('isExplicit0')"><a name="isExplicit0Anchor">isExplicit</a></td><td></td></tr>3311<tr><td colspan="4" class="doc" id="isExplicit0"><pre>Matches constructor, conversion function, and deduction guide declarations3312that have an explicit specifier if this explicit specifier is resolved to3313true.3314 3315Given3316 template<bool b>3317 struct S {3318 S(int); // #13319 explicit S(double); // #23320 operator int(); // #33321 explicit operator bool(); // #43322 explicit(false) S(bool) // # 73323 explicit(true) S(char) // # 83324 explicit(b) S(S) // # 93325 };3326 S(int) -> S<true> // #53327 explicit S(double) -> S<false> // #63328cxxConstructorDecl(isExplicit()) will match #2 and #8, but not #1, #7 or #9.3329cxxConversionDecl(isExplicit()) will match #4, but not #3.3330cxxDeductionGuideDecl(isExplicit()) will match #6, but not #5.3331</pre></td></tr>3332 3333 3334<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html">CXXConstructorDecl</a>></td><td class="name" onclick="toggle('isInheritingConstructor0')"><a name="isInheritingConstructor0Anchor">isInheritingConstructor</a></td><td></td></tr>3335<tr><td colspan="4" class="doc" id="isInheritingConstructor0"><pre></pre></td></tr>3336 3337 3338<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html">CXXConstructorDecl</a>></td><td class="name" onclick="toggle('isMoveConstructor0')"><a name="isMoveConstructor0Anchor">isMoveConstructor</a></td><td></td></tr>3339<tr><td colspan="4" class="doc" id="isMoveConstructor0"><pre>Matches constructor declarations that are move constructors.3340 3341Given3342 struct S {3343 S(); // #13344 S(const S &); // #23345 S(S &&); // #33346 };3347cxxConstructorDecl(isMoveConstructor()) will match #3, but not #1 or #2.3348</pre></td></tr>3349 3350 3351<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConversionDecl.html">CXXConversionDecl</a>></td><td class="name" onclick="toggle('isExplicit1')"><a name="isExplicit1Anchor">isExplicit</a></td><td></td></tr>3352<tr><td colspan="4" class="doc" id="isExplicit1"><pre>Matches constructor, conversion function, and deduction guide declarations3353that have an explicit specifier if this explicit specifier is resolved to3354true.3355 3356Given3357 template<bool b>3358 struct S {3359 S(int); // #13360 explicit S(double); // #23361 operator int(); // #33362 explicit operator bool(); // #43363 explicit(false) S(bool) // # 73364 explicit(true) S(char) // # 83365 explicit(b) S(S) // # 93366 };3367 S(int) -> S<true> // #53368 explicit S(double) -> S<false> // #63369cxxConstructorDecl(isExplicit()) will match #2 and #8, but not #1, #7 or #9.3370cxxConversionDecl(isExplicit()) will match #4, but not #3.3371cxxDeductionGuideDecl(isExplicit()) will match #6, but not #5.3372</pre></td></tr>3373 3374 3375<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>></td><td class="name" onclick="toggle('isBaseInitializer0')"><a name="isBaseInitializer0Anchor">isBaseInitializer</a></td><td></td></tr>3376<tr><td colspan="4" class="doc" id="isBaseInitializer0"><pre>Matches a constructor initializer if it is initializing a base, as3377opposed to a member.3378 3379Given3380 struct B {};3381 struct D : B {3382 int I;3383 D(int i) : I(i) {}3384 };3385 struct E : B {3386 E() : B() {}3387 };3388cxxConstructorDecl(hasAnyConstructorInitializer(isBaseInitializer()))3389 will match E(), but not match D(int).3390</pre></td></tr>3391 3392 3393<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>></td><td class="name" onclick="toggle('isMemberInitializer0')"><a name="isMemberInitializer0Anchor">isMemberInitializer</a></td><td></td></tr>3394<tr><td colspan="4" class="doc" id="isMemberInitializer0"><pre>Matches a constructor initializer if it is initializing a member, as3395opposed to a base.3396 3397Given3398 struct B {};3399 struct D : B {3400 int I;3401 D(int i) : I(i) {}3402 };3403 struct E : B {3404 E() : B() {}3405 };3406cxxConstructorDecl(hasAnyConstructorInitializer(isMemberInitializer()))3407 will match D(int), but not match E().3408</pre></td></tr>3409 3410 3411<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>></td><td class="name" onclick="toggle('isWritten0')"><a name="isWritten0Anchor">isWritten</a></td><td></td></tr>3412<tr><td colspan="4" class="doc" id="isWritten0"><pre>Matches a constructor initializer if it is explicitly written in3413code (as opposed to implicitly added by the compiler).3414 3415Given3416 struct Foo {3417 Foo() { }3418 Foo(int) : foo_("A") { }3419 string foo_;3420 };3421cxxConstructorDecl(hasAnyConstructorInitializer(isWritten()))3422 will match Foo(int), but not Foo()3423</pre></td></tr>3424 3425 3426<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXDeductionGuideDecl.html">CXXDeductionGuideDecl</a>></td><td class="name" onclick="toggle('isExplicit2')"><a name="isExplicit2Anchor">isExplicit</a></td><td></td></tr>3427<tr><td colspan="4" class="doc" id="isExplicit2"><pre>Matches constructor, conversion function, and deduction guide declarations3428that have an explicit specifier if this explicit specifier is resolved to3429true.3430 3431Given3432 template<bool b>3433 struct S {3434 S(int); // #13435 explicit S(double); // #23436 operator int(); // #33437 explicit operator bool(); // #43438 explicit(false) S(bool) // # 73439 explicit(true) S(char) // # 83440 explicit(b) S(S) // # 93441 };3442 S(int) -> S<true> // #53443 explicit S(double) -> S<false> // #63444cxxConstructorDecl(isExplicit()) will match #2 and #8, but not #1, #7 or #9.3445cxxConversionDecl(isExplicit()) will match #4, but not #3.3446cxxDeductionGuideDecl(isExplicit()) will match #6, but not #5.3447</pre></td></tr>3448 3449 3450<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXDependentScopeMemberExpr.html">CXXDependentScopeMemberExpr</a>></td><td class="name" onclick="toggle('hasMemberName0')"><a name="hasMemberName0Anchor">hasMemberName</a></td><td>std::string N</td></tr>3451<tr><td colspan="4" class="doc" id="hasMemberName0"><pre>Matches template-dependent, but known, member names.3452 3453In template declarations, dependent members are not resolved and so can3454not be matched to particular named declarations.3455 3456This matcher allows to match on the known name of members.3457 3458Given3459 template <typename T>3460 struct S {3461 void mem();3462 };3463 template <typename T>3464 void x() {3465 S<T> s;3466 s.mem();3467 }3468cxxDependentScopeMemberExpr(hasMemberName("mem")) matches `s.mem()`3469</pre></td></tr>3470 3471 3472<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXDependentScopeMemberExpr.html">CXXDependentScopeMemberExpr</a>></td><td class="name" onclick="toggle('isArrow2')"><a name="isArrow2Anchor">isArrow</a></td><td></td></tr>3473<tr><td colspan="4" class="doc" id="isArrow2"><pre>Matches member expressions that are called with '->' as opposed3474to '.'.3475 3476Member calls on the implicit this pointer match as called with '->'.3477 3478Given3479 class Y {3480 void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; }3481 template <class T> void f() { this->f<T>(); f<T>(); }3482 int a;3483 static int b;3484 };3485 template <class T>3486 class Z {3487 void x() { this->m; }3488 };3489memberExpr(isArrow())3490 matches this->x, x, y.x, a, this->b3491cxxDependentScopeMemberExpr(isArrow())3492 matches this->m3493unresolvedMemberExpr(isArrow())3494 matches this->f<T>, f<T>3495</pre></td></tr>3496 3497 3498<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXDependentScopeMemberExpr.html">CXXDependentScopeMemberExpr</a>></td><td class="name" onclick="toggle('memberHasSameNameAsBoundNode0')"><a name="memberHasSameNameAsBoundNode0Anchor">memberHasSameNameAsBoundNode</a></td><td>std::string BindingID</td></tr>3499<tr><td colspan="4" class="doc" id="memberHasSameNameAsBoundNode0"><pre>Matches template-dependent, but known, member names against an already-bound3500node3501 3502In template declarations, dependent members are not resolved and so can3503not be matched to particular named declarations.3504 3505This matcher allows to match on the name of already-bound VarDecl, FieldDecl3506and CXXMethodDecl nodes.3507 3508Given3509 template <typename T>3510 struct S {3511 void mem();3512 };3513 template <typename T>3514 void x() {3515 S<T> s;3516 s.mem();3517 }3518The matcher3519@code3520cxxDependentScopeMemberExpr(3521 hasObjectExpression(declRefExpr(hasType(templateSpecializationType(3522 hasDeclaration(classTemplateDecl(has(cxxRecordDecl(has(3523 cxxMethodDecl(hasName("mem")).bind("templMem")3524 )))))3525 )))),3526 memberHasSameNameAsBoundNode("templMem")3527 )3528@endcode3529first matches and binds the @c mem member of the @c S template, then3530compares its name to the usage in @c s.mem() in the @c x function template3531</pre></td></tr>3532 3533 3534<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFoldExpr.html">CXXFoldExpr</a>></td><td class="name" onclick="toggle('hasOperatorName3')"><a name="hasOperatorName3Anchor">hasOperatorName</a></td><td>std::string Name</td></tr>3535<tr><td colspan="4" class="doc" id="hasOperatorName3"><pre>Matches the operator Name of operator expressions and fold expressions3536(binary or unary).3537 3538Example matches a || b (matcher = binaryOperator(hasOperatorName("||")))3539 !(a || b)3540 3541Example matches `(0 + ... + args)`3542 (matcher = cxxFoldExpr(hasOperatorName("+")))3543 template <typename... Args>3544 auto sum(Args... args) {3545 return (0 + ... + args);3546 }3547</pre></td></tr>3548 3549 3550<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFoldExpr.html">CXXFoldExpr</a>></td><td class="name" onclick="toggle('isBinaryFold0')"><a name="isBinaryFold0Anchor">isBinaryFold</a></td><td></td></tr>3551<tr><td colspan="4" class="doc" id="isBinaryFold0"><pre>Matches binary fold expressions, i.e. fold expressions with an initializer.3552 3553Example matches `(0 + ... + args)`3554 (matcher = cxxFoldExpr(isBinaryFold()))3555 template <typename... Args>3556 auto sum(Args... args) {3557 return (0 + ... + args);3558 }3559 3560 template <typename... Args>3561 auto multiply(Args... args) {3562 return (args * ...);3563 }3564</pre></td></tr>3565 3566 3567<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFoldExpr.html">CXXFoldExpr</a>></td><td class="name" onclick="toggle('isLeftFold0')"><a name="isLeftFold0Anchor">isLeftFold</a></td><td></td></tr>3568<tr><td colspan="4" class="doc" id="isLeftFold0"><pre>Matches left-folding fold expressions.3569 3570Example matches `(0 + ... + args)`3571 (matcher = cxxFoldExpr(isLeftFold()))3572 template <typename... Args>3573 auto sum(Args... args) {3574 return (0 + ... + args);3575 }3576 3577 template <typename... Args>3578 auto multiply(Args... args) {3579 return (args * ... * 1);3580 }3581</pre></td></tr>3582 3583 3584<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFoldExpr.html">CXXFoldExpr</a>></td><td class="name" onclick="toggle('isRightFold0')"><a name="isRightFold0Anchor">isRightFold</a></td><td></td></tr>3585<tr><td colspan="4" class="doc" id="isRightFold0"><pre>Matches right-folding fold expressions.3586 3587Example matches `(args * ... * 1)`3588 (matcher = cxxFoldExpr(isRightFold()))3589 template <typename... Args>3590 auto sum(Args... args) {3591 return (0 + ... + args);3592 }3593 3594 template <typename... Args>3595 auto multiply(Args... args) {3596 return (args * ... * 1);3597 }3598</pre></td></tr>3599 3600 3601<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFoldExpr.html">CXXFoldExpr</a>></td><td class="name" onclick="toggle('isUnaryFold0')"><a name="isUnaryFold0Anchor">isUnaryFold</a></td><td></td></tr>3602<tr><td colspan="4" class="doc" id="isUnaryFold0"><pre>Matches unary fold expressions, i.e. fold expressions without an3603initializer.3604 3605Example matches `(args * ...)`3606 (matcher = cxxFoldExpr(isUnaryFold()))3607 template <typename... Args>3608 auto sum(Args... args) {3609 return (0 + ... + args);3610 }3611 3612 template <typename... Args>3613 auto multiply(Args... args) {3614 return (args * ...);3615 }3616</pre></td></tr>3617 3618 3619<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('isConst0')"><a name="isConst0Anchor">isConst</a></td><td></td></tr>3620<tr><td colspan="4" class="doc" id="isConst0"><pre>Matches if the given method declaration is const.3621 3622Given3623struct A {3624 void foo() const;3625 void bar();3626};3627 3628cxxMethodDecl(isConst()) matches A::foo() but not A::bar()3629</pre></td></tr>3630 3631 3632<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('isCopyAssignmentOperator0')"><a name="isCopyAssignmentOperator0Anchor">isCopyAssignmentOperator</a></td><td></td></tr>3633<tr><td colspan="4" class="doc" id="isCopyAssignmentOperator0"><pre>Matches if the given method declaration declares a copy assignment3634operator.3635 3636Given3637struct A {3638 A &operator=(const A &);3639 A &operator=(A &&);3640};3641 3642cxxMethodDecl(isCopyAssignmentOperator()) matches the first method but not3643the second one.3644</pre></td></tr>3645 3646 3647<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('isExplicitObjectMemberFunction0')"><a name="isExplicitObjectMemberFunction0Anchor">isExplicitObjectMemberFunction</a></td><td></td></tr>3648<tr><td colspan="4" class="doc" id="isExplicitObjectMemberFunction0"><pre>Matches if the given method declaration declares a member function with an3649explicit object parameter.3650 3651Given3652struct A {3653 int operator-(this A, int);3654 void fun(this A &&self);3655 static int operator()(int);3656 int operator+(int);3657};3658 3659cxxMethodDecl(isExplicitObjectMemberFunction()) matches the first two3660methods but not the last two.3661</pre></td></tr>3662 3663 3664<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('isFinal1')"><a name="isFinal1Anchor">isFinal</a></td><td></td></tr>3665<tr><td colspan="4" class="doc" id="isFinal1"><pre>Matches if the given method or class declaration is final.3666 3667Given:3668 class A final {};3669 3670 struct B {3671 virtual void f();3672 };3673 3674 struct C : B {3675 void f() final;3676 };3677matches A and C::f, but not B, C, or B::f3678</pre></td></tr>3679 3680 3681<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('isMoveAssignmentOperator0')"><a name="isMoveAssignmentOperator0Anchor">isMoveAssignmentOperator</a></td><td></td></tr>3682<tr><td colspan="4" class="doc" id="isMoveAssignmentOperator0"><pre>Matches if the given method declaration declares a move assignment3683operator.3684 3685Given3686struct A {3687 A &operator=(const A &);3688 A &operator=(A &&);3689};3690 3691cxxMethodDecl(isMoveAssignmentOperator()) matches the second method but not3692the first one.3693</pre></td></tr>3694 3695 3696<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('isOverride0')"><a name="isOverride0Anchor">isOverride</a></td><td></td></tr>3697<tr><td colspan="4" class="doc" id="isOverride0"><pre>Matches if the given method declaration overrides another method.3698 3699Given3700 class A {3701 public:3702 virtual void x();3703 };3704 class B : public A {3705 public:3706 virtual void x();3707 };3708 matches B::x3709</pre></td></tr>3710 3711 3712<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('isPure0')"><a name="isPure0Anchor">isPure</a></td><td></td></tr>3713<tr><td colspan="4" class="doc" id="isPure0"><pre>Matches if the given method declaration is pure.3714 3715Given3716 class A {3717 public:3718 virtual void x() = 0;3719 };3720 matches A::x3721</pre></td></tr>3722 3723 3724<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('isUserProvided0')"><a name="isUserProvided0Anchor">isUserProvided</a></td><td></td></tr>3725<tr><td colspan="4" class="doc" id="isUserProvided0"><pre>Matches method declarations that are user-provided.3726 3727Given3728 struct S {3729 S(); // #13730 S(const S &) = default; // #23731 S(S &&) = delete; // #33732 };3733cxxConstructorDecl(isUserProvided()) will match #1, but not #2 or #3.3734</pre></td></tr>3735 3736 3737<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('isVirtual0')"><a name="isVirtual0Anchor">isVirtual</a></td><td></td></tr>3738<tr><td colspan="4" class="doc" id="isVirtual0"><pre>Matches declarations of virtual methods and C++ base specifiers that specify3739virtual inheritance.3740 3741Example:3742 class A {3743 public:3744 virtual void x(); // matches x3745 };3746 3747Example:3748 class Base {};3749 class DirectlyDerived : virtual Base {}; // matches Base3750 class IndirectlyDerived : DirectlyDerived, Base {}; // matches Base3751 3752Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>>3753</pre></td></tr>3754 3755 3756<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('isVirtualAsWritten0')"><a name="isVirtualAsWritten0Anchor">isVirtualAsWritten</a></td><td></td></tr>3757<tr><td colspan="4" class="doc" id="isVirtualAsWritten0"><pre>Matches if the given method declaration has an explicit "virtual".3758 3759Given3760 class A {3761 public:3762 virtual void x();3763 };3764 class B : public A {3765 public:3766 void x();3767 };3768 matches A::x but not B::x3769</pre></td></tr>3770 3771 3772<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>></td><td class="name" onclick="toggle('isArray0')"><a name="isArray0Anchor">isArray</a></td><td></td></tr>3773<tr><td colspan="4" class="doc" id="isArray0"><pre>Matches array new expressions.3774 3775Given:3776 MyClass *p1 = new MyClass[10];3777cxxNewExpr(isArray())3778 matches the expression 'new MyClass[10]'.3779</pre></td></tr>3780 3781 3782<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>></td><td class="name" onclick="toggle('hasAnyOperatorName1')"><a name="hasAnyOperatorName1Anchor">hasAnyOperatorName</a></td><td>StringRef, ..., StringRef</td></tr>3783<tr><td colspan="4" class="doc" id="hasAnyOperatorName1"><pre>Matches operator expressions (binary or unary) that have any of the3784specified names.3785 3786 hasAnyOperatorName("+", "-")3787 Is equivalent to3788 anyOf(hasOperatorName("+"), hasOperatorName("-"))3789</pre></td></tr>3790 3791 3792<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>></td><td class="name" onclick="toggle('hasAnyOverloadedOperatorName0')"><a name="hasAnyOverloadedOperatorName0Anchor">hasAnyOverloadedOperatorName</a></td><td>StringRef, ..., StringRef</td></tr>3793<tr><td colspan="4" class="doc" id="hasAnyOverloadedOperatorName0"><pre>Matches overloaded operator names.3794 3795Matches overloaded operator names specified in strings without the3796"operator" prefix: e.g. "<<".3797 3798 hasAnyOverloadedOperatorName("+", "-")3799Is equivalent to3800 anyOf(hasOverloadedOperatorName("+"), hasOverloadedOperatorName("-"))3801</pre></td></tr>3802 3803 3804<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>></td><td class="name" onclick="toggle('hasOperatorName1')"><a name="hasOperatorName1Anchor">hasOperatorName</a></td><td>std::string Name</td></tr>3805<tr><td colspan="4" class="doc" id="hasOperatorName1"><pre>Matches the operator Name of operator expressions and fold expressions3806(binary or unary).3807 3808Example matches a || b (matcher = binaryOperator(hasOperatorName("||")))3809 !(a || b)3810 3811Example matches `(0 + ... + args)`3812 (matcher = cxxFoldExpr(hasOperatorName("+")))3813 template <typename... Args>3814 auto sum(Args... args) {3815 return (0 + ... + args);3816 }3817</pre></td></tr>3818 3819 3820<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>></td><td class="name" onclick="toggle('hasOverloadedOperatorName1')"><a name="hasOverloadedOperatorName1Anchor">hasOverloadedOperatorName</a></td><td>StringRef Name</td></tr>3821<tr><td colspan="4" class="doc" id="hasOverloadedOperatorName1"><pre>Matches overloaded operator names.3822 3823Matches overloaded operator names specified in strings without the3824"operator" prefix: e.g. "<<".3825 3826Given:3827 class A { int operator*(); };3828 const A &operator<<(const A &a, const A &b);3829 A a;3830 a << a; // <-- This matches3831 3832cxxOperatorCallExpr(hasOverloadedOperatorName("<<"))) matches the3833specified line and3834cxxRecordDecl(hasMethod(hasOverloadedOperatorName("*")))3835matches the declaration of A.3836 3837Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>3838</pre></td></tr>3839 3840 3841<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>></td><td class="name" onclick="toggle('isAssignmentOperator1')"><a name="isAssignmentOperator1Anchor">isAssignmentOperator</a></td><td></td></tr>3842<tr><td colspan="4" class="doc" id="isAssignmentOperator1"><pre>Matches all kinds of assignment operators.3843 3844Example 1: matches a += b (matcher = binaryOperator(isAssignmentOperator()))3845 if (a == b)3846 a += b;3847 3848Example 2: matches s1 = s23849 (matcher = cxxOperatorCallExpr(isAssignmentOperator()))3850 struct S { S& operator=(const S&); };3851 void x() { S s1, s2; s1 = s2; }3852</pre></td></tr>3853 3854 3855<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>></td><td class="name" onclick="toggle('isComparisonOperator1')"><a name="isComparisonOperator1Anchor">isComparisonOperator</a></td><td></td></tr>3856<tr><td colspan="4" class="doc" id="isComparisonOperator1"><pre>Matches comparison operators.3857 3858Example 1: matches a == b (matcher = binaryOperator(isComparisonOperator()))3859 if (a == b)3860 a += b;3861 3862Example 2: matches s1 < s23863 (matcher = cxxOperatorCallExpr(isComparisonOperator()))3864 struct S { bool operator<(const S& other); };3865 void x(S s1, S s2) { bool b1 = s1 < s2; }3866</pre></td></tr>3867 3868 3869<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('hasDefinition0')"><a name="hasDefinition0Anchor">hasDefinition</a></td><td></td></tr>3870<tr><td colspan="4" class="doc" id="hasDefinition0"><pre>Matches a class declaration that is defined.3871 3872Example matches x (matcher = cxxRecordDecl(hasDefinition()))3873class x {};3874class y;3875</pre></td></tr>3876 3877 3878<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isDerivedFrom2')"><a name="isDerivedFrom2Anchor">isDerivedFrom</a></td><td>std::string BaseName</td></tr>3879<tr><td colspan="4" class="doc" id="isDerivedFrom2"><pre>Overloaded method as shortcut for isDerivedFrom(hasName(...)).3880</pre></td></tr>3881 3882 3883<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isDirectlyDerivedFrom2')"><a name="isDirectlyDerivedFrom2Anchor">isDirectlyDerivedFrom</a></td><td>std::string BaseName</td></tr>3884<tr><td colspan="4" class="doc" id="isDirectlyDerivedFrom2"><pre>Overloaded method as shortcut for isDirectlyDerivedFrom(hasName(...)).3885</pre></td></tr>3886 3887 3888<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isExplicitTemplateSpecialization2')"><a name="isExplicitTemplateSpecialization2Anchor">isExplicitTemplateSpecialization</a></td><td></td></tr>3889<tr><td colspan="4" class="doc" id="isExplicitTemplateSpecialization2"><pre>Matches explicit template specializations of function, class, or3890static member variable template instantiations.3891 3892Given3893 template<typename T> void A(T t) { }3894 template<> void A(int N) { }3895functionDecl(isExplicitTemplateSpecialization())3896 matches the specialization A<int>().3897 3898Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>>3899</pre></td></tr>3900 3901 3902<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isFinal0')"><a name="isFinal0Anchor">isFinal</a></td><td></td></tr>3903<tr><td colspan="4" class="doc" id="isFinal0"><pre>Matches if the given method or class declaration is final.3904 3905Given:3906 class A final {};3907 3908 struct B {3909 virtual void f();3910 };3911 3912 struct C : B {3913 void f() final;3914 };3915matches A and C::f, but not B, C, or B::f3916</pre></td></tr>3917 3918 3919<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isLambda0')"><a name="isLambda0Anchor">isLambda</a></td><td></td></tr>3920<tr><td colspan="4" class="doc" id="isLambda0"><pre>Matches the generated class of lambda expressions.3921 3922Given:3923 auto x = []{};3924 3925cxxRecordDecl(isLambda()) matches the implicit class declaration of3926decltype(x)3927</pre></td></tr>3928 3929 3930<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isSameOrDerivedFrom2')"><a name="isSameOrDerivedFrom2Anchor">isSameOrDerivedFrom</a></td><td>std::string BaseName</td></tr>3931<tr><td colspan="4" class="doc" id="isSameOrDerivedFrom2"><pre>Overloaded method as shortcut for3932isSameOrDerivedFrom(hasName(...)).3933</pre></td></tr>3934 3935 3936<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isTemplateInstantiation2')"><a name="isTemplateInstantiation2Anchor">isTemplateInstantiation</a></td><td></td></tr>3937<tr><td colspan="4" class="doc" id="isTemplateInstantiation2"><pre>Matches template instantiations of function, class, or static3938member variable template instantiations.3939 3940Given3941 template <typename T> class X {}; class A {}; X<A> x;3942or3943 template <typename T> class X {}; class A {}; template class X<A>;3944or3945 template <typename T> class X {}; class A {}; extern template class X<A>;3946cxxRecordDecl(hasName("::X"), isTemplateInstantiation())3947 matches the template instantiation of X<A>.3948 3949But given3950 template <typename T> class X {}; class A {};3951 template <> class X<A> {}; X<A> x;3952cxxRecordDecl(hasName("::X"), isTemplateInstantiation())3953 does not match, as X<A> is an explicit template specialization.3954 3955Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>>3956</pre></td></tr>3957 3958 3959<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRewrittenBinaryOperator.html">CXXRewrittenBinaryOperator</a>></td><td class="name" onclick="toggle('hasAnyOperatorName2')"><a name="hasAnyOperatorName2Anchor">hasAnyOperatorName</a></td><td>StringRef, ..., StringRef</td></tr>3960<tr><td colspan="4" class="doc" id="hasAnyOperatorName2"><pre>Matches operator expressions (binary or unary) that have any of the3961specified names.3962 3963 hasAnyOperatorName("+", "-")3964 Is equivalent to3965 anyOf(hasOperatorName("+"), hasOperatorName("-"))3966</pre></td></tr>3967 3968 3969<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRewrittenBinaryOperator.html">CXXRewrittenBinaryOperator</a>></td><td class="name" onclick="toggle('hasOperatorName2')"><a name="hasOperatorName2Anchor">hasOperatorName</a></td><td>std::string Name</td></tr>3970<tr><td colspan="4" class="doc" id="hasOperatorName2"><pre>Matches the operator Name of operator expressions and fold expressions3971(binary or unary).3972 3973Example matches a || b (matcher = binaryOperator(hasOperatorName("||")))3974 !(a || b)3975 3976Example matches `(0 + ... + args)`3977 (matcher = cxxFoldExpr(hasOperatorName("+")))3978 template <typename... Args>3979 auto sum(Args... args) {3980 return (0 + ... + args);3981 }3982</pre></td></tr>3983 3984 3985<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRewrittenBinaryOperator.html">CXXRewrittenBinaryOperator</a>></td><td class="name" onclick="toggle('isAssignmentOperator2')"><a name="isAssignmentOperator2Anchor">isAssignmentOperator</a></td><td></td></tr>3986<tr><td colspan="4" class="doc" id="isAssignmentOperator2"><pre>Matches all kinds of assignment operators.3987 3988Example 1: matches a += b (matcher = binaryOperator(isAssignmentOperator()))3989 if (a == b)3990 a += b;3991 3992Example 2: matches s1 = s23993 (matcher = cxxOperatorCallExpr(isAssignmentOperator()))3994 struct S { S& operator=(const S&); };3995 void x() { S s1, s2; s1 = s2; }3996</pre></td></tr>3997 3998 3999<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRewrittenBinaryOperator.html">CXXRewrittenBinaryOperator</a>></td><td class="name" onclick="toggle('isComparisonOperator2')"><a name="isComparisonOperator2Anchor">isComparisonOperator</a></td><td></td></tr>4000<tr><td colspan="4" class="doc" id="isComparisonOperator2"><pre>Matches comparison operators.4001 4002Example 1: matches a == b (matcher = binaryOperator(isComparisonOperator()))4003 if (a == b)4004 a += b;4005 4006Example 2: matches s1 < s24007 (matcher = cxxOperatorCallExpr(isComparisonOperator()))4008 struct S { bool operator<(const S& other); };4009 void x(S s1, S s2) { bool b1 = s1 < s2; }4010</pre></td></tr>4011 4012 4013<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXUnresolvedConstructExpr.html">CXXUnresolvedConstructExpr</a>></td><td class="name" onclick="toggle('argumentCountAtLeast2')"><a name="argumentCountAtLeast2Anchor">argumentCountAtLeast</a></td><td>unsigned N</td></tr>4014<tr><td colspan="4" class="doc" id="argumentCountAtLeast2"><pre>Checks that a call expression or a constructor call expression has at least4015the specified number of arguments (including absent default arguments).4016 4017Example matches f(0, 0) and g(0, 0, 0)4018(matcher = callExpr(argumentCountAtLeast(2)))4019 void f(int x, int y);4020 void g(int x, int y, int z);4021 f(0, 0);4022 g(0, 0, 0);4023</pre></td></tr>4024 4025 4026<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXUnresolvedConstructExpr.html">CXXUnresolvedConstructExpr</a>></td><td class="name" onclick="toggle('argumentCountIs2')"><a name="argumentCountIs2Anchor">argumentCountIs</a></td><td>unsigned N</td></tr>4027<tr><td colspan="4" class="doc" id="argumentCountIs2"><pre>Checks that a call expression or a constructor call expression has4028a specific number of arguments (including absent default arguments).4029 4030Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2)))4031 void f(int x, int y);4032 f(0, 0);4033</pre></td></tr>4034 4035 4036<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>></td><td class="name" onclick="toggle('argumentCountAtLeast0')"><a name="argumentCountAtLeast0Anchor">argumentCountAtLeast</a></td><td>unsigned N</td></tr>4037<tr><td colspan="4" class="doc" id="argumentCountAtLeast0"><pre>Checks that a call expression or a constructor call expression has at least4038the specified number of arguments (including absent default arguments).4039 4040Example matches f(0, 0) and g(0, 0, 0)4041(matcher = callExpr(argumentCountAtLeast(2)))4042 void f(int x, int y);4043 void g(int x, int y, int z);4044 f(0, 0);4045 g(0, 0, 0);4046</pre></td></tr>4047 4048 4049<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>></td><td class="name" onclick="toggle('argumentCountIs0')"><a name="argumentCountIs0Anchor">argumentCountIs</a></td><td>unsigned N</td></tr>4050<tr><td colspan="4" class="doc" id="argumentCountIs0"><pre>Checks that a call expression or a constructor call expression has4051a specific number of arguments (including absent default arguments).4052 4053Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2)))4054 void f(int x, int y);4055 f(0, 0);4056</pre></td></tr>4057 4058 4059<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>></td><td class="name" onclick="toggle('usesADL0')"><a name="usesADL0Anchor">usesADL</a></td><td></td></tr>4060<tr><td colspan="4" class="doc" id="usesADL0"><pre>Matches call expressions which were resolved using ADL.4061 4062Example matches y(x) but not y(42) or NS::y(x).4063 namespace NS {4064 struct X {};4065 void y(X);4066 }4067 4068 void y(...);4069 4070 void test() {4071 NS::X x;4072 y(x); // Matches4073 NS::y(x); // Doesn't match4074 y(42); // Doesn't match4075 using NS::y;4076 y(x); // Found by both unqualified lookup and ADL, doesn't match4077 }4078</pre></td></tr>4079 4080 4081<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CastExpr.html">CastExpr</a>></td><td class="name" onclick="toggle('hasCastKind0')"><a name="hasCastKind0Anchor">hasCastKind</a></td><td>CastKind Kind</td></tr>4082<tr><td colspan="4" class="doc" id="hasCastKind0"><pre>Matches casts that has a given cast kind.4083 4084Example: matches the implicit cast around 04085(matcher = castExpr(hasCastKind(CK_NullToPointer)))4086 int *p = 0;4087 4088If the matcher is use from clang-query, CastKind parameter4089should be passed as a quoted string. e.g., hasCastKind("CK_NullToPointer").4090</pre></td></tr>4091 4092 4093<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>></td><td class="name" onclick="toggle('equals4')"><a name="equals4Anchor">equals</a></td><td>bool Value</td></tr>4094<tr><td colspan="4" class="doc" id="equals4"><pre></pre></td></tr>4095 4096 4097<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>></td><td class="name" onclick="toggle('equals3')"><a name="equals3Anchor">equals</a></td><td>const ValueT Value</td></tr>4098<tr><td colspan="4" class="doc" id="equals3"><pre>Matches literals that are equal to the given value of type ValueT.4099 4100Given4101 f('false, 3.14, 42);4102characterLiteral(equals(0))4103 matches 'cxxBoolLiteral(equals(false)) and cxxBoolLiteral(equals(0))4104 match false4105floatLiteral(equals(3.14)) and floatLiteral(equals(314e-2))4106 match 3.144107integerLiteral(equals(42))4108 matches 424109 4110Note that you cannot directly match a negative numeric literal because the4111minus sign is not part of the literal: It is a unary operator whose operand4112is the positive numeric literal. Instead, you must use a unaryOperator()4113matcher to match the minus sign:4114 4115unaryOperator(hasOperatorName("-"),4116 hasUnaryOperand(integerLiteral(equals(13))))4117 4118Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBoolLiteralExpr.html">CXXBoolLiteralExpr</a>>,4119 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>>4120</pre></td></tr>4121 4122 4123<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>></td><td class="name" onclick="toggle('equals10')"><a name="equals10Anchor">equals</a></td><td>double Value</td></tr>4124<tr><td colspan="4" class="doc" id="equals10"><pre></pre></td></tr>4125 4126 4127<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>></td><td class="name" onclick="toggle('equals7')"><a name="equals7Anchor">equals</a></td><td>unsigned Value</td></tr>4128<tr><td colspan="4" class="doc" id="equals7"><pre></pre></td></tr>4129 4130 4131<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html">ClassTemplateSpecializationDecl</a>></td><td class="name" onclick="toggle('templateArgumentCountIs0')"><a name="templateArgumentCountIs0Anchor">templateArgumentCountIs</a></td><td>unsigned N</td></tr>4132<tr><td colspan="4" class="doc" id="templateArgumentCountIs0"><pre>Matches if the number of template arguments equals N.4133 4134Given4135 template<typename T> struct C {};4136 C<int> c;4137 template<typename T> void f() {}4138 void func() { f<int>(); };4139 4140classTemplateSpecializationDecl(templateArgumentCountIs(1))4141 matches C<int>.4142 4143functionDecl(templateArgumentCountIs(1))4144 matches f<int>();4145</pre></td></tr>4146 4147 4148<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CompoundStmt.html">CompoundStmt</a>></td><td class="name" onclick="toggle('statementCountIs0')"><a name="statementCountIs0Anchor">statementCountIs</a></td><td>unsigned N</td></tr>4149<tr><td colspan="4" class="doc" id="statementCountIs0"><pre>Checks that a compound statement contains a specific number of4150child statements.4151 4152Example: Given4153 { for (;;) {} }4154compoundStmt(statementCountIs(0)))4155 matches '{}'4156 but does not match the outer compound statement.4157</pre></td></tr>4158 4159 4160<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ConstantArrayType.html">ConstantArrayType</a>></td><td class="name" onclick="toggle('hasSize0')"><a name="hasSize0Anchor">hasSize</a></td><td>unsigned N</td></tr>4161<tr><td colspan="4" class="doc" id="hasSize0"><pre>Matches nodes that have the specified size.4162 4163Given4164 int a[42];4165 int b[2 * 21];4166 int c[41], d[43];4167 char *s = "abcd";4168 wchar_t *ws = L"abcd";4169 char *w = "a";4170constantArrayType(hasSize(42))4171 matches "int a[42]" and "int b[2 * 21]"4172stringLiteral(hasSize(4))4173 matches "abcd", L"abcd"4174</pre></td></tr>4175 4176 4177<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html">DeclStmt</a>></td><td class="name" onclick="toggle('declCountIs0')"><a name="declCountIs0Anchor">declCountIs</a></td><td>unsigned N</td></tr>4178<tr><td colspan="4" class="doc" id="declCountIs0"><pre>Matches declaration statements that contain a specific number of4179declarations.4180 4181Example: Given4182 int a, b;4183 int c;4184 int d = 2, e;4185declCountIs(2)4186 matches 'int a, b;' and 'int d = 2, e;', but not 'int c;'.4187</pre></td></tr>4188 4189 4190<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('declaresSameEntityAsBoundNode0')"><a name="declaresSameEntityAsBoundNode0Anchor">declaresSameEntityAsBoundNode</a></td><td>std::string ID</td></tr>4191<tr><td colspan="4" class="doc" id="declaresSameEntityAsBoundNode0"><pre>Matches a declaration if it declares the same entity as the node previously4192bound to ID.4193</pre></td></tr>4194 4195 4196<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('equalsBoundNode1')"><a name="equalsBoundNode1Anchor">equalsBoundNode</a></td><td>std::string ID</td></tr>4197<tr><td colspan="4" class="doc" id="equalsBoundNode1"><pre>Matches if a node equals a previously bound node.4198 4199Matches a node if it equals the node previously bound to ID.4200 4201Given4202 class X { int a; int b; };4203cxxRecordDecl(4204 has(fieldDecl(hasName("a"), hasType(type().bind("t")))),4205 has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t"))))))4206 matches the class X, as a and b have the same type.4207 4208Note that when multiple matches are involved via forEach* matchers,4209equalsBoundNodes acts as a filter.4210For example:4211compoundStmt(4212 forEachDescendant(varDecl().bind("d")),4213 forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d"))))))4214will trigger a match for each combination of variable declaration4215and reference to that variable declaration within a compound statement.4216</pre></td></tr>4217 4218 4219<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('equalsNode0')"><a name="equalsNode0Anchor">equalsNode</a></td><td>const Decl* Other</td></tr>4220<tr><td colspan="4" class="doc" id="equalsNode0"><pre>Matches if a node equals another node.4221 4222Decl has pointer identity in the AST.4223</pre></td></tr>4224 4225 4226<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('hasAttr0')"><a name="hasAttr0Anchor">hasAttr</a></td><td>attr::Kind AttrKind</td></tr>4227<tr><td colspan="4" class="doc" id="hasAttr0"><pre>Matches declaration that has a given attribute.4228 4229Given4230 __attribute__((device)) void f() { ... }4231decl(hasAttr(clang::attr::CUDADevice)) matches the function declaration of4232f. If the matcher is used from clang-query, attr::Kind parameter should be4233passed as a quoted string. e.g., hasAttr("attr::CUDADevice").4234</pre></td></tr>4235 4236 4237<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('isExpandedFromMacro0')"><a name="isExpandedFromMacro0Anchor">isExpandedFromMacro</a></td><td>std::string MacroName</td></tr>4238<tr><td colspan="4" class="doc" id="isExpandedFromMacro0"><pre>Matches statements that are (transitively) expanded from the named macro.4239Does not match if only part of the statement is expanded from that macro or4240if different parts of the statement are expanded from different4241appearances of the macro.4242</pre></td></tr>4243 4244 4245<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('isExpansionInFileMatching0')"><a name="isExpansionInFileMatching0Anchor">isExpansionInFileMatching</a></td><td>StringRef RegExp, Regex::RegexFlags Flags = NoFlags</td></tr>4246<tr><td colspan="4" class="doc" id="isExpansionInFileMatching0"><pre>Matches AST nodes that were expanded within files whose name is4247partially matching a given regex.4248 4249Example matches Y but not X4250 (matcher = cxxRecordDecl(isExpansionInFileMatching("AST.*"))4251 #include "ASTMatcher.h"4252 class X {};4253ASTMatcher.h:4254 class Y {};4255 4256Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>>4257 4258If the matcher is used in clang-query, RegexFlags parameter4259should be passed as a quoted string. e.g: "NoFlags".4260Flags can be combined with '|' example "IgnoreCase | BasicRegex"4261</pre></td></tr>4262 4263 4264<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('isExpansionInMainFile0')"><a name="isExpansionInMainFile0Anchor">isExpansionInMainFile</a></td><td></td></tr>4265<tr><td colspan="4" class="doc" id="isExpansionInMainFile0"><pre>Matches AST nodes that were expanded within the main-file.4266 4267Example matches X but not Y4268 (matcher = cxxRecordDecl(isExpansionInMainFile())4269 #include <Y.h>4270 class X {};4271Y.h:4272 class Y {};4273 4274Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>>4275</pre></td></tr>4276 4277 4278<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('isExpansionInSystemHeader0')"><a name="isExpansionInSystemHeader0Anchor">isExpansionInSystemHeader</a></td><td></td></tr>4279<tr><td colspan="4" class="doc" id="isExpansionInSystemHeader0"><pre>Matches AST nodes that were expanded within system-header-files.4280 4281Example matches Y but not X4282 (matcher = cxxRecordDecl(isExpansionInSystemHeader())4283 #include <SystemHeader.h>4284 class X {};4285SystemHeader.h:4286 class Y {};4287 4288Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>>4289</pre></td></tr>4290 4291 4292<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('isImplicit0')"><a name="isImplicit0Anchor">isImplicit</a></td><td></td></tr>4293<tr><td colspan="4" class="doc" id="isImplicit0"><pre>Matches an entity that has been implicitly added by the compiler (e.g.4294implicit default/copy constructors).4295</pre></td></tr>4296 4297 4298<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('isInAnonymousNamespace0')"><a name="isInAnonymousNamespace0Anchor">isInAnonymousNamespace</a></td><td></td></tr>4299<tr><td colspan="4" class="doc" id="isInAnonymousNamespace0"><pre>Matches declarations in an anonymous namespace.4300 4301Given4302 class vector {};4303 namespace foo {4304 class vector {};4305 namespace {4306 class vector {}; // #14307 }4308 }4309 namespace {4310 class vector {}; // #24311 namespace foo {4312 class vector{}; // #34313 }4314 }4315cxxRecordDecl(hasName("vector"), isInAnonymousNamespace()) will match4316#1, #2 and #3.4317</pre></td></tr>4318 4319 4320<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('isInStdNamespace0')"><a name="isInStdNamespace0Anchor">isInStdNamespace</a></td><td></td></tr>4321<tr><td colspan="4" class="doc" id="isInStdNamespace0"><pre>Matches declarations in the namespace `std`, but not in nested namespaces.4322 4323Given4324 class vector {};4325 namespace foo {4326 class vector {};4327 namespace std {4328 class vector {};4329 }4330 }4331 namespace std {4332 inline namespace __1 {4333 class vector {}; // #14334 namespace experimental {4335 class vector {};4336 }4337 }4338 }4339cxxRecordDecl(hasName("vector"), isInStdNamespace()) will match only #1.4340</pre></td></tr>4341 4342 4343<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('isInstantiated0')"><a name="isInstantiated0Anchor">isInstantiated</a></td><td></td></tr>4344<tr><td colspan="4" class="doc" id="isInstantiated0"><pre>Matches declarations that are template instantiations or are inside4345template instantiations.4346 4347Given4348 template<typename T> void A(T t) { T i; }4349 A(0);4350 A(0U);4351functionDecl(isInstantiated())4352 matches 'A(int) {...};' and 'A(unsigned) {...}'.4353</pre></td></tr>4354 4355 4356<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('isPrivate0')"><a name="isPrivate0Anchor">isPrivate</a></td><td></td></tr>4357<tr><td colspan="4" class="doc" id="isPrivate0"><pre>Matches private C++ declarations and C++ base specifiers that specify4358private inheritance.4359 4360Examples:4361 class C {4362 public: int a;4363 protected: int b;4364 private: int c; // fieldDecl(isPrivate()) matches 'c'4365 };4366 4367 struct Base {};4368 struct Derived1 : private Base {}; // matches 'Base'4369 class Derived2 : Base {}; // matches 'Base'4370</pre></td></tr>4371 4372 4373<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('isProtected0')"><a name="isProtected0Anchor">isProtected</a></td><td></td></tr>4374<tr><td colspan="4" class="doc" id="isProtected0"><pre>Matches protected C++ declarations and C++ base specifiers that specify4375protected inheritance.4376 4377Examples:4378 class C {4379 public: int a;4380 protected: int b; // fieldDecl(isProtected()) matches 'b'4381 private: int c;4382 };4383 4384 class Base {};4385 class Derived : protected Base {}; // matches 'Base'4386</pre></td></tr>4387 4388 4389<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('isPublic0')"><a name="isPublic0Anchor">isPublic</a></td><td></td></tr>4390<tr><td colspan="4" class="doc" id="isPublic0"><pre>Matches public C++ declarations and C++ base specifiers that specify public4391inheritance.4392 4393Examples:4394 class C {4395 public: int a; // fieldDecl(isPublic()) matches 'a'4396 protected: int b;4397 private: int c;4398 };4399 4400 class Base {};4401 class Derived1 : public Base {}; // matches 'Base'4402 struct Derived2 : Base {}; // matches 'Base'4403</pre></td></tr>4404 4405 4406<tr><td>Matcher<DependentNameType></td><td class="name" onclick="toggle('hasDependentName1')"><a name="hasDependentName1Anchor">hasDependentName</a></td><td>std::string N</td></tr>4407<tr><td colspan="4" class="doc" id="hasDependentName1"><pre>Matches the dependent name of a DependentScopeDeclRefExpr or4408DependentNameType4409 4410Given:4411 template <class T> class X : T { void f() { T::v; } };4412dependentScopeDeclRefExpr(hasDependentName("v")) matches `T::v`4413 4414Given:4415 template <typename T> struct declToImport {4416 typedef typename T::type dependent_name;4417 };4418dependentNameType(hasDependentName("type")) matches `T::type`4419</pre></td></tr>4420 4421 4422<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DependentScopeDeclRefExpr.html">DependentScopeDeclRefExpr</a>></td><td class="name" onclick="toggle('hasDependentName0')"><a name="hasDependentName0Anchor">hasDependentName</a></td><td>std::string N</td></tr>4423<tr><td colspan="4" class="doc" id="hasDependentName0"><pre>Matches the dependent name of a DependentScopeDeclRefExpr or4424DependentNameType4425 4426Given:4427 template <class T> class X : T { void f() { T::v; } };4428dependentScopeDeclRefExpr(hasDependentName("v")) matches `T::v`4429 4430Given:4431 template <typename T> struct declToImport {4432 typedef typename T::type dependent_name;4433 };4434dependentNameType(hasDependentName("type")) matches `T::type`4435</pre></td></tr>4436 4437 4438<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DesignatedInitExpr.html">DesignatedInitExpr</a>></td><td class="name" onclick="toggle('designatorCountIs0')"><a name="designatorCountIs0Anchor">designatorCountIs</a></td><td>unsigned N</td></tr>4439<tr><td colspan="4" class="doc" id="designatorCountIs0"><pre>Matches designated initializer expressions that contain4440a specific number of designators.4441 4442Example: Given4443 point ptarray[10] = { [2].y = 1.0, [0].x = 1.0 };4444 point ptarray2[10] = { [2].y = 1.0, [2].x = 0.0, [0].x = 1.0 };4445designatorCountIs(2)4446 matches '{ [2].y = 1.0, [0].x = 1.0 }',4447 but not '{ [2].y = 1.0, [2].x = 0.0, [0].x = 1.0 }'.4448</pre></td></tr>4449 4450 4451<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1EnumDecl.html">EnumDecl</a>></td><td class="name" onclick="toggle('isScoped0')"><a name="isScoped0Anchor">isScoped</a></td><td></td></tr>4452<tr><td colspan="4" class="doc" id="isScoped0"><pre>Matches C++11 scoped enum declaration.4453 4454Example matches Y (matcher = enumDecl(isScoped()))4455enum X {};4456enum class Y {};4457</pre></td></tr>4458 4459 4460<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>></td><td class="name" onclick="toggle('isInstantiationDependent0')"><a name="isInstantiationDependent0Anchor">isInstantiationDependent</a></td><td></td></tr>4461<tr><td colspan="4" class="doc" id="isInstantiationDependent0"><pre>Matches expressions that are instantiation-dependent even if it is4462neither type- nor value-dependent.4463 4464In the following example, the expression sizeof(sizeof(T() + T()))4465is instantiation-dependent (since it involves a template parameter T),4466but is neither type- nor value-dependent, since the type of the inner4467sizeof is known (std::size_t) and therefore the size of the outer4468sizeof is known.4469 template<typename T>4470 void f(T x, T y) { sizeof(sizeof(T() + T()); }4471expr(isInstantiationDependent()) matches sizeof(sizeof(T() + T())4472</pre></td></tr>4473 4474 4475<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>></td><td class="name" onclick="toggle('isTypeDependent0')"><a name="isTypeDependent0Anchor">isTypeDependent</a></td><td></td></tr>4476<tr><td colspan="4" class="doc" id="isTypeDependent0"><pre>Matches expressions that are type-dependent because the template type4477is not yet instantiated.4478 4479For example, the expressions "x" and "x + y" are type-dependent in4480the following code, but "y" is not type-dependent:4481 template<typename T>4482 void add(T x, int y) {4483 x + y;4484 }4485expr(isTypeDependent()) matches x + y4486</pre></td></tr>4487 4488 4489<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>></td><td class="name" onclick="toggle('isValueDependent0')"><a name="isValueDependent0Anchor">isValueDependent</a></td><td></td></tr>4490<tr><td colspan="4" class="doc" id="isValueDependent0"><pre>Matches expression that are value-dependent because they contain a4491non-type template parameter.4492 4493For example, the array bound of "Chars" in the following example is4494value-dependent.4495 template<int Size> int f() { return Size; }4496expr(isValueDependent()) matches return Size4497</pre></td></tr>4498 4499 4500<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>></td><td class="name" onclick="toggle('nullPointerConstant0')"><a name="nullPointerConstant0Anchor">nullPointerConstant</a></td><td></td></tr>4501<tr><td colspan="4" class="doc" id="nullPointerConstant0"><pre>Matches expressions that resolve to a null pointer constant, such as4502GNU's __null, C++11's nullptr, or C's NULL macro.4503 4504Given:4505 void *v1 = NULL;4506 void *v2 = nullptr;4507 void *v3 = __null; // GNU extension4508 char *cp = (char *)0;4509 int *ip = 0;4510 int i = 0;4511expr(nullPointerConstant())4512 matches the initializer for v1, v2, v3, cp, and ip. Does not match the4513 initializer for i.4514</pre></td></tr>4515 4516 4517<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html">FieldDecl</a>></td><td class="name" onclick="toggle('hasBitWidth0')"><a name="hasBitWidth0Anchor">hasBitWidth</a></td><td>unsigned Width</td></tr>4518<tr><td colspan="4" class="doc" id="hasBitWidth0"><pre>Matches non-static data members that are bit-fields of the specified4519bit width.4520 4521Given4522 class C {4523 int a : 2;4524 int b : 4;4525 int c : 2;4526 };4527fieldDecl(hasBitWidth(2))4528 matches 'int a;' and 'int c;' but not 'int b;'.4529</pre></td></tr>4530 4531 4532<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html">FieldDecl</a>></td><td class="name" onclick="toggle('isBitField0')"><a name="isBitField0Anchor">isBitField</a></td><td></td></tr>4533<tr><td colspan="4" class="doc" id="isBitField0"><pre>Matches non-static data members that are bit-fields.4534 4535Given4536 class C {4537 int a : 2;4538 int b;4539 };4540fieldDecl(isBitField())4541 matches 'int a;' but not 'int b;'.4542</pre></td></tr>4543 4544 4545<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>></td><td class="name" onclick="toggle('equals1')"><a name="equals1Anchor">equals</a></td><td>const ValueT Value</td></tr>4546<tr><td colspan="4" class="doc" id="equals1"><pre>Matches literals that are equal to the given value of type ValueT.4547 4548Given4549 f('false, 3.14, 42);4550characterLiteral(equals(0))4551 matches 'cxxBoolLiteral(equals(false)) and cxxBoolLiteral(equals(0))4552 match false4553floatLiteral(equals(3.14)) and floatLiteral(equals(314e-2))4554 match 3.144555integerLiteral(equals(42))4556 matches 424557 4558Note that you cannot directly match a negative numeric literal because the4559minus sign is not part of the literal: It is a unary operator whose operand4560is the positive numeric literal. Instead, you must use a unaryOperator()4561matcher to match the minus sign:4562 4563unaryOperator(hasOperatorName("-"),4564 hasUnaryOperand(integerLiteral(equals(13))))4565 4566Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBoolLiteralExpr.html">CXXBoolLiteralExpr</a>>,4567 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>>4568</pre></td></tr>4569 4570 4571<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>></td><td class="name" onclick="toggle('equals12')"><a name="equals12Anchor">equals</a></td><td>double Value</td></tr>4572<tr><td colspan="4" class="doc" id="equals12"><pre></pre></td></tr>4573 4574 4575<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('hasAnyOverloadedOperatorName1')"><a name="hasAnyOverloadedOperatorName1Anchor">hasAnyOverloadedOperatorName</a></td><td>StringRef, ..., StringRef</td></tr>4576<tr><td colspan="4" class="doc" id="hasAnyOverloadedOperatorName1"><pre>Matches overloaded operator names.4577 4578Matches overloaded operator names specified in strings without the4579"operator" prefix: e.g. "<<".4580 4581 hasAnyOverloadedOperatorName("+", "-")4582Is equivalent to4583 anyOf(hasOverloadedOperatorName("+"), hasOverloadedOperatorName("-"))4584</pre></td></tr>4585 4586 4587<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('hasDynamicExceptionSpec0')"><a name="hasDynamicExceptionSpec0Anchor">hasDynamicExceptionSpec</a></td><td></td></tr>4588<tr><td colspan="4" class="doc" id="hasDynamicExceptionSpec0"><pre>Matches functions that have a dynamic exception specification.4589 4590Given:4591 void f();4592 void g() noexcept;4593 void h() noexcept(true);4594 void i() noexcept(false);4595 void j() throw();4596 void k() throw(int);4597 void l() throw(...);4598functionDecl(hasDynamicExceptionSpec()) and4599 functionProtoType(hasDynamicExceptionSpec())4600 match the declarations of j, k, and l, but not f, g, h, or i.4601</pre></td></tr>4602 4603 4604<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('hasOverloadedOperatorName0')"><a name="hasOverloadedOperatorName0Anchor">hasOverloadedOperatorName</a></td><td>StringRef Name</td></tr>4605<tr><td colspan="4" class="doc" id="hasOverloadedOperatorName0"><pre>Matches overloaded operator names.4606 4607Matches overloaded operator names specified in strings without the4608"operator" prefix: e.g. "<<".4609 4610Given:4611 class A { int operator*(); };4612 const A &operator<<(const A &a, const A &b);4613 A a;4614 a << a; // <-- This matches4615 4616cxxOperatorCallExpr(hasOverloadedOperatorName("<<"))) matches the4617specified line and4618cxxRecordDecl(hasMethod(hasOverloadedOperatorName("*")))4619matches the declaration of A.4620 4621Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>4622</pre></td></tr>4623 4624 4625<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('hasTrailingReturn0')"><a name="hasTrailingReturn0Anchor">hasTrailingReturn</a></td><td></td></tr>4626<tr><td colspan="4" class="doc" id="hasTrailingReturn0"><pre>Matches a function declared with a trailing return type.4627 4628Example matches Y (matcher = functionDecl(hasTrailingReturn()))4629int X() {}4630auto Y() -> int {}4631</pre></td></tr>4632 4633 4634<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isConsteval0')"><a name="isConsteval0Anchor">isConsteval</a></td><td></td></tr>4635<tr><td colspan="4" class="doc" id="isConsteval0"><pre>Matches consteval function declarations and if consteval/if ! consteval4636statements.4637 4638Given:4639 consteval int a();4640 void b() { if consteval {} }4641 void c() { if ! consteval {} }4642 void d() { if ! consteval {} else {} }4643functionDecl(isConsteval())4644 matches the declaration of "int a()".4645ifStmt(isConsteval())4646 matches the if statement in "void b()", "void c()", "void d()".4647</pre></td></tr>4648 4649 4650<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isConstexpr1')"><a name="isConstexpr1Anchor">isConstexpr</a></td><td></td></tr>4651<tr><td colspan="4" class="doc" id="isConstexpr1"><pre>Matches constexpr variable and function declarations,4652 and if constexpr.4653 4654Given:4655 constexpr int foo = 42;4656 constexpr int bar();4657 void baz() { if constexpr(1 > 0) {} }4658varDecl(isConstexpr())4659 matches the declaration of foo.4660functionDecl(isConstexpr())4661 matches the declaration of bar.4662ifStmt(isConstexpr())4663 matches the if statement in baz.4664</pre></td></tr>4665 4666 4667<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isDefaulted0')"><a name="isDefaulted0Anchor">isDefaulted</a></td><td></td></tr>4668<tr><td colspan="4" class="doc" id="isDefaulted0"><pre>Matches defaulted function declarations.4669 4670Given:4671 class A { ~A(); };4672 class B { ~B() = default; };4673functionDecl(isDefaulted())4674 matches the declaration of ~B, but not ~A.4675</pre></td></tr>4676 4677 4678<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isDefinition3')"><a name="isDefinition3Anchor">isDefinition</a></td><td></td></tr>4679<tr><td colspan="4" class="doc" id="isDefinition3"><pre>Matches if a declaration has a body attached.4680 4681Example matches A, va, fa4682 class A {};4683 class B; // Doesn't match, as it has no body.4684 int va;4685 extern int vb; // Doesn't match, as it doesn't define the variable.4686 void fa() {}4687 void fb(); // Doesn't match, as it has no body.4688 @interface X4689 - (void)ma; // Doesn't match, interface is declaration.4690 @end4691 @implementation X4692 - (void)ma {}4693 @end4694 4695Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagDecl.html">TagDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>,4696 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html">ObjCMethodDecl</a>>4697</pre></td></tr>4698 4699 4700<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isDeleted0')"><a name="isDeleted0Anchor">isDeleted</a></td><td></td></tr>4701<tr><td colspan="4" class="doc" id="isDeleted0"><pre>Matches deleted function declarations.4702 4703Given:4704 void Func();4705 void DeletedFunc() = delete;4706functionDecl(isDeleted())4707 matches the declaration of DeletedFunc, but not Func.4708</pre></td></tr>4709 4710 4711<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isExplicitTemplateSpecialization0')"><a name="isExplicitTemplateSpecialization0Anchor">isExplicitTemplateSpecialization</a></td><td></td></tr>4712<tr><td colspan="4" class="doc" id="isExplicitTemplateSpecialization0"><pre>Matches explicit template specializations of function, class, or4713static member variable template instantiations.4714 4715Given4716 template<typename T> void A(T t) { }4717 template<> void A(int N) { }4718functionDecl(isExplicitTemplateSpecialization())4719 matches the specialization A<int>().4720 4721Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>>4722</pre></td></tr>4723 4724 4725<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isExternC0')"><a name="isExternC0Anchor">isExternC</a></td><td></td></tr>4726<tr><td colspan="4" class="doc" id="isExternC0"><pre>Matches extern "C" function or variable declarations.4727 4728Given:4729 extern "C" void f() {}4730 extern "C" { void g() {} }4731 void h() {}4732 extern "C" int x = 1;4733 extern "C" int y = 2;4734 int z = 3;4735functionDecl(isExternC())4736 matches the declaration of f and g, but not the declaration of h.4737varDecl(isExternC())4738 matches the declaration of x and y, but not the declaration of z.4739</pre></td></tr>4740 4741 4742<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isInline1')"><a name="isInline1Anchor">isInline</a></td><td></td></tr>4743<tr><td colspan="4" class="doc" id="isInline1"><pre>Matches functions, variables and namespace declarations that are marked with4744the inline keyword.4745 4746Given4747 inline void f();4748 void g();4749 namespace n {4750 inline namespace m {}4751 }4752 inline int Foo = 5;4753functionDecl(isInline()) will match ::f().4754namespaceDecl(isInline()) will match n::m.4755varDecl(isInline()) will match Foo;4756</pre></td></tr>4757 4758 4759<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isMain0')"><a name="isMain0Anchor">isMain</a></td><td></td></tr>4760<tr><td colspan="4" class="doc" id="isMain0"><pre>Determines whether the function is "main", which is the entry point4761into an executable program.4762</pre></td></tr>4763 4764 4765<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isNoReturn0')"><a name="isNoReturn0Anchor">isNoReturn</a></td><td></td></tr>4766<tr><td colspan="4" class="doc" id="isNoReturn0"><pre>Matches FunctionDecls that have a noreturn attribute.4767 4768Given4769 void nope();4770 [[noreturn]] void a();4771 __attribute__((noreturn)) void b();4772 struct c { [[noreturn]] c(); };4773functionDecl(isNoReturn())4774 matches all of those except4775 void nope();4776</pre></td></tr>4777 4778 4779<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isNoThrow0')"><a name="isNoThrow0Anchor">isNoThrow</a></td><td></td></tr>4780<tr><td colspan="4" class="doc" id="isNoThrow0"><pre>Matches functions that have a non-throwing exception specification.4781 4782Given:4783 void f();4784 void g() noexcept;4785 void h() throw();4786 void i() throw(int);4787 void j() noexcept(false);4788functionDecl(isNoThrow()) and functionProtoType(isNoThrow())4789 match the declarations of g, and h, but not f, i or j.4790</pre></td></tr>4791 4792 4793<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isStaticStorageClass0')"><a name="isStaticStorageClass0Anchor">isStaticStorageClass</a></td><td></td></tr>4794<tr><td colspan="4" class="doc" id="isStaticStorageClass0"><pre>Matches variable/function declarations that have "static" storage4795class specifier ("static" keyword) written in the source.4796 4797Given:4798 static void f() {}4799 static int i = 0;4800 extern int j;4801 int k;4802functionDecl(isStaticStorageClass())4803 matches the function declaration f.4804varDecl(isStaticStorageClass())4805 matches the variable declaration i.4806</pre></td></tr>4807 4808 4809<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isTemplateInstantiation0')"><a name="isTemplateInstantiation0Anchor">isTemplateInstantiation</a></td><td></td></tr>4810<tr><td colspan="4" class="doc" id="isTemplateInstantiation0"><pre>Matches template instantiations of function, class, or static4811member variable template instantiations.4812 4813Given4814 template <typename T> class X {}; class A {}; X<A> x;4815or4816 template <typename T> class X {}; class A {}; template class X<A>;4817or4818 template <typename T> class X {}; class A {}; extern template class X<A>;4819cxxRecordDecl(hasName("::X"), isTemplateInstantiation())4820 matches the template instantiation of X<A>.4821 4822But given4823 template <typename T> class X {}; class A {};4824 template <> class X<A> {}; X<A> x;4825cxxRecordDecl(hasName("::X"), isTemplateInstantiation())4826 does not match, as X<A> is an explicit template specialization.4827 4828Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>>4829</pre></td></tr>4830 4831 4832<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isVariadic0')"><a name="isVariadic0Anchor">isVariadic</a></td><td></td></tr>4833<tr><td colspan="4" class="doc" id="isVariadic0"><pre>Matches if a function declaration is variadic.4834 4835Example matches f, but not g or h. The function i will not match, even when4836compiled in C mode.4837 void f(...);4838 void g(int);4839 template <typename... Ts> void h(Ts...);4840 void i();4841</pre></td></tr>4842 4843 4844<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isWeak0')"><a name="isWeak0Anchor">isWeak</a></td><td></td></tr>4845<tr><td colspan="4" class="doc" id="isWeak0"><pre>Matches weak function declarations.4846 4847Given:4848 void foo() __attribute__((__weakref__("__foo")));4849 void bar();4850functionDecl(isWeak())4851 matches the weak declaration "foo", but not "bar".4852</pre></td></tr>4853 4854 4855<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('parameterCountIs0')"><a name="parameterCountIs0Anchor">parameterCountIs</a></td><td>unsigned N</td></tr>4856<tr><td colspan="4" class="doc" id="parameterCountIs0"><pre>Matches FunctionDecls and FunctionProtoTypes that have a4857specific parameter count.4858 4859Given4860 void f(int i) {}4861 void g(int i, int j) {}4862 void h(int i, int j);4863 void j(int i);4864 void k(int x, int y, int z, ...);4865functionDecl(parameterCountIs(2))4866 matches g and h4867functionProtoType(parameterCountIs(2))4868 matches g and h4869functionProtoType(parameterCountIs(3))4870 matches k4871</pre></td></tr>4872 4873 4874<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('templateArgumentCountIs2')"><a name="templateArgumentCountIs2Anchor">templateArgumentCountIs</a></td><td>unsigned N</td></tr>4875<tr><td colspan="4" class="doc" id="templateArgumentCountIs2"><pre>Matches if the number of template arguments equals N.4876 4877Given4878 template<typename T> struct C {};4879 C<int> c;4880 template<typename T> void f() {}4881 void func() { f<int>(); };4882 4883classTemplateSpecializationDecl(templateArgumentCountIs(1))4884 matches C<int>.4885 4886functionDecl(templateArgumentCountIs(1))4887 matches f<int>();4888</pre></td></tr>4889 4890 4891<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionProtoType.html">FunctionProtoType</a>></td><td class="name" onclick="toggle('hasDynamicExceptionSpec1')"><a name="hasDynamicExceptionSpec1Anchor">hasDynamicExceptionSpec</a></td><td></td></tr>4892<tr><td colspan="4" class="doc" id="hasDynamicExceptionSpec1"><pre>Matches functions that have a dynamic exception specification.4893 4894Given:4895 void f();4896 void g() noexcept;4897 void h() noexcept(true);4898 void i() noexcept(false);4899 void j() throw();4900 void k() throw(int);4901 void l() throw(...);4902functionDecl(hasDynamicExceptionSpec()) and4903 functionProtoType(hasDynamicExceptionSpec())4904 match the declarations of j, k, and l, but not f, g, h, or i.4905</pre></td></tr>4906 4907 4908<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionProtoType.html">FunctionProtoType</a>></td><td class="name" onclick="toggle('isNoThrow1')"><a name="isNoThrow1Anchor">isNoThrow</a></td><td></td></tr>4909<tr><td colspan="4" class="doc" id="isNoThrow1"><pre>Matches functions that have a non-throwing exception specification.4910 4911Given:4912 void f();4913 void g() noexcept;4914 void h() throw();4915 void i() throw(int);4916 void j() noexcept(false);4917functionDecl(isNoThrow()) and functionProtoType(isNoThrow())4918 match the declarations of g, and h, but not f, i or j.4919</pre></td></tr>4920 4921 4922<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionProtoType.html">FunctionProtoType</a>></td><td class="name" onclick="toggle('parameterCountIs1')"><a name="parameterCountIs1Anchor">parameterCountIs</a></td><td>unsigned N</td></tr>4923<tr><td colspan="4" class="doc" id="parameterCountIs1"><pre>Matches FunctionDecls and FunctionProtoTypes that have a4924specific parameter count.4925 4926Given4927 void f(int i) {}4928 void g(int i, int j) {}4929 void h(int i, int j);4930 void j(int i);4931 void k(int x, int y, int z, ...);4932functionDecl(parameterCountIs(2))4933 matches g and h4934functionProtoType(parameterCountIs(2))4935 matches g and h4936functionProtoType(parameterCountIs(3))4937 matches k4938</pre></td></tr>4939 4940 4941<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IfStmt.html">IfStmt</a>></td><td class="name" onclick="toggle('isConsteval1')"><a name="isConsteval1Anchor">isConsteval</a></td><td></td></tr>4942<tr><td colspan="4" class="doc" id="isConsteval1"><pre>Matches consteval function declarations and if consteval/if ! consteval4943statements.4944 4945Given:4946 consteval int a();4947 void b() { if consteval {} }4948 void c() { if ! consteval {} }4949 void d() { if ! consteval {} else {} }4950functionDecl(isConsteval())4951 matches the declaration of "int a()".4952ifStmt(isConsteval())4953 matches the if statement in "void b()", "void c()", "void d()".4954</pre></td></tr>4955 4956 4957<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IfStmt.html">IfStmt</a>></td><td class="name" onclick="toggle('isConstexpr2')"><a name="isConstexpr2Anchor">isConstexpr</a></td><td></td></tr>4958<tr><td colspan="4" class="doc" id="isConstexpr2"><pre>Matches constexpr variable and function declarations,4959 and if constexpr.4960 4961Given:4962 constexpr int foo = 42;4963 constexpr int bar();4964 void baz() { if constexpr(1 > 0) {} }4965varDecl(isConstexpr())4966 matches the declaration of foo.4967functionDecl(isConstexpr())4968 matches the declaration of bar.4969ifStmt(isConstexpr())4970 matches the if statement in baz.4971</pre></td></tr>4972 4973 4974<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>></td><td class="name" onclick="toggle('equals6')"><a name="equals6Anchor">equals</a></td><td>bool Value</td></tr>4975<tr><td colspan="4" class="doc" id="equals6"><pre></pre></td></tr>4976 4977 4978<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>></td><td class="name" onclick="toggle('equals0')"><a name="equals0Anchor">equals</a></td><td>const ValueT Value</td></tr>4979<tr><td colspan="4" class="doc" id="equals0"><pre>Matches literals that are equal to the given value of type ValueT.4980 4981Given4982 f('false, 3.14, 42);4983characterLiteral(equals(0))4984 matches 'cxxBoolLiteral(equals(false)) and cxxBoolLiteral(equals(0))4985 match false4986floatLiteral(equals(3.14)) and floatLiteral(equals(314e-2))4987 match 3.144988integerLiteral(equals(42))4989 matches 424990 4991Note that you cannot directly match a negative numeric literal because the4992minus sign is not part of the literal: It is a unary operator whose operand4993is the positive numeric literal. Instead, you must use a unaryOperator()4994matcher to match the minus sign:4995 4996unaryOperator(hasOperatorName("-"),4997 hasUnaryOperand(integerLiteral(equals(13))))4998 4999Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBoolLiteralExpr.html">CXXBoolLiteralExpr</a>>,5000 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>>5001</pre></td></tr>5002 5003 5004<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>></td><td class="name" onclick="toggle('equals13')"><a name="equals13Anchor">equals</a></td><td>double Value</td></tr>5005<tr><td colspan="4" class="doc" id="equals13"><pre></pre></td></tr>5006 5007 5008<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>></td><td class="name" onclick="toggle('equals9')"><a name="equals9Anchor">equals</a></td><td>unsigned Value</td></tr>5009<tr><td colspan="4" class="doc" id="equals9"><pre></pre></td></tr>5010 5011 5012<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LambdaCapture.html">LambdaCapture</a>></td><td class="name" onclick="toggle('capturesThis0')"><a name="capturesThis0Anchor">capturesThis</a></td><td></td></tr>5013<tr><td colspan="4" class="doc" id="capturesThis0"><pre>Matches a `LambdaCapture` that refers to 'this'.5014 5015Given5016class C {5017 int cc;5018 int f() {5019 auto l = [this]() { return cc; };5020 return l();5021 }5022};5023lambdaExpr(hasAnyCapture(lambdaCapture(capturesThis())))5024 matches `[this]() { return cc; }`.5025</pre></td></tr>5026 5027 5028<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LambdaCapture.html">LambdaCapture</a>></td><td class="name" onclick="toggle('isImplicit2')"><a name="isImplicit2Anchor">isImplicit</a></td><td></td></tr>5029<tr><td colspan="4" class="doc" id="isImplicit2"><pre>Matches an entity that has been implicitly added by the compiler (e.g.5030implicit default/copy constructors).5031</pre></td></tr>5032 5033 5034<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>></td><td class="name" onclick="toggle('isArrow0')"><a name="isArrow0Anchor">isArrow</a></td><td></td></tr>5035<tr><td colspan="4" class="doc" id="isArrow0"><pre>Matches member expressions that are called with '->' as opposed5036to '.'.5037 5038Member calls on the implicit this pointer match as called with '->'.5039 5040Given5041 class Y {5042 void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; }5043 template <class T> void f() { this->f<T>(); f<T>(); }5044 int a;5045 static int b;5046 };5047 template <class T>5048 class Z {5049 void x() { this->m; }5050 };5051memberExpr(isArrow())5052 matches this->x, x, y.x, a, this->b5053cxxDependentScopeMemberExpr(isArrow())5054 matches this->m5055unresolvedMemberExpr(isArrow())5056 matches this->f<T>, f<T>5057</pre></td></tr>5058 5059 5060<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>></td><td class="name" onclick="toggle('hasAnyName0')"><a name="hasAnyName0Anchor">hasAnyName</a></td><td>StringRef, ..., StringRef</td></tr>5061<tr><td colspan="4" class="doc" id="hasAnyName0"><pre>Matches NamedDecl nodes that have any of the specified names.5062 5063This matcher is only provided as a performance optimization of hasName.5064 hasAnyName(a, b, c)5065 is equivalent to, but faster than5066 anyOf(hasName(a), hasName(b), hasName(c))5067</pre></td></tr>5068 5069 5070<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>></td><td class="name" onclick="toggle('hasExternalFormalLinkage0')"><a name="hasExternalFormalLinkage0Anchor">hasExternalFormalLinkage</a></td><td></td></tr>5071<tr><td colspan="4" class="doc" id="hasExternalFormalLinkage0"><pre>Matches a declaration that has external formal linkage.5072 5073Example matches only z (matcher = varDecl(hasExternalFormalLinkage()))5074void f() {5075 int x;5076 static int y;5077}5078int z;5079 5080Example matches f() because it has external formal linkage despite being5081unique to the translation unit as though it has internal linkage5082(matcher = functionDecl(hasExternalFormalLinkage()))5083 5084namespace {5085void f() {}5086}5087</pre></td></tr>5088 5089 5090<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>></td><td class="name" onclick="toggle('hasName0')"><a name="hasName0Anchor">hasName</a></td><td>StringRef Name</td></tr>5091<tr><td colspan="4" class="doc" id="hasName0"><pre>Matches NamedDecl nodes that have the specified name.5092 5093Supports specifying enclosing namespaces or classes by prefixing the name5094with '<enclosing>::'.5095Does not match typedefs of an underlying type with the given name.5096 5097Example matches X (Name == "X")5098 class X;5099 5100Example matches X (Name is one of "::a::b::X", "a::b::X", "b::X", "X")5101 namespace a { namespace b { class X; } }5102</pre></td></tr>5103 5104 5105<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>></td><td class="name" onclick="toggle('matchesName0')"><a name="matchesName0Anchor">matchesName</a></td><td>StringRef RegExp, Regex::RegexFlags Flags = NoFlags</td></tr>5106<tr><td colspan="4" class="doc" id="matchesName0"><pre>Matches NamedDecl nodes whose fully qualified names contain5107a substring matched by the given RegExp.5108 5109Supports specifying enclosing namespaces or classes by5110prefixing the name with '<enclosing>::'. Does not match typedefs5111of an underlying type with the given name.5112 5113Example matches X (regexp == "::X")5114 class X;5115 5116Example matches X (regexp is one of "::X", "^foo::.*X", among others)5117 namespace foo { namespace bar { class X; } }5118 5119If the matcher is used in clang-query, RegexFlags parameter5120should be passed as a quoted string. e.g: "NoFlags".5121Flags can be combined with '|' example "IgnoreCase | BasicRegex"5122</pre></td></tr>5123 5124 5125<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamespaceDecl.html">NamespaceDecl</a>></td><td class="name" onclick="toggle('isAnonymous0')"><a name="isAnonymous0Anchor">isAnonymous</a></td><td></td></tr>5126<tr><td colspan="4" class="doc" id="isAnonymous0"><pre>Matches anonymous namespace declarations.5127 5128Given5129 namespace n {5130 namespace {} // #15131 }5132namespaceDecl(isAnonymous()) will match #1 but not ::n.5133</pre></td></tr>5134 5135 5136<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamespaceDecl.html">NamespaceDecl</a>></td><td class="name" onclick="toggle('isInline0')"><a name="isInline0Anchor">isInline</a></td><td></td></tr>5137<tr><td colspan="4" class="doc" id="isInline0"><pre>Matches functions, variables and namespace declarations that are marked with5138the inline keyword.5139 5140Given5141 inline void f();5142 void g();5143 namespace n {5144 inline namespace m {}5145 }5146 inline int Foo = 5;5147functionDecl(isInline()) will match ::f().5148namespaceDecl(isInline()) will match n::m.5149varDecl(isInline()) will match Foo;5150</pre></td></tr>5151 5152 5153<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPDefaultClause.html">OMPDefaultClause</a>></td><td class="name" onclick="toggle('isFirstPrivateKind0')"><a name="isFirstPrivateKind0Anchor">isFirstPrivateKind</a></td><td></td></tr>5154<tr><td colspan="4" class="doc" id="isFirstPrivateKind0"><pre>Matches if the OpenMP ``default`` clause has ``firstprivate`` kind5155specified.5156 5157Given5158 5159 #pragma omp parallel5160 #pragma omp parallel default(none)5161 #pragma omp parallel default(shared)5162 #pragma omp parallel default(private)5163 #pragma omp parallel default(firstprivate)5164 5165``ompDefaultClause(isFirstPrivateKind())`` matches only5166``default(firstprivate)``.5167</pre></td></tr>5168 5169 5170<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPDefaultClause.html">OMPDefaultClause</a>></td><td class="name" onclick="toggle('isNoneKind0')"><a name="isNoneKind0Anchor">isNoneKind</a></td><td></td></tr>5171<tr><td colspan="4" class="doc" id="isNoneKind0"><pre>Matches if the OpenMP ``default`` clause has ``none`` kind specified.5172 5173Given5174 5175 #pragma omp parallel5176 #pragma omp parallel default(none)5177 #pragma omp parallel default(shared)5178 #pragma omp parallel default(private)5179 #pragma omp parallel default(firstprivate)5180 5181``ompDefaultClause(isNoneKind())`` matches only ``default(none)``.5182</pre></td></tr>5183 5184 5185<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPDefaultClause.html">OMPDefaultClause</a>></td><td class="name" onclick="toggle('isPrivateKind0')"><a name="isPrivateKind0Anchor">isPrivateKind</a></td><td></td></tr>5186<tr><td colspan="4" class="doc" id="isPrivateKind0"><pre>Matches if the OpenMP ``default`` clause has ``private`` kind5187specified.5188 5189Given5190 5191 #pragma omp parallel5192 #pragma omp parallel default(none)5193 #pragma omp parallel default(shared)5194 #pragma omp parallel default(private)5195 #pragma omp parallel default(firstprivate)5196 5197``ompDefaultClause(isPrivateKind())`` matches only5198``default(private)``.5199</pre></td></tr>5200 5201 5202<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPDefaultClause.html">OMPDefaultClause</a>></td><td class="name" onclick="toggle('isSharedKind0')"><a name="isSharedKind0Anchor">isSharedKind</a></td><td></td></tr>5203<tr><td colspan="4" class="doc" id="isSharedKind0"><pre>Matches if the OpenMP ``default`` clause has ``shared`` kind specified.5204 5205Given5206 5207 #pragma omp parallel5208 #pragma omp parallel default(none)5209 #pragma omp parallel default(shared)5210 #pragma omp parallel default(private)5211 #pragma omp parallel default(firstprivate)5212 5213``ompDefaultClause(isSharedKind())`` matches only ``default(shared)``.5214</pre></td></tr>5215 5216 5217<tr><td>Matcher<OMPExecutableDirective></td><td class="name" onclick="toggle('isAllowedToContainClauseKind0')"><a name="isAllowedToContainClauseKind0Anchor">isAllowedToContainClauseKind</a></td><td>OpenMPClauseKind CKind</td></tr>5218<tr><td colspan="4" class="doc" id="isAllowedToContainClauseKind0"><pre>Matches if the OpenMP directive is allowed to contain the specified OpenMP5219clause kind.5220 5221Given5222 5223 #pragma omp parallel5224 #pragma omp parallel for5225 #pragma omp for5226 5227``ompExecutableDirective(isAllowedToContainClause(OMPC_default))`` matches5228``omp parallel`` and ``omp parallel for``.5229 5230If the matcher is use from clang-query, ``OpenMPClauseKind`` parameter5231should be passed as a quoted string. e.g.,5232``isAllowedToContainClauseKind("OMPC_default").``5233</pre></td></tr>5234 5235 5236<tr><td>Matcher<OMPExecutableDirective></td><td class="name" onclick="toggle('isStandaloneDirective0')"><a name="isStandaloneDirective0Anchor">isStandaloneDirective</a></td><td></td></tr>5237<tr><td colspan="4" class="doc" id="isStandaloneDirective0"><pre>Matches standalone OpenMP directives,5238i.e., directives that can't have a structured block.5239 5240Given5241 5242 #pragma omp parallel5243 {}5244 #pragma omp taskyield5245 5246``ompExecutableDirective(isStandaloneDirective()))`` matches5247``omp taskyield``.5248</pre></td></tr>5249 5250 5251<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCInterfaceDecl.html">ObjCInterfaceDecl</a>></td><td class="name" onclick="toggle('isDerivedFrom3')"><a name="isDerivedFrom3Anchor">isDerivedFrom</a></td><td>std::string BaseName</td></tr>5252<tr><td colspan="4" class="doc" id="isDerivedFrom3"><pre>Overloaded method as shortcut for isDerivedFrom(hasName(...)).5253</pre></td></tr>5254 5255 5256<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCInterfaceDecl.html">ObjCInterfaceDecl</a>></td><td class="name" onclick="toggle('isDirectlyDerivedFrom3')"><a name="isDirectlyDerivedFrom3Anchor">isDirectlyDerivedFrom</a></td><td>std::string BaseName</td></tr>5257<tr><td colspan="4" class="doc" id="isDirectlyDerivedFrom3"><pre>Overloaded method as shortcut for isDirectlyDerivedFrom(hasName(...)).5258</pre></td></tr>5259 5260 5261<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCInterfaceDecl.html">ObjCInterfaceDecl</a>></td><td class="name" onclick="toggle('isSameOrDerivedFrom3')"><a name="isSameOrDerivedFrom3Anchor">isSameOrDerivedFrom</a></td><td>std::string BaseName</td></tr>5262<tr><td colspan="4" class="doc" id="isSameOrDerivedFrom3"><pre>Overloaded method as shortcut for5263isSameOrDerivedFrom(hasName(...)).5264</pre></td></tr>5265 5266 5267<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>></td><td class="name" onclick="toggle('argumentCountAtLeast3')"><a name="argumentCountAtLeast3Anchor">argumentCountAtLeast</a></td><td>unsigned N</td></tr>5268<tr><td colspan="4" class="doc" id="argumentCountAtLeast3"><pre>Checks that a call expression or a constructor call expression has at least5269the specified number of arguments (including absent default arguments).5270 5271Example matches f(0, 0) and g(0, 0, 0)5272(matcher = callExpr(argumentCountAtLeast(2)))5273 void f(int x, int y);5274 void g(int x, int y, int z);5275 f(0, 0);5276 g(0, 0, 0);5277</pre></td></tr>5278 5279 5280<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>></td><td class="name" onclick="toggle('argumentCountIs3')"><a name="argumentCountIs3Anchor">argumentCountIs</a></td><td>unsigned N</td></tr>5281<tr><td colspan="4" class="doc" id="argumentCountIs3"><pre>Checks that a call expression or a constructor call expression has5282a specific number of arguments (including absent default arguments).5283 5284Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2)))5285 void f(int x, int y);5286 f(0, 0);5287</pre></td></tr>5288 5289 5290<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>></td><td class="name" onclick="toggle('hasAnySelector0')"><a name="hasAnySelector0Anchor">hasAnySelector</a></td><td>StringRef, ..., StringRef</td></tr>5291<tr><td colspan="4" class="doc" id="hasAnySelector0"><pre>Matches when at least one of the supplied string equals to the5292Selector.getAsString()5293 5294 matcher = objCMessageExpr(hasSelector("methodA:", "methodB:"));5295 matches both of the expressions below:5296 [myObj methodA:argA];5297 [myObj methodB:argB];5298</pre></td></tr>5299 5300 5301<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>></td><td class="name" onclick="toggle('hasKeywordSelector0')"><a name="hasKeywordSelector0Anchor">hasKeywordSelector</a></td><td></td></tr>5302<tr><td colspan="4" class="doc" id="hasKeywordSelector0"><pre>Matches when the selector is a keyword selector5303 5304objCMessageExpr(hasKeywordSelector()) matches the generated setFrame5305message expression in5306 5307 UIWebView *webView = ...;5308 CGRect bodyFrame = webView.frame;5309 bodyFrame.size.height = self.bodyContentHeight;5310 webView.frame = bodyFrame;5311 // ^---- matches here5312</pre></td></tr>5313 5314 5315<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>></td><td class="name" onclick="toggle('hasNullSelector0')"><a name="hasNullSelector0Anchor">hasNullSelector</a></td><td></td></tr>5316<tr><td colspan="4" class="doc" id="hasNullSelector0"><pre>Matches when the selector is the empty selector5317 5318Matches only when the selector of the objCMessageExpr is NULL. This may5319represent an error condition in the tree!5320</pre></td></tr>5321 5322 5323<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>></td><td class="name" onclick="toggle('hasSelector0')"><a name="hasSelector0Anchor">hasSelector</a></td><td>std::string BaseName</td></tr>5324<tr><td colspan="4" class="doc" id="hasSelector0"><pre>Matches when BaseName == Selector.getAsString()5325 5326 matcher = objCMessageExpr(hasSelector("loadHTMLString:baseURL:"));5327 matches the outer message expr in the code below, but NOT the message5328 invocation for self.bodyView.5329 [self.bodyView loadHTMLString:html baseURL:NULL];5330</pre></td></tr>5331 5332 5333<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>></td><td class="name" onclick="toggle('hasUnarySelector0')"><a name="hasUnarySelector0Anchor">hasUnarySelector</a></td><td></td></tr>5334<tr><td colspan="4" class="doc" id="hasUnarySelector0"><pre>Matches when the selector is a Unary Selector5335 5336 matcher = objCMessageExpr(matchesSelector(hasUnarySelector());5337 matches self.bodyView in the code below, but NOT the outer message5338 invocation of "loadHTMLString:baseURL:".5339 [self.bodyView loadHTMLString:html baseURL:NULL];5340</pre></td></tr>5341 5342 5343<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>></td><td class="name" onclick="toggle('isClassMessage0')"><a name="isClassMessage0Anchor">isClassMessage</a></td><td></td></tr>5344<tr><td colspan="4" class="doc" id="isClassMessage0"><pre>Returns true when the Objective-C message is sent to a class.5345 5346Example5347matcher = objcMessageExpr(isClassMessage())5348matches5349 [NSString stringWithFormat:@"format"];5350but not5351 NSString *x = @"hello";5352 [x containsString:@"h"];5353</pre></td></tr>5354 5355 5356<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>></td><td class="name" onclick="toggle('isInstanceMessage0')"><a name="isInstanceMessage0Anchor">isInstanceMessage</a></td><td></td></tr>5357<tr><td colspan="4" class="doc" id="isInstanceMessage0"><pre>Returns true when the Objective-C message is sent to an instance.5358 5359Example5360matcher = objcMessageExpr(isInstanceMessage())5361matches5362 NSString *x = @"hello";5363 [x containsString:@"h"];5364but not5365 [NSString stringWithFormat:@"format"];5366</pre></td></tr>5367 5368 5369<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>></td><td class="name" onclick="toggle('matchesSelector0')"><a name="matchesSelector0Anchor">matchesSelector</a></td><td>StringRef RegExp, Regex::RegexFlags Flags = NoFlags</td></tr>5370<tr><td colspan="4" class="doc" id="matchesSelector0"><pre>Matches ObjC selectors whose name contains5371a substring matched by the given RegExp.5372 matcher = objCMessageExpr(matchesSelector("loadHTMLStringmatches the outer message expr in the code below, but NOT the message5373 invocation for self.bodyView.5374 [self.bodyView loadHTMLString:html baseURL:NULL];5375 5376If the matcher is used in clang-query, RegexFlags parameter5377should be passed as a quoted string. e.g: "NoFlags".5378Flags can be combined with '|' example "IgnoreCase | BasicRegex"5379</pre></td></tr>5380 5381 5382<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>></td><td class="name" onclick="toggle('numSelectorArgs0')"><a name="numSelectorArgs0Anchor">numSelectorArgs</a></td><td>unsigned N</td></tr>5383<tr><td colspan="4" class="doc" id="numSelectorArgs0"><pre>Matches when the selector has the specified number of arguments5384 5385 matcher = objCMessageExpr(numSelectorArgs(0));5386 matches self.bodyView in the code below5387 5388 matcher = objCMessageExpr(numSelectorArgs(2));5389 matches the invocation of "loadHTMLString:baseURL:" but not that5390 of self.bodyView5391 [self.bodyView loadHTMLString:html baseURL:NULL];5392</pre></td></tr>5393 5394 5395<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html">ObjCMethodDecl</a>></td><td class="name" onclick="toggle('isClassMethod0')"><a name="isClassMethod0Anchor">isClassMethod</a></td><td></td></tr>5396<tr><td colspan="4" class="doc" id="isClassMethod0"><pre>Returns true when the Objective-C method declaration is a class method.5397 5398Example5399matcher = objcMethodDecl(isClassMethod())5400matches5401@interface I + (void)foo; @end5402but not5403@interface I - (void)bar; @end5404</pre></td></tr>5405 5406 5407<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html">ObjCMethodDecl</a>></td><td class="name" onclick="toggle('isDefinition2')"><a name="isDefinition2Anchor">isDefinition</a></td><td></td></tr>5408<tr><td colspan="4" class="doc" id="isDefinition2"><pre>Matches if a declaration has a body attached.5409 5410Example matches A, va, fa5411 class A {};5412 class B; // Doesn't match, as it has no body.5413 int va;5414 extern int vb; // Doesn't match, as it doesn't define the variable.5415 void fa() {}5416 void fb(); // Doesn't match, as it has no body.5417 @interface X5418 - (void)ma; // Doesn't match, interface is declaration.5419 @end5420 @implementation X5421 - (void)ma {}5422 @end5423 5424Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagDecl.html">TagDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>,5425 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html">ObjCMethodDecl</a>>5426</pre></td></tr>5427 5428 5429<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html">ObjCMethodDecl</a>></td><td class="name" onclick="toggle('isInstanceMethod0')"><a name="isInstanceMethod0Anchor">isInstanceMethod</a></td><td></td></tr>5430<tr><td colspan="4" class="doc" id="isInstanceMethod0"><pre>Returns true when the Objective-C method declaration is an instance method.5431 5432Example5433matcher = objcMethodDecl(isInstanceMethod())5434matches5435@interface I - (void)bar; @end5436but not5437@interface I + (void)foo; @end5438</pre></td></tr>5439 5440 5441<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html">ParmVarDecl</a>></td><td class="name" onclick="toggle('hasDefaultArgument0')"><a name="hasDefaultArgument0Anchor">hasDefaultArgument</a></td><td></td></tr>5442<tr><td colspan="4" class="doc" id="hasDefaultArgument0"><pre>Matches a declaration that has default arguments.5443 5444Example matches y (matcher = parmVarDecl(hasDefaultArgument()))5445void x(int val) {}5446void y(int val = 0) {}5447 5448Deprecated. Use hasInitializer() instead to be able to5449match on the contents of the default argument. For example:5450 5451void x(int val = 7) {}5452void y(int val = 42) {}5453parmVarDecl(hasInitializer(integerLiteral(equals(42))))5454 matches the parameter of y5455 5456A matcher such as5457 parmVarDecl(hasInitializer(anything()))5458is equivalent to parmVarDecl(hasDefaultArgument()).5459</pre></td></tr>5460 5461 5462<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html">ParmVarDecl</a>></td><td class="name" onclick="toggle('isAtPosition0')"><a name="isAtPosition0Anchor">isAtPosition</a></td><td>unsigned N</td></tr>5463<tr><td colspan="4" class="doc" id="isAtPosition0"><pre>Matches the ParmVarDecl nodes that are at the N'th position in the parameter5464list. The parameter list could be that of either a block, function, or5465objc-method.5466 5467 5468Given5469 5470void f(int a, int b, int c) {5471}5472 5473``parmVarDecl(isAtPosition(0))`` matches ``int a``.5474 5475``parmVarDecl(isAtPosition(1))`` matches ``int b``.5476</pre></td></tr>5477 5478 5479<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('asString0')"><a name="asString0Anchor">asString</a></td><td>std::string Name</td></tr>5480<tr><td colspan="4" class="doc" id="asString0"><pre>Matches if the matched type is represented by the given string.5481 5482Given5483 class Y { public: void x(); };5484 void z() { Y* y; y->x(); }5485cxxMemberCallExpr(on(hasType(asString("class Y *"))))5486 matches y->x()5487</pre></td></tr>5488 5489 5490<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('equalsBoundNode3')"><a name="equalsBoundNode3Anchor">equalsBoundNode</a></td><td>std::string ID</td></tr>5491<tr><td colspan="4" class="doc" id="equalsBoundNode3"><pre>Matches if a node equals a previously bound node.5492 5493Matches a node if it equals the node previously bound to ID.5494 5495Given5496 class X { int a; int b; };5497cxxRecordDecl(5498 has(fieldDecl(hasName("a"), hasType(type().bind("t")))),5499 has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t"))))))5500 matches the class X, as a and b have the same type.5501 5502Note that when multiple matches are involved via forEach* matchers,5503equalsBoundNodes acts as a filter.5504For example:5505compoundStmt(5506 forEachDescendant(varDecl().bind("d")),5507 forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d"))))))5508will trigger a match for each combination of variable declaration5509and reference to that variable declaration within a compound statement.5510</pre></td></tr>5511 5512 5513<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('hasLocalQualifiers0')"><a name="hasLocalQualifiers0Anchor">hasLocalQualifiers</a></td><td></td></tr>5514<tr><td colspan="4" class="doc" id="hasLocalQualifiers0"><pre>Matches QualType nodes that have local CV-qualifiers attached to5515the node, not hidden within a typedef.5516 5517Given5518 typedef const int const_int;5519 const_int i;5520 int *const j;5521 int *volatile k;5522 int m;5523varDecl(hasType(hasLocalQualifiers())) matches only j and k.5524i is const-qualified but the qualifier is not local.5525</pre></td></tr>5526 5527 5528<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('isAnyCharacter0')"><a name="isAnyCharacter0Anchor">isAnyCharacter</a></td><td></td></tr>5529<tr><td colspan="4" class="doc" id="isAnyCharacter0"><pre>Matches QualType nodes that are of character type.5530 5531Given5532 void a(char);5533 void b(wchar_t);5534 void c(double);5535functionDecl(hasAnyParameter(hasType(isAnyCharacter())))5536matches "a(char)", "b(wchar_t)", but not "c(double)".5537</pre></td></tr>5538 5539 5540<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('isAnyPointer0')"><a name="isAnyPointer0Anchor">isAnyPointer</a></td><td></td></tr>5541<tr><td colspan="4" class="doc" id="isAnyPointer0"><pre>Matches QualType nodes that are of any pointer type; this includes5542the Objective-C object pointer type, which is different despite being5543syntactically similar.5544 5545Given5546 int *i = nullptr;5547 5548 @interface Foo5549 @end5550 Foo *f;5551 5552 int j;5553varDecl(hasType(isAnyPointer()))5554 matches "int *i" and "Foo *f", but not "int j".5555</pre></td></tr>5556 5557 5558<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('isConstQualified0')"><a name="isConstQualified0Anchor">isConstQualified</a></td><td></td></tr>5559<tr><td colspan="4" class="doc" id="isConstQualified0"><pre>Matches QualType nodes that are const-qualified, i.e., that5560include "top-level" const.5561 5562Given5563 void a(int);5564 void b(int const);5565 void c(const int);5566 void d(const int*);5567 void e(int const) {};5568functionDecl(hasAnyParameter(hasType(isConstQualified())))5569 matches "void b(int const)", "void c(const int)" and5570 "void e(int const) {}". It does not match d as there5571 is no top-level const on the parameter type "const int *".5572</pre></td></tr>5573 5574 5575<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('isInteger0')"><a name="isInteger0Anchor">isInteger</a></td><td></td></tr>5576<tr><td colspan="4" class="doc" id="isInteger0"><pre>Matches QualType nodes that are of integer type.5577 5578Given5579 void a(int);5580 void b(unsigned long);5581 void c(double);5582functionDecl(hasAnyParameter(hasType(isInteger())))5583matches "a(int)", "b(unsigned long)", but not "c(double)".5584</pre></td></tr>5585 5586 5587<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('isSignedInteger0')"><a name="isSignedInteger0Anchor">isSignedInteger</a></td><td></td></tr>5588<tr><td colspan="4" class="doc" id="isSignedInteger0"><pre>Matches QualType nodes that are of signed integer type.5589 5590Given5591 void a(int);5592 void b(unsigned long);5593 void c(double);5594functionDecl(hasAnyParameter(hasType(isSignedInteger())))5595matches "a(int)", but not "b(unsigned long)" and "c(double)".5596</pre></td></tr>5597 5598 5599<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('isUnsignedInteger0')"><a name="isUnsignedInteger0Anchor">isUnsignedInteger</a></td><td></td></tr>5600<tr><td colspan="4" class="doc" id="isUnsignedInteger0"><pre>Matches QualType nodes that are of unsigned integer type.5601 5602Given5603 void a(int);5604 void b(unsigned long);5605 void c(double);5606functionDecl(hasAnyParameter(hasType(isUnsignedInteger())))5607matches "b(unsigned long)", but not "a(int)" and "c(double)".5608</pre></td></tr>5609 5610 5611<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('isVolatileQualified0')"><a name="isVolatileQualified0Anchor">isVolatileQualified</a></td><td></td></tr>5612<tr><td colspan="4" class="doc" id="isVolatileQualified0"><pre>Matches QualType nodes that are volatile-qualified, i.e., that5613include "top-level" volatile.5614 5615Given5616 void a(int);5617 void b(int volatile);5618 void c(volatile int);5619 void d(volatile int*);5620 void e(int volatile) {};5621functionDecl(hasAnyParameter(hasType(isVolatileQualified())))5622 matches "void b(int volatile)", "void c(volatile int)" and5623 "void e(int volatile) {}". It does not match d as there5624 is no top-level volatile on the parameter type "volatile int *".5625</pre></td></tr>5626 5627 5628<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('equalsBoundNode0')"><a name="equalsBoundNode0Anchor">equalsBoundNode</a></td><td>std::string ID</td></tr>5629<tr><td colspan="4" class="doc" id="equalsBoundNode0"><pre>Matches if a node equals a previously bound node.5630 5631Matches a node if it equals the node previously bound to ID.5632 5633Given5634 class X { int a; int b; };5635cxxRecordDecl(5636 has(fieldDecl(hasName("a"), hasType(type().bind("t")))),5637 has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t"))))))5638 matches the class X, as a and b have the same type.5639 5640Note that when multiple matches are involved via forEach* matchers,5641equalsBoundNodes acts as a filter.5642For example:5643compoundStmt(5644 forEachDescendant(varDecl().bind("d")),5645 forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d"))))))5646will trigger a match for each combination of variable declaration5647and reference to that variable declaration within a compound statement.5648</pre></td></tr>5649 5650 5651<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('equalsNode1')"><a name="equalsNode1Anchor">equalsNode</a></td><td>const Stmt* Other</td></tr>5652<tr><td colspan="4" class="doc" id="equalsNode1"><pre>Matches if a node equals another node.5653 5654Stmt has pointer identity in the AST.5655</pre></td></tr>5656 5657 5658<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('isExpandedFromMacro1')"><a name="isExpandedFromMacro1Anchor">isExpandedFromMacro</a></td><td>std::string MacroName</td></tr>5659<tr><td colspan="4" class="doc" id="isExpandedFromMacro1"><pre>Matches statements that are (transitively) expanded from the named macro.5660Does not match if only part of the statement is expanded from that macro or5661if different parts of the statement are expanded from different5662appearances of the macro.5663</pre></td></tr>5664 5665 5666<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('isExpansionInFileMatching1')"><a name="isExpansionInFileMatching1Anchor">isExpansionInFileMatching</a></td><td>StringRef RegExp, Regex::RegexFlags Flags = NoFlags</td></tr>5667<tr><td colspan="4" class="doc" id="isExpansionInFileMatching1"><pre>Matches AST nodes that were expanded within files whose name is5668partially matching a given regex.5669 5670Example matches Y but not X5671 (matcher = cxxRecordDecl(isExpansionInFileMatching("AST.*"))5672 #include "ASTMatcher.h"5673 class X {};5674ASTMatcher.h:5675 class Y {};5676 5677Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>>5678 5679If the matcher is used in clang-query, RegexFlags parameter5680should be passed as a quoted string. e.g: "NoFlags".5681Flags can be combined with '|' example "IgnoreCase | BasicRegex"5682</pre></td></tr>5683 5684 5685<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('isExpansionInMainFile1')"><a name="isExpansionInMainFile1Anchor">isExpansionInMainFile</a></td><td></td></tr>5686<tr><td colspan="4" class="doc" id="isExpansionInMainFile1"><pre>Matches AST nodes that were expanded within the main-file.5687 5688Example matches X but not Y5689 (matcher = cxxRecordDecl(isExpansionInMainFile())5690 #include <Y.h>5691 class X {};5692Y.h:5693 class Y {};5694 5695Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>>5696</pre></td></tr>5697 5698 5699<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('isExpansionInSystemHeader1')"><a name="isExpansionInSystemHeader1Anchor">isExpansionInSystemHeader</a></td><td></td></tr>5700<tr><td colspan="4" class="doc" id="isExpansionInSystemHeader1"><pre>Matches AST nodes that were expanded within system-header-files.5701 5702Example matches Y but not X5703 (matcher = cxxRecordDecl(isExpansionInSystemHeader())5704 #include <SystemHeader.h>5705 class X {};5706SystemHeader.h:5707 class Y {};5708 5709Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>>5710</pre></td></tr>5711 5712 5713<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('isInTemplateInstantiation0')"><a name="isInTemplateInstantiation0Anchor">isInTemplateInstantiation</a></td><td></td></tr>5714<tr><td colspan="4" class="doc" id="isInTemplateInstantiation0"><pre>Matches statements inside of a template instantiation.5715 5716Given5717 int j;5718 template<typename T> void A(T t) { T i; j += 42;}5719 A(0);5720 A(0U);5721declStmt(isInTemplateInstantiation())5722 matches 'int i;' and 'unsigned i'.5723unless(stmt(isInTemplateInstantiation()))5724 will NOT match j += 42; as it's shared between the template definition and5725 instantiation.5726</pre></td></tr>5727 5728 5729<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1StringLiteral.html">StringLiteral</a>></td><td class="name" onclick="toggle('hasSize1')"><a name="hasSize1Anchor">hasSize</a></td><td>unsigned N</td></tr>5730<tr><td colspan="4" class="doc" id="hasSize1"><pre>Matches nodes that have the specified size.5731 5732Given5733 int a[42];5734 int b[2 * 21];5735 int c[41], d[43];5736 char *s = "abcd";5737 wchar_t *ws = L"abcd";5738 char *w = "a";5739constantArrayType(hasSize(42))5740 matches "int a[42]" and "int b[2 * 21]"5741stringLiteral(hasSize(4))5742 matches "abcd", L"abcd"5743</pre></td></tr>5744 5745 5746<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagDecl.html">TagDecl</a>></td><td class="name" onclick="toggle('isClass0')"><a name="isClass0Anchor">isClass</a></td><td></td></tr>5747<tr><td colspan="4" class="doc" id="isClass0"><pre>Matches TagDecl object that are spelled with "class."5748 5749Example matches C, but not S, U or E.5750 struct S {};5751 class C {};5752 union U {};5753 enum E {};5754</pre></td></tr>5755 5756 5757<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagDecl.html">TagDecl</a>></td><td class="name" onclick="toggle('isDefinition0')"><a name="isDefinition0Anchor">isDefinition</a></td><td></td></tr>5758<tr><td colspan="4" class="doc" id="isDefinition0"><pre>Matches if a declaration has a body attached.5759 5760Example matches A, va, fa5761 class A {};5762 class B; // Doesn't match, as it has no body.5763 int va;5764 extern int vb; // Doesn't match, as it doesn't define the variable.5765 void fa() {}5766 void fb(); // Doesn't match, as it has no body.5767 @interface X5768 - (void)ma; // Doesn't match, interface is declaration.5769 @end5770 @implementation X5771 - (void)ma {}5772 @end5773 5774Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagDecl.html">TagDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>,5775 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html">ObjCMethodDecl</a>>5776</pre></td></tr>5777 5778 5779<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagDecl.html">TagDecl</a>></td><td class="name" onclick="toggle('isEnum0')"><a name="isEnum0Anchor">isEnum</a></td><td></td></tr>5780<tr><td colspan="4" class="doc" id="isEnum0"><pre>Matches TagDecl object that are spelled with "enum."5781 5782Example matches E, but not C, S or U.5783 struct S {};5784 class C {};5785 union U {};5786 enum E {};5787</pre></td></tr>5788 5789 5790<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagDecl.html">TagDecl</a>></td><td class="name" onclick="toggle('isStruct0')"><a name="isStruct0Anchor">isStruct</a></td><td></td></tr>5791<tr><td colspan="4" class="doc" id="isStruct0"><pre>Matches TagDecl object that are spelled with "struct."5792 5793Example matches S, but not C, U or E.5794 struct S {};5795 class C {};5796 union U {};5797 enum E {};5798</pre></td></tr>5799 5800 5801<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagDecl.html">TagDecl</a>></td><td class="name" onclick="toggle('isUnion0')"><a name="isUnion0Anchor">isUnion</a></td><td></td></tr>5802<tr><td colspan="4" class="doc" id="isUnion0"><pre>Matches TagDecl object that are spelled with "union."5803 5804Example matches U, but not C, S or E.5805 struct S {};5806 class C {};5807 union U {};5808 enum E {};5809</pre></td></tr>5810 5811 5812<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>></td><td class="name" onclick="toggle('equalsIntegralValue0')"><a name="equalsIntegralValue0Anchor">equalsIntegralValue</a></td><td>std::string Value</td></tr>5813<tr><td colspan="4" class="doc" id="equalsIntegralValue0"><pre>Matches a TemplateArgument of integral type with a given value.5814 5815Note that 'Value' is a string as the template argument's value is5816an arbitrary precision integer. 'Value' must be equal to the canonical5817representation of that integral value in base 10.5818 5819Given5820 template<int T> struct C {};5821 C<42> c;5822classTemplateSpecializationDecl(5823 hasAnyTemplateArgument(equalsIntegralValue("42")))5824 matches the implicit instantiation of C in C<42>.5825</pre></td></tr>5826 5827 5828<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>></td><td class="name" onclick="toggle('isIntegral0')"><a name="isIntegral0Anchor">isIntegral</a></td><td></td></tr>5829<tr><td colspan="4" class="doc" id="isIntegral0"><pre>Matches a TemplateArgument that is an integral value.5830 5831Given5832 template<int T> struct C {};5833 C<42> c;5834classTemplateSpecializationDecl(5835 hasAnyTemplateArgument(isIntegral()))5836 matches the implicit instantiation of C in C<42>5837 with isIntegral() matching 42.5838</pre></td></tr>5839 5840 5841<tr><td>Matcher<TemplateSpecializationType></td><td class="name" onclick="toggle('templateArgumentCountIs3')"><a name="templateArgumentCountIs3Anchor">templateArgumentCountIs</a></td><td>unsigned N</td></tr>5842<tr><td colspan="4" class="doc" id="templateArgumentCountIs3"><pre>Matches if the number of template arguments equals N.5843 5844Given5845 template<typename T> struct C {};5846 C<int> c;5847 template<typename T> void f() {}5848 void func() { f<int>(); };5849 5850classTemplateSpecializationDecl(templateArgumentCountIs(1))5851 matches C<int>.5852 5853functionDecl(templateArgumentCountIs(1))5854 matches f<int>();5855</pre></td></tr>5856 5857 5858<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td><td class="name" onclick="toggle('isExpandedFromMacro2')"><a name="isExpandedFromMacro2Anchor">isExpandedFromMacro</a></td><td>std::string MacroName</td></tr>5859<tr><td colspan="4" class="doc" id="isExpandedFromMacro2"><pre>Matches statements that are (transitively) expanded from the named macro.5860Does not match if only part of the statement is expanded from that macro or5861if different parts of the statement are expanded from different5862appearances of the macro.5863</pre></td></tr>5864 5865 5866<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td><td class="name" onclick="toggle('isExpansionInFileMatching2')"><a name="isExpansionInFileMatching2Anchor">isExpansionInFileMatching</a></td><td>StringRef RegExp, Regex::RegexFlags Flags = NoFlags</td></tr>5867<tr><td colspan="4" class="doc" id="isExpansionInFileMatching2"><pre>Matches AST nodes that were expanded within files whose name is5868partially matching a given regex.5869 5870Example matches Y but not X5871 (matcher = cxxRecordDecl(isExpansionInFileMatching("AST.*"))5872 #include "ASTMatcher.h"5873 class X {};5874ASTMatcher.h:5875 class Y {};5876 5877Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>>5878 5879If the matcher is used in clang-query, RegexFlags parameter5880should be passed as a quoted string. e.g: "NoFlags".5881Flags can be combined with '|' example "IgnoreCase | BasicRegex"5882</pre></td></tr>5883 5884 5885<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td><td class="name" onclick="toggle('isExpansionInMainFile2')"><a name="isExpansionInMainFile2Anchor">isExpansionInMainFile</a></td><td></td></tr>5886<tr><td colspan="4" class="doc" id="isExpansionInMainFile2"><pre>Matches AST nodes that were expanded within the main-file.5887 5888Example matches X but not Y5889 (matcher = cxxRecordDecl(isExpansionInMainFile())5890 #include <Y.h>5891 class X {};5892Y.h:5893 class Y {};5894 5895Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>>5896</pre></td></tr>5897 5898 5899<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td><td class="name" onclick="toggle('isExpansionInSystemHeader2')"><a name="isExpansionInSystemHeader2Anchor">isExpansionInSystemHeader</a></td><td></td></tr>5900<tr><td colspan="4" class="doc" id="isExpansionInSystemHeader2"><pre>Matches AST nodes that were expanded within system-header-files.5901 5902Example matches Y but not X5903 (matcher = cxxRecordDecl(isExpansionInSystemHeader())5904 #include <SystemHeader.h>5905 class X {};5906SystemHeader.h:5907 class Y {};5908 5909Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>>5910</pre></td></tr>5911 5912 5913<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('booleanType0')"><a name="booleanType0Anchor">booleanType</a></td><td></td></tr>5914<tr><td colspan="4" class="doc" id="booleanType0"><pre>Matches type bool.5915 5916Given5917 struct S { bool func(); };5918functionDecl(returns(booleanType()))5919 matches "bool func();"5920</pre></td></tr>5921 5922 5923<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('equalsBoundNode2')"><a name="equalsBoundNode2Anchor">equalsBoundNode</a></td><td>std::string ID</td></tr>5924<tr><td colspan="4" class="doc" id="equalsBoundNode2"><pre>Matches if a node equals a previously bound node.5925 5926Matches a node if it equals the node previously bound to ID.5927 5928Given5929 class X { int a; int b; };5930cxxRecordDecl(5931 has(fieldDecl(hasName("a"), hasType(type().bind("t")))),5932 has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t"))))))5933 matches the class X, as a and b have the same type.5934 5935Note that when multiple matches are involved via forEach* matchers,5936equalsBoundNodes acts as a filter.5937For example:5938compoundStmt(5939 forEachDescendant(varDecl().bind("d")),5940 forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d"))))))5941will trigger a match for each combination of variable declaration5942and reference to that variable declaration within a compound statement.5943</pre></td></tr>5944 5945 5946<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('equalsNode2')"><a name="equalsNode2Anchor">equalsNode</a></td><td>const Type* Other</td></tr>5947<tr><td colspan="4" class="doc" id="equalsNode2"><pre>Matches if a node equals another node.5948 5949Type has pointer identity in the AST.5950</pre></td></tr>5951 5952 5953<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('realFloatingPointType0')"><a name="realFloatingPointType0Anchor">realFloatingPointType</a></td><td></td></tr>5954<tr><td colspan="4" class="doc" id="realFloatingPointType0"><pre>Matches any real floating-point type (float, double, long double).5955 5956Given5957 int i;5958 float f;5959realFloatingPointType()5960 matches "float f" but not "int i"5961</pre></td></tr>5962 5963 5964<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('voidType0')"><a name="voidType0Anchor">voidType</a></td><td></td></tr>5965<tr><td colspan="4" class="doc" id="voidType0"><pre>Matches type void.5966 5967Given5968 struct S { void func(); };5969functionDecl(returns(voidType()))5970 matches "void func();"5971</pre></td></tr>5972 5973 5974<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html">UnaryExprOrTypeTraitExpr</a>></td><td class="name" onclick="toggle('ofKind0')"><a name="ofKind0Anchor">ofKind</a></td><td>UnaryExprOrTypeTrait Kind</td></tr>5975<tr><td colspan="4" class="doc" id="ofKind0"><pre>Matches unary expressions of a certain kind.5976 5977Given5978 int x;5979 int s = sizeof(x) + alignof(x)5980unaryExprOrTypeTraitExpr(ofKind(UETT_SizeOf))5981 matches sizeof(x)5982 5983If the matcher is use from clang-query, UnaryExprOrTypeTrait parameter5984should be passed as a quoted string. e.g., ofKind("UETT_SizeOf").5985</pre></td></tr>5986 5987 5988<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnaryOperator.html">UnaryOperator</a>></td><td class="name" onclick="toggle('hasAnyOperatorName3')"><a name="hasAnyOperatorName3Anchor">hasAnyOperatorName</a></td><td>StringRef, ..., StringRef</td></tr>5989<tr><td colspan="4" class="doc" id="hasAnyOperatorName3"><pre>Matches operator expressions (binary or unary) that have any of the5990specified names.5991 5992 hasAnyOperatorName("+", "-")5993 Is equivalent to5994 anyOf(hasOperatorName("+"), hasOperatorName("-"))5995</pre></td></tr>5996 5997 5998<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnaryOperator.html">UnaryOperator</a>></td><td class="name" onclick="toggle('hasOperatorName4')"><a name="hasOperatorName4Anchor">hasOperatorName</a></td><td>std::string Name</td></tr>5999<tr><td colspan="4" class="doc" id="hasOperatorName4"><pre>Matches the operator Name of operator expressions and fold expressions6000(binary or unary).6001 6002Example matches a || b (matcher = binaryOperator(hasOperatorName("||")))6003 !(a || b)6004 6005Example matches `(0 + ... + args)`6006 (matcher = cxxFoldExpr(hasOperatorName("+")))6007 template <typename... Args>6008 auto sum(Args... args) {6009 return (0 + ... + args);6010 }6011</pre></td></tr>6012 6013 6014<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedMemberExpr.html">UnresolvedMemberExpr</a>></td><td class="name" onclick="toggle('isArrow1')"><a name="isArrow1Anchor">isArrow</a></td><td></td></tr>6015<tr><td colspan="4" class="doc" id="isArrow1"><pre>Matches member expressions that are called with '->' as opposed6016to '.'.6017 6018Member calls on the implicit this pointer match as called with '->'.6019 6020Given6021 class Y {6022 void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; }6023 template <class T> void f() { this->f<T>(); f<T>(); }6024 int a;6025 static int b;6026 };6027 template <class T>6028 class Z {6029 void x() { this->m; }6030 };6031memberExpr(isArrow())6032 matches this->x, x, y.x, a, this->b6033cxxDependentScopeMemberExpr(isArrow())6034 matches this->m6035unresolvedMemberExpr(isArrow())6036 matches this->f<T>, f<T>6037</pre></td></tr>6038 6039 6040<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>></td><td class="name" onclick="toggle('hasAutomaticStorageDuration0')"><a name="hasAutomaticStorageDuration0Anchor">hasAutomaticStorageDuration</a></td><td></td></tr>6041<tr><td colspan="4" class="doc" id="hasAutomaticStorageDuration0"><pre>Matches a variable declaration that has automatic storage duration.6042 6043Example matches x, but not y, z, or a.6044(matcher = varDecl(hasAutomaticStorageDuration())6045void f() {6046 int x;6047 static int y;6048 thread_local int z;6049}6050int a;6051</pre></td></tr>6052 6053 6054<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>></td><td class="name" onclick="toggle('hasGlobalStorage0')"><a name="hasGlobalStorage0Anchor">hasGlobalStorage</a></td><td></td></tr>6055<tr><td colspan="4" class="doc" id="hasGlobalStorage0"><pre>Matches a variable declaration that does not have local storage.6056 6057Example matches y and z (matcher = varDecl(hasGlobalStorage())6058void f() {6059 int x;6060 static int y;6061}6062int z;6063</pre></td></tr>6064 6065 6066<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>></td><td class="name" onclick="toggle('hasLocalStorage0')"><a name="hasLocalStorage0Anchor">hasLocalStorage</a></td><td></td></tr>6067<tr><td colspan="4" class="doc" id="hasLocalStorage0"><pre>Matches a variable declaration that has function scope and is a6068non-static local variable.6069 6070Example matches x (matcher = varDecl(hasLocalStorage())6071void f() {6072 int x;6073 static int y;6074}6075int z;6076</pre></td></tr>6077 6078 6079<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>></td><td class="name" onclick="toggle('hasStaticStorageDuration0')"><a name="hasStaticStorageDuration0Anchor">hasStaticStorageDuration</a></td><td></td></tr>6080<tr><td colspan="4" class="doc" id="hasStaticStorageDuration0"><pre>Matches a variable declaration that has static storage duration.6081It includes the variable declared at namespace scope and those declared6082with "static" and "extern" storage class specifiers.6083 6084void f() {6085 int x;6086 static int y;6087 thread_local int z;6088}6089int a;6090static int b;6091extern int c;6092varDecl(hasStaticStorageDuration())6093 matches the function declaration y, a, b and c.6094</pre></td></tr>6095 6096 6097<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>></td><td class="name" onclick="toggle('hasThreadStorageDuration0')"><a name="hasThreadStorageDuration0Anchor">hasThreadStorageDuration</a></td><td></td></tr>6098<tr><td colspan="4" class="doc" id="hasThreadStorageDuration0"><pre>Matches a variable declaration that has thread storage duration.6099 6100Example matches z, but not x, z, or a.6101(matcher = varDecl(hasThreadStorageDuration())6102void f() {6103 int x;6104 static int y;6105 thread_local int z;6106}6107int a;6108</pre></td></tr>6109 6110 6111<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>></td><td class="name" onclick="toggle('isConstexpr0')"><a name="isConstexpr0Anchor">isConstexpr</a></td><td></td></tr>6112<tr><td colspan="4" class="doc" id="isConstexpr0"><pre>Matches constexpr variable and function declarations,6113 and if constexpr.6114 6115Given:6116 constexpr int foo = 42;6117 constexpr int bar();6118 void baz() { if constexpr(1 > 0) {} }6119varDecl(isConstexpr())6120 matches the declaration of foo.6121functionDecl(isConstexpr())6122 matches the declaration of bar.6123ifStmt(isConstexpr())6124 matches the if statement in baz.6125</pre></td></tr>6126 6127 6128<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>></td><td class="name" onclick="toggle('isConstinit0')"><a name="isConstinit0Anchor">isConstinit</a></td><td></td></tr>6129<tr><td colspan="4" class="doc" id="isConstinit0"><pre>Matches constinit variable declarations.6130 6131Given:6132 constinit int foo = 42;6133 constinit const char* bar = "bar";6134 int baz = 42;6135 [[clang::require_constant_initialization]] int xyz = 42;6136varDecl(isConstinit())6137 matches the declaration of `foo` and `bar`, but not `baz` and `xyz`.6138</pre></td></tr>6139 6140 6141<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>></td><td class="name" onclick="toggle('isDefinition1')"><a name="isDefinition1Anchor">isDefinition</a></td><td></td></tr>6142<tr><td colspan="4" class="doc" id="isDefinition1"><pre>Matches if a declaration has a body attached.6143 6144Example matches A, va, fa6145 class A {};6146 class B; // Doesn't match, as it has no body.6147 int va;6148 extern int vb; // Doesn't match, as it doesn't define the variable.6149 void fa() {}6150 void fb(); // Doesn't match, as it has no body.6151 @interface X6152 - (void)ma; // Doesn't match, interface is declaration.6153 @end6154 @implementation X6155 - (void)ma {}6156 @end6157 6158Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagDecl.html">TagDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>,6159 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html">ObjCMethodDecl</a>>6160</pre></td></tr>6161 6162 6163<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>></td><td class="name" onclick="toggle('isExceptionVariable0')"><a name="isExceptionVariable0Anchor">isExceptionVariable</a></td><td></td></tr>6164<tr><td colspan="4" class="doc" id="isExceptionVariable0"><pre>Matches a variable declaration that is an exception variable from6165a C++ catch block, or an Objective-C statement.6166 6167Example matches x (matcher = varDecl(isExceptionVariable())6168void f(int y) {6169 try {6170 } catch (int x) {6171 }6172}6173</pre></td></tr>6174 6175 6176<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>></td><td class="name" onclick="toggle('isExplicitTemplateSpecialization1')"><a name="isExplicitTemplateSpecialization1Anchor">isExplicitTemplateSpecialization</a></td><td></td></tr>6177<tr><td colspan="4" class="doc" id="isExplicitTemplateSpecialization1"><pre>Matches explicit template specializations of function, class, or6178static member variable template instantiations.6179 6180Given6181 template<typename T> void A(T t) { }6182 template<> void A(int N) { }6183functionDecl(isExplicitTemplateSpecialization())6184 matches the specialization A<int>().6185 6186Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>>6187</pre></td></tr>6188 6189 6190<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>></td><td class="name" onclick="toggle('isExternC1')"><a name="isExternC1Anchor">isExternC</a></td><td></td></tr>6191<tr><td colspan="4" class="doc" id="isExternC1"><pre>Matches extern "C" function or variable declarations.6192 6193Given:6194 extern "C" void f() {}6195 extern "C" { void g() {} }6196 void h() {}6197 extern "C" int x = 1;6198 extern "C" int y = 2;6199 int z = 3;6200functionDecl(isExternC())6201 matches the declaration of f and g, but not the declaration of h.6202varDecl(isExternC())6203 matches the declaration of x and y, but not the declaration of z.6204</pre></td></tr>6205 6206 6207<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>></td><td class="name" onclick="toggle('isInitCapture0')"><a name="isInitCapture0Anchor">isInitCapture</a></td><td></td></tr>6208<tr><td colspan="4" class="doc" id="isInitCapture0"><pre>Matches a variable serving as the implicit variable for a lambda init-6209capture.6210 6211Example matches x (matcher = varDecl(isInitCapture()))6212auto f = [x=3]() { return x; };6213</pre></td></tr>6214 6215 6216<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>></td><td class="name" onclick="toggle('isInline2')"><a name="isInline2Anchor">isInline</a></td><td></td></tr>6217<tr><td colspan="4" class="doc" id="isInline2"><pre>Matches functions, variables and namespace declarations that are marked with6218the inline keyword.6219 6220Given6221 inline void f();6222 void g();6223 namespace n {6224 inline namespace m {}6225 }6226 inline int Foo = 5;6227functionDecl(isInline()) will match ::f().6228namespaceDecl(isInline()) will match n::m.6229varDecl(isInline()) will match Foo;6230</pre></td></tr>6231 6232 6233<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>></td><td class="name" onclick="toggle('isStaticLocal0')"><a name="isStaticLocal0Anchor">isStaticLocal</a></td><td></td></tr>6234<tr><td colspan="4" class="doc" id="isStaticLocal0"><pre>Matches a static variable with local scope.6235 6236Example matches y (matcher = varDecl(isStaticLocal()))6237void f() {6238 int x;6239 static int y;6240}6241static int z;6242</pre></td></tr>6243 6244 6245<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>></td><td class="name" onclick="toggle('isStaticStorageClass1')"><a name="isStaticStorageClass1Anchor">isStaticStorageClass</a></td><td></td></tr>6246<tr><td colspan="4" class="doc" id="isStaticStorageClass1"><pre>Matches variable/function declarations that have "static" storage6247class specifier ("static" keyword) written in the source.6248 6249Given:6250 static void f() {}6251 static int i = 0;6252 extern int j;6253 int k;6254functionDecl(isStaticStorageClass())6255 matches the function declaration f.6256varDecl(isStaticStorageClass())6257 matches the variable declaration i.6258</pre></td></tr>6259 6260 6261<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>></td><td class="name" onclick="toggle('isTemplateInstantiation1')"><a name="isTemplateInstantiation1Anchor">isTemplateInstantiation</a></td><td></td></tr>6262<tr><td colspan="4" class="doc" id="isTemplateInstantiation1"><pre>Matches template instantiations of function, class, or static6263member variable template instantiations.6264 6265Given6266 template <typename T> class X {}; class A {}; X<A> x;6267or6268 template <typename T> class X {}; class A {}; template class X<A>;6269or6270 template <typename T> class X {}; class A {}; extern template class X<A>;6271cxxRecordDecl(hasName("::X"), isTemplateInstantiation())6272 matches the template instantiation of X<A>.6273 6274But given6275 template <typename T> class X {}; class A {};6276 template <> class X<A> {}; X<A> x;6277cxxRecordDecl(hasName("::X"), isTemplateInstantiation())6278 does not match, as X<A> is an explicit template specialization.6279 6280Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>>6281</pre></td></tr>6282 6283 6284<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarTemplateSpecializationDecl.html">VarTemplateSpecializationDecl</a>></td><td class="name" onclick="toggle('templateArgumentCountIs1')"><a name="templateArgumentCountIs1Anchor">templateArgumentCountIs</a></td><td>unsigned N</td></tr>6285<tr><td colspan="4" class="doc" id="templateArgumentCountIs1"><pre>Matches if the number of template arguments equals N.6286 6287Given6288 template<typename T> struct C {};6289 C<int> c;6290 template<typename T> void f() {}6291 void func() { f<int>(); };6292 6293classTemplateSpecializationDecl(templateArgumentCountIs(1))6294 matches C<int>.6295 6296functionDecl(templateArgumentCountIs(1))6297 matches f<int>();6298</pre></td></tr>6299 6300<!--END_NARROWING_MATCHERS -->6301</table>6302 6303<!-- ======================================================================= -->6304<h2 id="traversal-matchers">AST Traversal Matchers</h2>6305<!-- ======================================================================= -->6306 6307<p>Traversal matchers specify the relationship to other nodes that are6308reachable from the current node.</p>6309 6310<p>Note that there are special traversal matchers (has, hasDescendant, forEach and6311forEachDescendant) which work on all nodes and allow users to write more generic6312match expressions.</p>6313 6314<table>6315<tr style="text-align:left"><th>Return type</th><th>Name</th><th>Parameters</th></tr>6316<!-- START_TRAVERSAL_MATCHERS -->6317 6318<tr><td>Matcher<*></td><td class="name" onclick="toggle('binaryOperation0')"><a name="binaryOperation0Anchor">binaryOperation</a></td><td>Matcher<*>...Matcher<*></td></tr>6319<tr><td colspan="4" class="doc" id="binaryOperation0"><pre>Matches nodes which can be used with binary operators.6320 6321The code6322 var1 != var2;6323might be represented in the clang AST as a binaryOperator, a6324cxxOperatorCallExpr or a cxxRewrittenBinaryOperator, depending on6325 6326* whether the types of var1 and var2 are fundamental (binaryOperator) or at6327 least one is a class type (cxxOperatorCallExpr)6328* whether the code appears in a template declaration, if at least one of the6329 vars is a dependent-type (binaryOperator)6330* whether the code relies on a rewritten binary operator, such as a6331spaceship operator or an inverted equality operator6332(cxxRewrittenBinaryOperator)6333 6334This matcher elides details in places where the matchers for the nodes are6335compatible.6336 6337Given6338 binaryOperation(6339 hasOperatorName("!="),6340 hasLHS(expr().bind("lhs")),6341 hasRHS(expr().bind("rhs"))6342 )6343matches each use of "!=" in:6344 struct S{6345 bool operator!=(const S&) const;6346 };6347 6348 void foo()6349 {6350 1 != 2;6351 S() != S();6352 }6353 6354 template<typename T>6355 void templ()6356 {6357 1 != 2;6358 T() != S();6359 }6360 struct HasOpEq6361 {6362 bool operator==(const HasOpEq &) const;6363 };6364 6365 void inverse()6366 {6367 HasOpEq s1;6368 HasOpEq s2;6369 if (s1 != s2)6370 return;6371 }6372 6373 struct HasSpaceship6374 {6375 bool operator<=>(const HasOpEq &) const;6376 };6377 6378 void use_spaceship()6379 {6380 HasSpaceship s1;6381 HasSpaceship s2;6382 if (s1 != s2)6383 return;6384 }6385</pre></td></tr>6386 6387 6388<tr><td>Matcher<*></td><td class="name" onclick="toggle('eachOf0')"><a name="eachOf0Anchor">eachOf</a></td><td>Matcher<*>, ..., Matcher<*></td></tr>6389<tr><td colspan="4" class="doc" id="eachOf0"><pre>Matches if any of the given matchers matches.6390 6391Unlike anyOf, eachOf will generate a match result for each6392matching submatcher.6393 6394For example, in:6395 class A { int a; int b; };6396The matcher:6397 cxxRecordDecl(eachOf(has(fieldDecl(hasName("a")).bind("v")),6398 has(fieldDecl(hasName("b")).bind("v"))))6399will generate two results binding "v", the first of which binds6400the field declaration of a, the second the field declaration of6401b.6402 6403Usable as: Any Matcher6404</pre></td></tr>6405 6406 6407<tr><td>Matcher<*></td><td class="name" onclick="toggle('findAll0')"><a name="findAll0Anchor">findAll</a></td><td>Matcher<*> Matcher</td></tr>6408<tr><td colspan="4" class="doc" id="findAll0"><pre>Matches if the node or any descendant matches.6409 6410Generates results for each match.6411 6412For example, in:6413 class A { class B {}; class C {}; };6414The matcher:6415 cxxRecordDecl(hasName("::A"),6416 findAll(cxxRecordDecl(isDefinition()).bind("m")))6417will generate results for A, B and C.6418 6419Usable as: Any Matcher6420</pre></td></tr>6421 6422 6423<tr><td>Matcher<*></td><td class="name" onclick="toggle('forEachDescendant0')"><a name="forEachDescendant0Anchor">forEachDescendant</a></td><td>Matcher<*></td></tr>6424<tr><td colspan="4" class="doc" id="forEachDescendant0"><pre>Matches AST nodes that have descendant AST nodes that match the6425provided matcher.6426 6427Example matches X, A, A::X, B, B::C, B::C::X6428 (matcher = cxxRecordDecl(forEachDescendant(cxxRecordDecl(hasName("X")))))6429 class X {};6430 class A { class X {}; }; // Matches A, because A::X is a class of name6431 // X inside A.6432 class B { class C { class X {}; }; };6433 6434DescendantT must be an AST base type.6435 6436As opposed to 'hasDescendant', 'forEachDescendant' will cause a match for6437each result that matches instead of only on the first one.6438 6439Note: Recursively combined ForEachDescendant can cause many matches:6440 cxxRecordDecl(forEachDescendant(cxxRecordDecl(6441 forEachDescendant(cxxRecordDecl())6442 )))6443will match 10 times (plus injected class name matches) on:6444 class A { class B { class C { class D { class E {}; }; }; }; };6445 6446Usable as: Any Matcher6447</pre></td></tr>6448 6449 6450<tr><td>Matcher<*></td><td class="name" onclick="toggle('forEach0')"><a name="forEach0Anchor">forEach</a></td><td>Matcher<*></td></tr>6451<tr><td colspan="4" class="doc" id="forEach0"><pre>Matches AST nodes that have child AST nodes that match the6452provided matcher.6453 6454Example matches X, Y, Y::X, Z::Y, Z::Y::X6455 (matcher = cxxRecordDecl(forEach(cxxRecordDecl(hasName("X")))6456 class X {};6457 class Y { class X {}; }; // Matches Y, because Y::X is a class of name X6458 // inside Y.6459 class Z { class Y { class X {}; }; }; // Does not match Z.6460 6461ChildT must be an AST base type.6462 6463As opposed to 'has', 'forEach' will cause a match for each result that6464matches instead of only on the first one.6465 6466Usable as: Any Matcher6467</pre></td></tr>6468 6469 6470<tr><td>Matcher<*></td><td class="name" onclick="toggle('hasAncestor0')"><a name="hasAncestor0Anchor">hasAncestor</a></td><td>Matcher<*></td></tr>6471<tr><td colspan="4" class="doc" id="hasAncestor0"><pre>Matches AST nodes that have an ancestor that matches the provided6472matcher.6473 6474Given6475void f() { if (true) { int x = 42; } }6476void g() { for (;;) { int x = 43; } }6477expr(integerLiteral(hasAncestor(ifStmt()))) matches 42, but not 43.6478 6479Usable as: Any Matcher6480</pre></td></tr>6481 6482 6483<tr><td>Matcher<*></td><td class="name" onclick="toggle('hasDescendant0')"><a name="hasDescendant0Anchor">hasDescendant</a></td><td>Matcher<*></td></tr>6484<tr><td colspan="4" class="doc" id="hasDescendant0"><pre>Matches AST nodes that have descendant AST nodes that match the6485provided matcher.6486 6487Example matches X, Y, Z6488 (matcher = cxxRecordDecl(hasDescendant(cxxRecordDecl(hasName("X")))))6489 class X {}; // Matches X, because X::X is a class of name X inside X.6490 class Y { class X {}; };6491 class Z { class Y { class X {}; }; };6492 6493DescendantT must be an AST base type.6494 6495Usable as: Any Matcher6496</pre></td></tr>6497 6498 6499<tr><td>Matcher<*></td><td class="name" onclick="toggle('has0')"><a name="has0Anchor">has</a></td><td>Matcher<*></td></tr>6500<tr><td colspan="4" class="doc" id="has0"><pre>Matches AST nodes that have child AST nodes that match the6501provided matcher.6502 6503Example matches X, Y6504 (matcher = cxxRecordDecl(has(cxxRecordDecl(hasName("X")))6505 class X {}; // Matches X, because X::X is a class of name X inside X.6506 class Y { class X {}; };6507 class Z { class Y { class X {}; }; }; // Does not match Z.6508 6509ChildT must be an AST base type.6510 6511Usable as: Any Matcher6512Note that has is direct matcher, so it also matches things like implicit6513casts and paren casts. If you are matching with expr then you should6514probably consider using ignoringParenImpCasts like:6515has(ignoringParenImpCasts(expr())).6516</pre></td></tr>6517 6518 6519<tr><td>Matcher<*></td><td class="name" onclick="toggle('hasParent0')"><a name="hasParent0Anchor">hasParent</a></td><td>Matcher<*></td></tr>6520<tr><td colspan="4" class="doc" id="hasParent0"><pre>Matches AST nodes that have a parent that matches the provided6521matcher.6522 6523Given6524void f() { for (;;) { int x = 42; if (true) { int x = 43; } } }6525compoundStmt(hasParent(ifStmt())) matches "{ int x = 43; }".6526 6527Usable as: Any Matcher6528</pre></td></tr>6529 6530 6531<tr><td>Matcher<*></td><td class="name" onclick="toggle('invocation0')"><a name="invocation0Anchor">invocation</a></td><td>Matcher<*>...Matcher<*></td></tr>6532<tr><td colspan="4" class="doc" id="invocation0"><pre>Matches function calls and constructor calls6533 6534Because CallExpr and CXXConstructExpr do not share a common6535base class with API accessing arguments etc, AST Matchers for code6536which should match both are typically duplicated. This matcher6537removes the need for duplication.6538 6539Given code6540struct ConstructorTakesInt6541{6542 ConstructorTakesInt(int i) {}6543};6544 6545void callTakesInt(int i)6546{6547}6548 6549void doCall()6550{6551 callTakesInt(42);6552}6553 6554void doConstruct()6555{6556 ConstructorTakesInt cti(42);6557}6558 6559The matcher6560invocation(hasArgument(0, integerLiteral(equals(42))))6561matches the expression in both doCall and doConstruct6562</pre></td></tr>6563 6564 6565<tr><td>Matcher<*></td><td class="name" onclick="toggle('optionally0')"><a name="optionally0Anchor">optionally</a></td><td>Matcher<*></td></tr>6566<tr><td colspan="4" class="doc" id="optionally0"><pre>Matches any node regardless of the submatcher.6567 6568However, optionally will retain any bindings generated by the submatcher.6569Useful when additional information which may or may not present about a main6570matching node is desired.6571 6572For example, in:6573 class Foo {6574 int bar;6575 }6576The matcher:6577 cxxRecordDecl(6578 optionally(has(6579 fieldDecl(hasName("bar")).bind("var")6580 ))).bind("record")6581will produce a result binding for both "record" and "var".6582The matcher will produce a "record" binding for even if there is no data6583member named "bar" in that class.6584 6585Usable as: Any Matcher6586</pre></td></tr>6587 6588 6589<tr><td>Matcher<*></td><td class="name" onclick="toggle('traverse0')"><a name="traverse0Anchor">traverse</a></td><td>TraversalKind TK, Matcher<*> InnerMatcher</td></tr>6590<tr><td colspan="4" class="doc" id="traverse0"><pre>Causes all nested matchers to be matched with the specified traversal kind.6591 6592Given6593 void foo()6594 {6595 int i = 3.0;6596 }6597The matcher6598 traverse(TK_IgnoreUnlessSpelledInSource,6599 varDecl(hasInitializer(floatLiteral().bind("init")))6600 )6601matches the variable declaration with "init" bound to the "3.0".6602</pre></td></tr>6603 6604 6605<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AbstractConditionalOperator.html">AbstractConditionalOperator</a>></td><td class="name" onclick="toggle('hasCondition5')"><a name="hasCondition5Anchor">hasCondition</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>6606<tr><td colspan="4" class="doc" id="hasCondition5"><pre>Matches the condition expression of an if statement, for loop, while loop,6607do-while loop, switch statement or conditional operator.6608 6609Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true))))6610 if (true) {}6611</pre></td></tr>6612 6613 6614<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AbstractConditionalOperator.html">AbstractConditionalOperator</a>></td><td class="name" onclick="toggle('hasFalseExpression0')"><a name="hasFalseExpression0Anchor">hasFalseExpression</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>6615<tr><td colspan="4" class="doc" id="hasFalseExpression0"><pre>Matches the false branch expression of a conditional operator6616(binary or ternary).6617 6618Example matches b6619 condition ? a : b6620 condition ?: b6621</pre></td></tr>6622 6623 6624<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AbstractConditionalOperator.html">AbstractConditionalOperator</a>></td><td class="name" onclick="toggle('hasTrueExpression0')"><a name="hasTrueExpression0Anchor">hasTrueExpression</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>6625<tr><td colspan="4" class="doc" id="hasTrueExpression0"><pre>Matches the true branch expression of a conditional operator.6626 6627Example 1 (conditional ternary operator): matches a6628 condition ? a : b6629 6630Example 2 (conditional binary operator): matches opaqueValueExpr(condition)6631 condition ?: b6632</pre></td></tr>6633 6634 6635<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>></td><td class="name" onclick="toggle('hasDeclaration16')"><a name="hasDeclaration16Anchor">hasDeclaration</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>6636<tr><td colspan="4" class="doc" id="hasDeclaration16"><pre>Matches a node if the declaration associated with that node6637matches the given matcher.6638 6639The associated declaration is:6640- for type nodes, the declaration of the underlying type6641- for CallExpr, the declaration of the callee6642- for MemberExpr, the declaration of the referenced member6643- for CXXConstructExpr, the declaration of the constructor6644- for CXXNewExpr, the declaration of the operator new6645- for ObjCIvarExpr, the declaration of the ivar6646 6647For type nodes, hasDeclaration will generally match the declaration of the6648sugared type. Given6649 class X {};6650 typedef X Y;6651 Y y;6652in varDecl(hasType(hasDeclaration(decl()))) the decl will match the6653typedefDecl. A common use case is to match the underlying, desugared type.6654This can be achieved by using the hasUnqualifiedDesugaredType matcher:6655 varDecl(hasType(hasUnqualifiedDesugaredType(6656 recordType(hasDeclaration(decl())))))6657In this matcher, the decl will match the CXXRecordDecl of class X.6658 6659Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>,6660 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>,6661 Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>,6662 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<RecordType>,6663 Matcher<TagType>, Matcher<TemplateSpecializationType>,6664 Matcher<TemplateTypeParmType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>,6665 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingType.html">UsingType</a>>6666</pre></td></tr>6667 6668 6669<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ArraySubscriptExpr.html">ArraySubscriptExpr</a>></td><td class="name" onclick="toggle('hasBase0')"><a name="hasBase0Anchor">hasBase</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>6670<tr><td colspan="4" class="doc" id="hasBase0"><pre>Matches the base expression of an array subscript expression.6671 6672Given6673 int i[5];6674 void f() { i[1] = 42; }6675arraySubscriptExpression(hasBase(implicitCastExpr(6676 hasSourceExpression(declRefExpr()))))6677 matches i[1] with the declRefExpr() matching i6678</pre></td></tr>6679 6680 6681<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ArraySubscriptExpr.html">ArraySubscriptExpr</a>></td><td class="name" onclick="toggle('hasIndex0')"><a name="hasIndex0Anchor">hasIndex</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>6682<tr><td colspan="4" class="doc" id="hasIndex0"><pre>Matches the index expression of an array subscript expression.6683 6684Given6685 int i[5];6686 void f() { i[1] = 42; }6687arraySubscriptExpression(hasIndex(integerLiteral()))6688 matches i[1] with the integerLiteral() matching 16689</pre></td></tr>6690 6691 6692<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ArraySubscriptExpr.html">ArraySubscriptExpr</a>></td><td class="name" onclick="toggle('hasLHS3')"><a name="hasLHS3Anchor">hasLHS</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>6693<tr><td colspan="4" class="doc" id="hasLHS3"><pre>Matches the left hand side of binary operator expressions.6694 6695Example matches a (matcher = binaryOperator(hasLHS()))6696 a || b6697</pre></td></tr>6698 6699 6700<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ArraySubscriptExpr.html">ArraySubscriptExpr</a>></td><td class="name" onclick="toggle('hasRHS3')"><a name="hasRHS3Anchor">hasRHS</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>6701<tr><td colspan="4" class="doc" id="hasRHS3"><pre>Matches the right hand side of binary operator expressions.6702 6703Example matches b (matcher = binaryOperator(hasRHS()))6704 a || b6705</pre></td></tr>6706 6707 6708<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ArrayType.html">ArrayType</a>></td><td class="name" onclick="toggle('hasElementType0')"><a name="hasElementType0Anchor">hasElementType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr>6709<tr><td colspan="4" class="doc" id="hasElementType0"><pre>Matches arrays and C99 complex types that have a specific element6710type.6711 6712Given6713 struct A {};6714 A a[7];6715 int b[7];6716arrayType(hasElementType(builtinType()))6717 matches "int b[7]"6718 6719Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ArrayType.html">ArrayType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ComplexType.html">ComplexType</a>>6720</pre></td></tr>6721 6722 6723<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AtomicType.html">AtomicType</a>></td><td class="name" onclick="toggle('hasValueType0')"><a name="hasValueType0Anchor">hasValueType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr>6724<tr><td colspan="4" class="doc" id="hasValueType0"><pre>Matches atomic types with a specific value type.6725 6726Given6727 _Atomic(int) i;6728 _Atomic(float) f;6729atomicType(hasValueType(isInteger()))6730 matches "_Atomic(int) i"6731 6732Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AtomicType.html">AtomicType</a>>6733</pre></td></tr>6734 6735 6736<tr><td>Matcher<AutoType></td><td class="name" onclick="toggle('hasDeducedType0')"><a name="hasDeducedType0Anchor">hasDeducedType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr>6737<tr><td colspan="4" class="doc" id="hasDeducedType0"><pre>Matches AutoType nodes where the deduced type is a specific type.6738 6739Note: There is no TypeLoc for the deduced type and thus no6740getDeducedLoc() matcher.6741 6742Given6743 auto a = 1;6744 auto b = 2.0;6745autoType(hasDeducedType(isInteger()))6746 matches "auto a"6747 6748Usable as: Matcher<AutoType>6749</pre></td></tr>6750 6751 6752<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BaseUsingDecl.html">BaseUsingDecl</a>></td><td class="name" onclick="toggle('hasAnyUsingShadowDecl0')"><a name="hasAnyUsingShadowDecl0Anchor">hasAnyUsingShadowDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingShadowDecl.html">UsingShadowDecl</a>> InnerMatcher</td></tr>6753<tr><td colspan="4" class="doc" id="hasAnyUsingShadowDecl0"><pre>Matches any using shadow declaration.6754 6755Given6756 namespace X { void b(); }6757 using X::b;6758usingDecl(hasAnyUsingShadowDecl(hasName("b"))))6759 matches using X::b </pre></td></tr>6760 6761 6762<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html">BinaryOperator</a>></td><td class="name" onclick="toggle('hasEitherOperand0')"><a name="hasEitherOperand0Anchor">hasEitherOperand</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>6763<tr><td colspan="4" class="doc" id="hasEitherOperand0"><pre>Matches if either the left hand side or the right hand side of a6764binary operator or fold expression matches.6765</pre></td></tr>6766 6767 6768<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html">BinaryOperator</a>></td><td class="name" onclick="toggle('hasLHS0')"><a name="hasLHS0Anchor">hasLHS</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>6769<tr><td colspan="4" class="doc" id="hasLHS0"><pre>Matches the left hand side of binary operator expressions.6770 6771Example matches a (matcher = binaryOperator(hasLHS()))6772 a || b6773</pre></td></tr>6774 6775 6776<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html">BinaryOperator</a>></td><td class="name" onclick="toggle('hasOperands0')"><a name="hasOperands0Anchor">hasOperands</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> Matcher1, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> Matcher2</td></tr>6777<tr><td colspan="4" class="doc" id="hasOperands0"><pre>Matches if both matchers match with opposite sides of the binary operator6778or fold expression.6779 6780Example matcher = binaryOperator(hasOperands(integerLiteral(equals(1),6781 integerLiteral(equals(2)))6782 1 + 2 // Match6783 2 + 1 // Match6784 1 + 1 // No match6785 2 + 2 // No match6786</pre></td></tr>6787 6788 6789<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html">BinaryOperator</a>></td><td class="name" onclick="toggle('hasRHS0')"><a name="hasRHS0Anchor">hasRHS</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>6790<tr><td colspan="4" class="doc" id="hasRHS0"><pre>Matches the right hand side of binary operator expressions.6791 6792Example matches b (matcher = binaryOperator(hasRHS()))6793 a || b6794</pre></td></tr>6795 6796 6797<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BindingDecl.html">BindingDecl</a>></td><td class="name" onclick="toggle('forDecomposition0')"><a name="forDecomposition0Anchor">forDecomposition</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</a>> InnerMatcher</td></tr>6798<tr><td colspan="4" class="doc" id="forDecomposition0"><pre>Matches the DecompositionDecl the binding belongs to.6799 6800For example, in:6801void foo()6802{6803 int arr[3];6804 auto &[f, s, t] = arr;6805 6806 f = 42;6807}6808The matcher:6809 bindingDecl(hasName("f"),6810 forDecomposition(decompositionDecl())6811matches 'f' in 'auto &[f, s, t]'.6812</pre></td></tr>6813 6814 6815<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockDecl.html">BlockDecl</a>></td><td class="name" onclick="toggle('hasAnyParameter2')"><a name="hasAnyParameter2Anchor">hasAnyParameter</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html">ParmVarDecl</a>> InnerMatcher</td></tr>6816<tr><td colspan="4" class="doc" id="hasAnyParameter2"><pre>Matches any parameter of a function or an ObjC method declaration or a6817block.6818 6819Does not match the 'this' parameter of a method.6820 6821Given6822 class X { void f(int x, int y, int z) {} };6823cxxMethodDecl(hasAnyParameter(hasName("y")))6824 matches f(int x, int y, int z) {}6825with hasAnyParameter(...)6826 matching int y6827 6828For ObjectiveC, given6829 @interface I - (void) f:(int) y; @end6830 6831the matcher objcMethodDecl(hasAnyParameter(hasName("y")))6832matches the declaration of method f with hasParameter6833matching y.6834 6835For blocks, given6836 b = ^(int y) { printf("%d", y) };6837 6838the matcher blockDecl(hasAnyParameter(hasName("y")))6839matches the declaration of the block b with hasParameter6840matching y.6841</pre></td></tr>6842 6843 6844<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockDecl.html">BlockDecl</a>></td><td class="name" onclick="toggle('hasParameter2')"><a name="hasParameter2Anchor">hasParameter</a></td><td>unsigned N, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html">ParmVarDecl</a>> InnerMatcher</td></tr>6845<tr><td colspan="4" class="doc" id="hasParameter2"><pre>Matches the n'th parameter of a function or an ObjC method6846declaration or a block.6847 6848Given6849 class X { void f(int x) {} };6850cxxMethodDecl(hasParameter(0, hasType(varDecl())))6851 matches f(int x) {}6852with hasParameter(...)6853 matching int x6854 6855For ObjectiveC, given6856 @interface I - (void) f:(int) y; @end6857 6858the matcher objcMethodDecl(hasParameter(0, hasName("y")))6859matches the declaration of method f with hasParameter6860matching y.6861</pre></td></tr>6862 6863 6864<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockDecl.html">BlockDecl</a>></td><td class="name" onclick="toggle('hasTypeLoc0')"><a name="hasTypeLoc0Anchor">hasTypeLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> Inner</td></tr>6865<tr><td colspan="4" class="doc" id="hasTypeLoc0"><pre>Matches if the type location of a node matches the inner matcher.6866 6867Examples:6868 int x;6869declaratorDecl(hasTypeLoc(loc(asString("int"))))6870 matches int x6871 6872auto x = int(3);6873cxxTemporaryObjectExpr(hasTypeLoc(loc(asString("int"))))6874 matches int(3)6875 6876struct Foo { Foo(int, int); };6877auto x = Foo(1, 2);6878cxxFunctionalCastExpr(hasTypeLoc(loc(asString("struct Foo"))))6879 matches Foo(1, 2)6880 6881Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockDecl.html">BlockDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>>,6882 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFunctionalCastExpr.html">CXXFunctionalCastExpr</a>>,6883 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXTemporaryObjectExpr.html">CXXTemporaryObjectExpr</a>>,6884 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXUnresolvedConstructExpr.html">CXXUnresolvedConstructExpr</a>>,6885 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CompoundLiteralExpr.html">CompoundLiteralExpr</a>>,6886 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclaratorDecl.html">DeclaratorDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ExplicitCastExpr.html">ExplicitCastExpr</a>>,6887 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCPropertyDecl.html">ObjCPropertyDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgumentLoc.html">TemplateArgumentLoc</a>>,6888 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefNameDecl.html">TypedefNameDecl</a>>6889</pre></td></tr>6890 6891 6892<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockPointerType.html">BlockPointerType</a>></td><td class="name" onclick="toggle('pointee0')"><a name="pointee0Anchor">pointee</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr>6893<tr><td colspan="4" class="doc" id="pointee0"><pre>Narrows PointerType (and similar) matchers to those where the6894pointee matches a given matcher.6895 6896Given6897 int *a;6898 int const *b;6899 float const *f;6900pointerType(pointee(isConstQualified(), isInteger()))6901 matches "int const *b"6902 6903Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockPointerType.html">BlockPointerType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberPointerType.html">MemberPointerType</a>>,6904 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1PointerType.html">PointerType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ReferenceType.html">ReferenceType</a>>,6905 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCObjectPointerType.html">ObjCObjectPointerType</a>>6906</pre></td></tr>6907 6908 6909<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>></td><td class="name" onclick="toggle('hasTypeLoc1')"><a name="hasTypeLoc1Anchor">hasTypeLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> Inner</td></tr>6910<tr><td colspan="4" class="doc" id="hasTypeLoc1"><pre>Matches if the type location of a node matches the inner matcher.6911 6912Examples:6913 int x;6914declaratorDecl(hasTypeLoc(loc(asString("int"))))6915 matches int x6916 6917auto x = int(3);6918cxxTemporaryObjectExpr(hasTypeLoc(loc(asString("int"))))6919 matches int(3)6920 6921struct Foo { Foo(int, int); };6922auto x = Foo(1, 2);6923cxxFunctionalCastExpr(hasTypeLoc(loc(asString("struct Foo"))))6924 matches Foo(1, 2)6925 6926Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockDecl.html">BlockDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>>,6927 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFunctionalCastExpr.html">CXXFunctionalCastExpr</a>>,6928 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXTemporaryObjectExpr.html">CXXTemporaryObjectExpr</a>>,6929 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXUnresolvedConstructExpr.html">CXXUnresolvedConstructExpr</a>>,6930 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CompoundLiteralExpr.html">CompoundLiteralExpr</a>>,6931 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclaratorDecl.html">DeclaratorDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ExplicitCastExpr.html">ExplicitCastExpr</a>>,6932 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCPropertyDecl.html">ObjCPropertyDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgumentLoc.html">TemplateArgumentLoc</a>>,6933 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefNameDecl.html">TypedefNameDecl</a>>6934</pre></td></tr>6935 6936 6937<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>></td><td class="name" onclick="toggle('hasType8')"><a name="hasType8Anchor">hasType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>6938<tr><td colspan="4" class="doc" id="hasType8"><pre>Overloaded to match the declaration of the expression's or value6939declaration's type.6940 6941In case of a value declaration (for example a variable declaration),6942this resolves one layer of indirection. For example, in the value6943declaration "X x;", cxxRecordDecl(hasName("X")) matches the declaration of6944X, while varDecl(hasType(cxxRecordDecl(hasName("X")))) matches the6945declaration of x.6946 6947Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X")))))6948 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X")))))6949 and friend class X (matcher = friendDecl(hasType("X"))6950 and public virtual X (matcher = cxxBaseSpecifier(hasType(6951 cxxRecordDecl(hasName("X"))))6952 class X {};6953 void y(X &x) { x; X z; }6954 class Y { friend class X; };6955 class Z : public virtual X {};6956 6957Example matches class Derived6958(matcher = cxxRecordDecl(hasAnyBase(hasType(cxxRecordDecl(hasName("Base"))))))6959class Base {};6960class Derived : Base {};6961 6962Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FriendDecl.html">FriendDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</a>>,6963Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>>6964</pre></td></tr>6965 6966 6967<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>></td><td class="name" onclick="toggle('hasType4')"><a name="hasType4Anchor">hasType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr>6968<tr><td colspan="4" class="doc" id="hasType4"><pre>Matches if the expression's or declaration's type matches a type6969matcher.6970 6971Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X")))))6972 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X")))))6973 and U (matcher = typedefDecl(hasType(asString("int")))6974 and friend class X (matcher = friendDecl(hasType("X"))6975 and public virtual X (matcher = cxxBaseSpecifier(hasType(6976 asString("class X")))6977 class X {};6978 void y(X &x) { x; X z; }6979 typedef int U;6980 class Y { friend class X; };6981 class Z : public virtual X {};6982</pre></td></tr>6983 6984 6985<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>></td><td class="name" onclick="toggle('forEachArgumentWithParam1')"><a name="forEachArgumentWithParam1Anchor">forEachArgumentWithParam</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> ArgMatcher, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html">ParmVarDecl</a>> ParamMatcher</td></tr>6986<tr><td colspan="4" class="doc" id="forEachArgumentWithParam1"><pre>Matches all arguments and their respective ParmVarDecl.6987 6988Given6989 void f(int i);6990 int y;6991 f(y);6992callExpr(6993 forEachArgumentWithParam(6994 declRefExpr(to(varDecl(hasName("y")))),6995 parmVarDecl(hasType(isInteger()))6996))6997 matches f(y);6998with declRefExpr(...)6999 matching int y7000and parmVarDecl(...)7001 matching int i7002</pre></td></tr>7003 7004 7005<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>></td><td class="name" onclick="toggle('forEachArgumentWithParamType1')"><a name="forEachArgumentWithParamType1Anchor">forEachArgumentWithParamType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> ArgMatcher, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> ParamMatcher</td></tr>7006<tr><td colspan="4" class="doc" id="forEachArgumentWithParamType1"><pre>Matches all arguments and their respective types for a CallExpr or7007CXXConstructExpr. It is very similar to forEachArgumentWithParam but7008it works on calls through function pointers as well.7009 7010The difference is, that function pointers do not provide access to a7011ParmVarDecl, but only the QualType for each argument.7012 7013Given7014 void f(int i);7015 int y;7016 f(y);7017 void (*f_ptr)(int) = f;7018 f_ptr(y);7019callExpr(7020 forEachArgumentWithParamType(7021 declRefExpr(to(varDecl(hasName("y")))),7022 qualType(isInteger()).bind("type)7023))7024 matches f(y) and f_ptr(y)7025with declRefExpr(...)7026 matching int y7027and qualType(...)7028 matching int7029</pre></td></tr>7030 7031 7032<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>></td><td class="name" onclick="toggle('hasAnyArgument1')"><a name="hasAnyArgument1Anchor">hasAnyArgument</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>7033<tr><td colspan="4" class="doc" id="hasAnyArgument1"><pre>Matches any argument of a call expression or a constructor call7034expression, or an ObjC-message-send expression.7035 7036Given7037 void x(int, int, int) { int y; x(1, y, 42); }7038callExpr(hasAnyArgument(declRefExpr()))7039 matches x(1, y, 42)7040with hasAnyArgument(...)7041 matching y7042 7043For ObjectiveC, given7044 @interface I - (void) f:(int) y; @end7045 void foo(I *i) { [i f:12]; }7046objcMessageExpr(hasAnyArgument(integerLiteral(equals(12))))7047 matches [i f:12]7048</pre></td></tr>7049 7050 7051<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>></td><td class="name" onclick="toggle('hasArgument1')"><a name="hasArgument1Anchor">hasArgument</a></td><td>unsigned N, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>7052<tr><td colspan="4" class="doc" id="hasArgument1"><pre>Matches the n'th argument of a call expression or a constructor7053call expression.7054 7055Example matches y in x(y)7056 (matcher = callExpr(hasArgument(0, declRefExpr())))7057 void x(int) { int y; x(y); }7058</pre></td></tr>7059 7060 7061<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>></td><td class="name" onclick="toggle('hasDeclaration14')"><a name="hasDeclaration14Anchor">hasDeclaration</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>7062<tr><td colspan="4" class="doc" id="hasDeclaration14"><pre>Matches a node if the declaration associated with that node7063matches the given matcher.7064 7065The associated declaration is:7066- for type nodes, the declaration of the underlying type7067- for CallExpr, the declaration of the callee7068- for MemberExpr, the declaration of the referenced member7069- for CXXConstructExpr, the declaration of the constructor7070- for CXXNewExpr, the declaration of the operator new7071- for ObjCIvarExpr, the declaration of the ivar7072 7073For type nodes, hasDeclaration will generally match the declaration of the7074sugared type. Given7075 class X {};7076 typedef X Y;7077 Y y;7078in varDecl(hasType(hasDeclaration(decl()))) the decl will match the7079typedefDecl. A common use case is to match the underlying, desugared type.7080This can be achieved by using the hasUnqualifiedDesugaredType matcher:7081 varDecl(hasType(hasUnqualifiedDesugaredType(7082 recordType(hasDeclaration(decl())))))7083In this matcher, the decl will match the CXXRecordDecl of class X.7084 7085Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>,7086 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>,7087 Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>,7088 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<RecordType>,7089 Matcher<TagType>, Matcher<TemplateSpecializationType>,7090 Matcher<TemplateTypeParmType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>,7091 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingType.html">UsingType</a>>7092</pre></td></tr>7093 7094 7095<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html">CXXConstructorDecl</a>></td><td class="name" onclick="toggle('forEachConstructorInitializer0')"><a name="forEachConstructorInitializer0Anchor">forEachConstructorInitializer</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>> InnerMatcher</td></tr>7096<tr><td colspan="4" class="doc" id="forEachConstructorInitializer0"><pre>Matches each constructor initializer in a constructor definition.7097 7098Given7099 class A { A() : i(42), j(42) {} int i; int j; };7100cxxConstructorDecl(forEachConstructorInitializer(7101 forField(decl().bind("x"))7102))7103 will trigger two matches, binding for 'i' and 'j' respectively.7104</pre></td></tr>7105 7106 7107<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html">CXXConstructorDecl</a>></td><td class="name" onclick="toggle('hasAnyConstructorInitializer0')"><a name="hasAnyConstructorInitializer0Anchor">hasAnyConstructorInitializer</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>> InnerMatcher</td></tr>7108<tr><td colspan="4" class="doc" id="hasAnyConstructorInitializer0"><pre>Matches a constructor initializer.7109 7110Given7111 struct Foo {7112 Foo() : foo_(1) { }7113 int foo_;7114 };7115cxxRecordDecl(has(cxxConstructorDecl(7116 hasAnyConstructorInitializer(anything())7117)))7118 record matches Foo, hasAnyConstructorInitializer matches foo_(1)7119</pre></td></tr>7120 7121 7122<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>></td><td class="name" onclick="toggle('forField0')"><a name="forField0Anchor">forField</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html">FieldDecl</a>> InnerMatcher</td></tr>7123<tr><td colspan="4" class="doc" id="forField0"><pre>Matches the field declaration of a constructor initializer.7124 7125Given7126 struct Foo {7127 Foo() : foo_(1) { }7128 int foo_;7129 };7130cxxRecordDecl(has(cxxConstructorDecl(hasAnyConstructorInitializer(7131 forField(hasName("foo_"))))))7132 matches Foo7133with forField matching foo_7134</pre></td></tr>7135 7136 7137<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>></td><td class="name" onclick="toggle('hasTypeLoc2')"><a name="hasTypeLoc2Anchor">hasTypeLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> Inner</td></tr>7138<tr><td colspan="4" class="doc" id="hasTypeLoc2"><pre>Matches if the type location of a node matches the inner matcher.7139 7140Examples:7141 int x;7142declaratorDecl(hasTypeLoc(loc(asString("int"))))7143 matches int x7144 7145auto x = int(3);7146cxxTemporaryObjectExpr(hasTypeLoc(loc(asString("int"))))7147 matches int(3)7148 7149struct Foo { Foo(int, int); };7150auto x = Foo(1, 2);7151cxxFunctionalCastExpr(hasTypeLoc(loc(asString("struct Foo"))))7152 matches Foo(1, 2)7153 7154Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockDecl.html">BlockDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>>,7155 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFunctionalCastExpr.html">CXXFunctionalCastExpr</a>>,7156 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXTemporaryObjectExpr.html">CXXTemporaryObjectExpr</a>>,7157 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXUnresolvedConstructExpr.html">CXXUnresolvedConstructExpr</a>>,7158 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CompoundLiteralExpr.html">CompoundLiteralExpr</a>>,7159 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclaratorDecl.html">DeclaratorDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ExplicitCastExpr.html">ExplicitCastExpr</a>>,7160 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCPropertyDecl.html">ObjCPropertyDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgumentLoc.html">TemplateArgumentLoc</a>>,7161 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefNameDecl.html">TypedefNameDecl</a>>7162</pre></td></tr>7163 7164 7165<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>></td><td class="name" onclick="toggle('withInitializer0')"><a name="withInitializer0Anchor">withInitializer</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>7166<tr><td colspan="4" class="doc" id="withInitializer0"><pre>Matches the initializer expression of a constructor initializer.7167 7168Given7169 struct Foo {7170 Foo() : foo_(1) { }7171 int foo_;7172 };7173cxxRecordDecl(has(cxxConstructorDecl(hasAnyConstructorInitializer(7174 withInitializer(integerLiteral(equals(1)))))))7175 matches Foo7176with withInitializer matching (1)7177</pre></td></tr>7178 7179 7180<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXDependentScopeMemberExpr.html">CXXDependentScopeMemberExpr</a>></td><td class="name" onclick="toggle('hasObjectExpression2')"><a name="hasObjectExpression2Anchor">hasObjectExpression</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>7181<tr><td colspan="4" class="doc" id="hasObjectExpression2"><pre>Matches a member expression where the object expression is matched by a7182given matcher. Implicit object expressions are included; that is, it matches7183use of implicit `this`.7184 7185Given7186 struct X {7187 int m;7188 int f(X x) { x.m; return m; }7189 };7190memberExpr(hasObjectExpression(hasType(cxxRecordDecl(hasName("X")))))7191 matches `x.m`, but not `m`; however,7192memberExpr(hasObjectExpression(hasType(pointsTo(7193 cxxRecordDecl(hasName("X"))))))7194 matches `m` (aka. `this->m`), but not `x.m`.7195</pre></td></tr>7196 7197 7198<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFoldExpr.html">CXXFoldExpr</a>></td><td class="name" onclick="toggle('callee1')"><a name="callee1Anchor">callee</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr>7199<tr><td colspan="4" class="doc" id="callee1"><pre>Matches if the call or fold expression's callee expression matches.7200 7201Given7202 class Y { void x() { this->x(); x(); Y y; y.x(); } };7203 void f() { f(); }7204callExpr(callee(expr()))7205 matches this->x(), x(), y.x(), f()7206with callee(...)7207 matching this->x, x, y.x, f respectively7208 7209Given7210 template <typename... Args>7211 auto sum(Args... args) {7212 return (0 + ... + args);7213 }7214 7215 template <typename... Args>7216 auto multiply(Args... args) {7217 return (args * ... * 1);7218 }7219cxxFoldExpr(callee(expr()))7220 matches (args * ... * 1)7221with callee(...)7222 matching *7223 7224Note: Callee cannot take the more general internal::Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>>7225because this introduces ambiguous overloads with calls to Callee taking a7226internal::Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, as the matcher hierarchy is purely7227implemented in terms of implicit casts.7228</pre></td></tr>7229 7230 7231<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFoldExpr.html">CXXFoldExpr</a>></td><td class="name" onclick="toggle('hasEitherOperand2')"><a name="hasEitherOperand2Anchor">hasEitherOperand</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>7232<tr><td colspan="4" class="doc" id="hasEitherOperand2"><pre>Matches if either the left hand side or the right hand side of a7233binary operator or fold expression matches.7234</pre></td></tr>7235 7236 7237<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFoldExpr.html">CXXFoldExpr</a>></td><td class="name" onclick="toggle('hasFoldInit0')"><a name="hasFoldInit0Anchor">hasFoldInit</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMacher</td></tr>7238<tr><td colspan="4" class="doc" id="hasFoldInit0"><pre>Matches the operand that does not contain the parameter pack.7239 7240Example matches `(0 + ... + args)` and `(args * ... * 1)`7241 (matcher = cxxFoldExpr(hasFoldInit(expr())))7242 with hasFoldInit(...)7243 matching `0` and `1` respectively7244 template <typename... Args>7245 auto sum(Args... args) {7246 return (0 + ... + args);7247 }7248 7249 template <typename... Args>7250 auto multiply(Args... args) {7251 return (args * ... * 1);7252 }7253</pre></td></tr>7254 7255 7256<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFoldExpr.html">CXXFoldExpr</a>></td><td class="name" onclick="toggle('hasLHS4')"><a name="hasLHS4Anchor">hasLHS</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>7257<tr><td colspan="4" class="doc" id="hasLHS4"><pre>Matches the left hand side of binary operator expressions.7258 7259Example matches a (matcher = binaryOperator(hasLHS()))7260 a || b7261</pre></td></tr>7262 7263 7264<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFoldExpr.html">CXXFoldExpr</a>></td><td class="name" onclick="toggle('hasOperands2')"><a name="hasOperands2Anchor">hasOperands</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> Matcher1, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> Matcher2</td></tr>7265<tr><td colspan="4" class="doc" id="hasOperands2"><pre>Matches if both matchers match with opposite sides of the binary operator7266or fold expression.7267 7268Example matcher = binaryOperator(hasOperands(integerLiteral(equals(1),7269 integerLiteral(equals(2)))7270 1 + 2 // Match7271 2 + 1 // Match7272 1 + 1 // No match7273 2 + 2 // No match7274</pre></td></tr>7275 7276 7277<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFoldExpr.html">CXXFoldExpr</a>></td><td class="name" onclick="toggle('hasPattern0')"><a name="hasPattern0Anchor">hasPattern</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMacher</td></tr>7278<tr><td colspan="4" class="doc" id="hasPattern0"><pre>Matches the operand that contains the parameter pack.7279 7280Example matches `(0 + ... + args)`7281 (matcher = cxxFoldExpr(hasPattern(expr())))7282 with hasPattern(...)7283 matching `args`7284 template <typename... Args>7285 auto sum(Args... args) {7286 return (0 + ... + args);7287 }7288 7289 template <typename... Args>7290 auto multiply(Args... args) {7291 return (args * ... * 1);7292 }7293</pre></td></tr>7294 7295 7296<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFoldExpr.html">CXXFoldExpr</a>></td><td class="name" onclick="toggle('hasRHS4')"><a name="hasRHS4Anchor">hasRHS</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>7297<tr><td colspan="4" class="doc" id="hasRHS4"><pre>Matches the right hand side of binary operator expressions.7298 7299Example matches b (matcher = binaryOperator(hasRHS()))7300 a || b7301</pre></td></tr>7302 7303 7304<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXForRangeStmt.html">CXXForRangeStmt</a>></td><td class="name" onclick="toggle('hasBody3')"><a name="hasBody3Anchor">hasBody</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr>7305<tr><td colspan="4" class="doc" id="hasBody3"><pre>Matches a 'for', 'while', 'while' statement or a function or coroutine7306definition that has a given body. Note that in case of functions or7307coroutines this matcher only matches the definition itself and not the7308other declarations of the same function or coroutine.7309 7310Given7311 for (;;) {}7312forStmt(hasBody(compoundStmt()))7313 matches 'for (;;) {}'7314with compoundStmt()7315 matching '{}'7316 7317Given7318 void f();7319 void f() {}7320functionDecl(hasBody(compoundStmt()))7321 matches 'void f() {}'7322with compoundStmt()7323 matching '{}'7324 but does not match 'void f();'7325</pre></td></tr>7326 7327 7328<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXForRangeStmt.html">CXXForRangeStmt</a>></td><td class="name" onclick="toggle('hasInitStatement2')"><a name="hasInitStatement2Anchor">hasInitStatement</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr>7329<tr><td colspan="4" class="doc" id="hasInitStatement2"><pre>Matches selection statements with initializer.7330 7331Given:7332 void foo() {7333 if (int i = foobar(); i > 0) {}7334 switch (int i = foobar(); i) {}7335 for (auto& a = get_range(); auto& x : a) {}7336 }7337 void bar() {7338 if (foobar() > 0) {}7339 switch (foobar()) {}7340 for (auto& x : get_range()) {}7341 }7342ifStmt(hasInitStatement(anything()))7343 matches the if statement in foo but not in bar.7344switchStmt(hasInitStatement(anything()))7345 matches the switch statement in foo but not in bar.7346cxxForRangeStmt(hasInitStatement(anything()))7347 matches the range for statement in foo but not in bar.7348</pre></td></tr>7349 7350 7351<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXForRangeStmt.html">CXXForRangeStmt</a>></td><td class="name" onclick="toggle('hasLoopVariable0')"><a name="hasLoopVariable0Anchor">hasLoopVariable</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>> InnerMatcher</td></tr>7352<tr><td colspan="4" class="doc" id="hasLoopVariable0"><pre>Matches the initialization statement of a for loop.7353 7354Example:7355 forStmt(hasLoopVariable(anything()))7356matches 'int x' in7357 for (int x : a) { }7358</pre></td></tr>7359 7360 7361<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXForRangeStmt.html">CXXForRangeStmt</a>></td><td class="name" onclick="toggle('hasRangeInit0')"><a name="hasRangeInit0Anchor">hasRangeInit</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>7362<tr><td colspan="4" class="doc" id="hasRangeInit0"><pre>Matches the range initialization statement of a for loop.7363 7364Example:7365 forStmt(hasRangeInit(anything()))7366matches 'a' in7367 for (int x : a) { }7368</pre></td></tr>7369 7370 7371<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFunctionalCastExpr.html">CXXFunctionalCastExpr</a>></td><td class="name" onclick="toggle('hasTypeLoc3')"><a name="hasTypeLoc3Anchor">hasTypeLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> Inner</td></tr>7372<tr><td colspan="4" class="doc" id="hasTypeLoc3"><pre>Matches if the type location of a node matches the inner matcher.7373 7374Examples:7375 int x;7376declaratorDecl(hasTypeLoc(loc(asString("int"))))7377 matches int x7378 7379auto x = int(3);7380cxxTemporaryObjectExpr(hasTypeLoc(loc(asString("int"))))7381 matches int(3)7382 7383struct Foo { Foo(int, int); };7384auto x = Foo(1, 2);7385cxxFunctionalCastExpr(hasTypeLoc(loc(asString("struct Foo"))))7386 matches Foo(1, 2)7387 7388Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockDecl.html">BlockDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>>,7389 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFunctionalCastExpr.html">CXXFunctionalCastExpr</a>>,7390 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXTemporaryObjectExpr.html">CXXTemporaryObjectExpr</a>>,7391 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXUnresolvedConstructExpr.html">CXXUnresolvedConstructExpr</a>>,7392 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CompoundLiteralExpr.html">CompoundLiteralExpr</a>>,7393 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclaratorDecl.html">DeclaratorDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ExplicitCastExpr.html">ExplicitCastExpr</a>>,7394 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCPropertyDecl.html">ObjCPropertyDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgumentLoc.html">TemplateArgumentLoc</a>>,7395 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefNameDecl.html">TypedefNameDecl</a>>7396</pre></td></tr>7397 7398 7399<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMemberCallExpr.html">CXXMemberCallExpr</a>></td><td class="name" onclick="toggle('onImplicitObjectArgument0')"><a name="onImplicitObjectArgument0Anchor">onImplicitObjectArgument</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>7400<tr><td colspan="4" class="doc" id="onImplicitObjectArgument0"><pre>Matches on the implicit object argument of a member call expression. Unlike7401`on`, matches the argument directly without stripping away anything.7402 7403Given7404 class Y { public: void m(); };7405 Y g();7406 class X : public Y { void g(); };7407 void z(Y y, X x) { y.m(); x.m(); x.g(); (g()).m(); }7408cxxMemberCallExpr(onImplicitObjectArgument(hasType(7409 cxxRecordDecl(hasName("Y")))))7410 matches `y.m()`, `x.m()` and (`g()).m()`, but not `x.g()`).7411cxxMemberCallExpr(on(callExpr()))7412 only matches `(g()).m()` (the parens are ignored).7413 7414FIXME: Overload to allow directly matching types?7415</pre></td></tr>7416 7417 7418<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMemberCallExpr.html">CXXMemberCallExpr</a>></td><td class="name" onclick="toggle('on0')"><a name="on0Anchor">on</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>7419<tr><td colspan="4" class="doc" id="on0"><pre>Matches on the implicit object argument of a member call expression, after7420stripping off any parentheses or implicit casts.7421 7422Given7423 class Y { public: void m(); };7424 Y g();7425 class X : public Y {};7426 void z(Y y, X x) { y.m(); (g()).m(); x.m(); }7427cxxMemberCallExpr(on(hasType(cxxRecordDecl(hasName("Y")))))7428 matches `y.m()` and `(g()).m()`.7429cxxMemberCallExpr(on(hasType(cxxRecordDecl(hasName("X")))))7430 matches `x.m()`.7431cxxMemberCallExpr(on(callExpr()))7432 matches `(g()).m()`.7433 7434FIXME: Overload to allow directly matching types?7435</pre></td></tr>7436 7437 7438<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMemberCallExpr.html">CXXMemberCallExpr</a>></td><td class="name" onclick="toggle('thisPointerType1')"><a name="thisPointerType1Anchor">thisPointerType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>7439<tr><td colspan="4" class="doc" id="thisPointerType1"><pre>Overloaded to match the type's declaration.7440</pre></td></tr>7441 7442 7443<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMemberCallExpr.html">CXXMemberCallExpr</a>></td><td class="name" onclick="toggle('thisPointerType0')"><a name="thisPointerType0Anchor">thisPointerType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr>7444<tr><td colspan="4" class="doc" id="thisPointerType0"><pre>Matches if the type of the expression's implicit object argument either7445matches the InnerMatcher, or is a pointer to a type that matches the7446InnerMatcher.7447 7448Given7449 class Y { public: void m(); };7450 class X : public Y { void g(); };7451 void z() { Y y; y.m(); Y *p; p->m(); X x; x.m(); x.g(); }7452cxxMemberCallExpr(thisPointerType(hasDeclaration(7453 cxxRecordDecl(hasName("Y")))))7454 matches `y.m()`, `p->m()` and `x.m()`.7455cxxMemberCallExpr(thisPointerType(hasDeclaration(7456 cxxRecordDecl(hasName("X")))))7457 matches `x.g()`.7458</pre></td></tr>7459 7460 7461<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('forEachOverridden0')"><a name="forEachOverridden0Anchor">forEachOverridden</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>> InnerMatcher</td></tr>7462<tr><td colspan="4" class="doc" id="forEachOverridden0"><pre>Matches each method overridden by the given method. This matcher may7463produce multiple matches.7464 7465Given7466 class A { virtual void f(); };7467 class B : public A { void f(); };7468 class C : public B { void f(); };7469cxxMethodDecl(ofClass(hasName("C")),7470 forEachOverridden(cxxMethodDecl().bind("b"))).bind("d")7471 matches once, with "b" binding "A::f" and "d" binding "C::f" (Note7472 that B::f is not overridden by C::f).7473 7474The check can produce multiple matches in case of multiple inheritance, e.g.7475 class A1 { virtual void f(); };7476 class A2 { virtual void f(); };7477 class C : public A1, public A2 { void f(); };7478cxxMethodDecl(ofClass(hasName("C")),7479 forEachOverridden(cxxMethodDecl().bind("b"))).bind("d")7480 matches twice, once with "b" binding "A1::f" and "d" binding "C::f", and7481 once with "b" binding "A2::f" and "d" binding "C::f".7482</pre></td></tr>7483 7484 7485<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('ofClass0')"><a name="ofClass0Anchor">ofClass</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>> InnerMatcher</td></tr>7486<tr><td colspan="4" class="doc" id="ofClass0"><pre>Matches the class declaration that the given method declaration7487belongs to.7488 7489FIXME: Generalize this for other kinds of declarations.7490FIXME: What other kind of declarations would we need to generalize7491this to?7492 7493Example matches A() in the last line7494 (matcher = cxxConstructExpr(hasDeclaration(cxxMethodDecl(7495 ofClass(hasName("A"))))))7496 class A {7497 public:7498 A();7499 };7500 A a = A();7501</pre></td></tr>7502 7503 7504<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>></td><td class="name" onclick="toggle('hasAnyPlacementArg0')"><a name="hasAnyPlacementArg0Anchor">hasAnyPlacementArg</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>7505<tr><td colspan="4" class="doc" id="hasAnyPlacementArg0"><pre>Matches any placement new expression arguments.7506 7507Given:7508 MyClass *p1 = new (Storage) MyClass();7509cxxNewExpr(hasAnyPlacementArg(anything()))7510 matches the expression 'new (Storage, 16) MyClass()'.7511</pre></td></tr>7512 7513 7514<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>></td><td class="name" onclick="toggle('hasArraySize0')"><a name="hasArraySize0Anchor">hasArraySize</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>7515<tr><td colspan="4" class="doc" id="hasArraySize0"><pre>Matches array new expressions with a given array size.7516 7517Given:7518 MyClass *p1 = new MyClass[10];7519cxxNewExpr(hasArraySize(integerLiteral(equals(10))))7520 matches the expression 'new MyClass[10]'.7521</pre></td></tr>7522 7523 7524<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>></td><td class="name" onclick="toggle('hasDeclaration13')"><a name="hasDeclaration13Anchor">hasDeclaration</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>7525<tr><td colspan="4" class="doc" id="hasDeclaration13"><pre>Matches a node if the declaration associated with that node7526matches the given matcher.7527 7528The associated declaration is:7529- for type nodes, the declaration of the underlying type7530- for CallExpr, the declaration of the callee7531- for MemberExpr, the declaration of the referenced member7532- for CXXConstructExpr, the declaration of the constructor7533- for CXXNewExpr, the declaration of the operator new7534- for ObjCIvarExpr, the declaration of the ivar7535 7536For type nodes, hasDeclaration will generally match the declaration of the7537sugared type. Given7538 class X {};7539 typedef X Y;7540 Y y;7541in varDecl(hasType(hasDeclaration(decl()))) the decl will match the7542typedefDecl. A common use case is to match the underlying, desugared type.7543This can be achieved by using the hasUnqualifiedDesugaredType matcher:7544 varDecl(hasType(hasUnqualifiedDesugaredType(7545 recordType(hasDeclaration(decl())))))7546In this matcher, the decl will match the CXXRecordDecl of class X.7547 7548Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>,7549 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>,7550 Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>,7551 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<RecordType>,7552 Matcher<TagType>, Matcher<TemplateSpecializationType>,7553 Matcher<TemplateTypeParmType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>,7554 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingType.html">UsingType</a>>7555</pre></td></tr>7556 7557 7558<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>></td><td class="name" onclick="toggle('hasPlacementArg0')"><a name="hasPlacementArg0Anchor">hasPlacementArg</a></td><td>unsigned Index, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>7559<tr><td colspan="4" class="doc" id="hasPlacementArg0"><pre>Matches placement new expression arguments.7560 7561Given:7562 MyClass *p1 = new (Storage, 16) MyClass();7563cxxNewExpr(hasPlacementArg(1, integerLiteral(equals(16))))7564 matches the expression 'new (Storage, 16) MyClass()'.7565</pre></td></tr>7566 7567 7568<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>></td><td class="name" onclick="toggle('hasTypeLoc4')"><a name="hasTypeLoc4Anchor">hasTypeLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> Inner</td></tr>7569<tr><td colspan="4" class="doc" id="hasTypeLoc4"><pre>Matches if the type location of a node matches the inner matcher.7570 7571Examples:7572 int x;7573declaratorDecl(hasTypeLoc(loc(asString("int"))))7574 matches int x7575 7576auto x = int(3);7577cxxTemporaryObjectExpr(hasTypeLoc(loc(asString("int"))))7578 matches int(3)7579 7580struct Foo { Foo(int, int); };7581auto x = Foo(1, 2);7582cxxFunctionalCastExpr(hasTypeLoc(loc(asString("struct Foo"))))7583 matches Foo(1, 2)7584 7585Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockDecl.html">BlockDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>>,7586 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFunctionalCastExpr.html">CXXFunctionalCastExpr</a>>,7587 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXTemporaryObjectExpr.html">CXXTemporaryObjectExpr</a>>,7588 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXUnresolvedConstructExpr.html">CXXUnresolvedConstructExpr</a>>,7589 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CompoundLiteralExpr.html">CompoundLiteralExpr</a>>,7590 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclaratorDecl.html">DeclaratorDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ExplicitCastExpr.html">ExplicitCastExpr</a>>,7591 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCPropertyDecl.html">ObjCPropertyDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgumentLoc.html">TemplateArgumentLoc</a>>,7592 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefNameDecl.html">TypedefNameDecl</a>>7593</pre></td></tr>7594 7595 7596<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>></td><td class="name" onclick="toggle('hasEitherOperand1')"><a name="hasEitherOperand1Anchor">hasEitherOperand</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>7597<tr><td colspan="4" class="doc" id="hasEitherOperand1"><pre>Matches if either the left hand side or the right hand side of a7598binary operator or fold expression matches.7599</pre></td></tr>7600 7601 7602<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>></td><td class="name" onclick="toggle('hasLHS1')"><a name="hasLHS1Anchor">hasLHS</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>7603<tr><td colspan="4" class="doc" id="hasLHS1"><pre>Matches the left hand side of binary operator expressions.7604 7605Example matches a (matcher = binaryOperator(hasLHS()))7606 a || b7607</pre></td></tr>7608 7609 7610<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>></td><td class="name" onclick="toggle('hasOperands1')"><a name="hasOperands1Anchor">hasOperands</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> Matcher1, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> Matcher2</td></tr>7611<tr><td colspan="4" class="doc" id="hasOperands1"><pre>Matches if both matchers match with opposite sides of the binary operator7612or fold expression.7613 7614Example matcher = binaryOperator(hasOperands(integerLiteral(equals(1),7615 integerLiteral(equals(2)))7616 1 + 2 // Match7617 2 + 1 // Match7618 1 + 1 // No match7619 2 + 2 // No match7620</pre></td></tr>7621 7622 7623<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>></td><td class="name" onclick="toggle('hasRHS1')"><a name="hasRHS1Anchor">hasRHS</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>7624<tr><td colspan="4" class="doc" id="hasRHS1"><pre>Matches the right hand side of binary operator expressions.7625 7626Example matches b (matcher = binaryOperator(hasRHS()))7627 a || b7628</pre></td></tr>7629 7630 7631<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>></td><td class="name" onclick="toggle('hasUnaryOperand1')"><a name="hasUnaryOperand1Anchor">hasUnaryOperand</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>7632<tr><td colspan="4" class="doc" id="hasUnaryOperand1"><pre>Matches if the operand of a unary operator matches.7633 7634Example matches true (matcher = hasUnaryOperand(7635 cxxBoolLiteral(equals(true))))7636 !true7637</pre></td></tr>7638 7639 7640<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('hasAnyBase0')"><a name="hasAnyBase0Anchor">hasAnyBase</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>> BaseSpecMatcher</td></tr>7641<tr><td colspan="4" class="doc" id="hasAnyBase0"><pre>Matches C++ classes that have a direct or indirect base matching BaseSpecMatcher.7642 7643Example:7644matcher hasAnyBase(hasType(cxxRecordDecl(hasName("SpecialBase"))))7645 class Foo;7646 class Bar : Foo {};7647 class Baz : Bar {};7648 class SpecialBase;7649 class Proxy : SpecialBase {}; // matches Proxy7650 class IndirectlyDerived : Proxy {}; //matches IndirectlyDerived7651 7652FIXME: Refactor this and isDerivedFrom to reuse implementation.7653</pre></td></tr>7654 7655 7656<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('hasDirectBase0')"><a name="hasDirectBase0Anchor">hasDirectBase</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>> BaseSpecMatcher</td></tr>7657<tr><td colspan="4" class="doc" id="hasDirectBase0"><pre>Matches C++ classes that have a direct base matching BaseSpecMatcher.7658 7659Example:7660matcher hasDirectBase(hasType(cxxRecordDecl(hasName("SpecialBase"))))7661 class Foo;7662 class Bar : Foo {};7663 class Baz : Bar {};7664 class SpecialBase;7665 class Proxy : SpecialBase {}; // matches Proxy7666 class IndirectlyDerived : Proxy {}; // doesn't match7667</pre></td></tr>7668 7669 7670<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('hasMethod0')"><a name="hasMethod0Anchor">hasMethod</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>> InnerMatcher</td></tr>7671<tr><td colspan="4" class="doc" id="hasMethod0"><pre>Matches the first method of a class or struct that satisfies InnerMatcher.7672 7673Given:7674 class A { void func(); };7675 class B { void member(); };7676 7677cxxRecordDecl(hasMethod(hasName("func"))) matches the declaration of7678A but not B.7679</pre></td></tr>7680 7681 7682<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isDerivedFrom0')"><a name="isDerivedFrom0Anchor">isDerivedFrom</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>> Base</td></tr>7683<tr><td colspan="4" class="doc" id="isDerivedFrom0"><pre>Matches C++ classes that are directly or indirectly derived from a class7684matching Base, or Objective-C classes that directly or indirectly7685subclass a class matching Base.7686 7687Note that a class is not considered to be derived from itself.7688 7689Example matches Y, Z, C (Base == hasName("X"))7690 class X;7691 class Y : public X {}; // directly derived7692 class Z : public Y {}; // indirectly derived7693 typedef X A;7694 typedef A B;7695 class C : public B {}; // derived from a typedef of X7696 7697In the following example, Bar matches isDerivedFrom(hasName("X")):7698 class Foo;7699 typedef Foo X;7700 class Bar : public Foo {}; // derived from a type that X is a typedef of7701 7702In the following example, Bar matches isDerivedFrom(hasName("NSObject"))7703 @interface NSObject @end7704 @interface Bar : NSObject @end7705 7706Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCInterfaceDecl.html">ObjCInterfaceDecl</a>>7707</pre></td></tr>7708 7709 7710<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isDirectlyDerivedFrom0')"><a name="isDirectlyDerivedFrom0Anchor">isDirectlyDerivedFrom</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>> Base</td></tr>7711<tr><td colspan="4" class="doc" id="isDirectlyDerivedFrom0"><pre>Matches C++ or Objective-C classes that are directly derived from a class7712matching Base.7713 7714Note that a class is not considered to be derived from itself.7715 7716Example matches Y, C (Base == hasName("X"))7717 class X;7718 class Y : public X {}; // directly derived7719 class Z : public Y {}; // indirectly derived7720 typedef X A;7721 typedef A B;7722 class C : public B {}; // derived from a typedef of X7723 7724In the following example, Bar matches isDerivedFrom(hasName("X")):7725 class Foo;7726 typedef Foo X;7727 class Bar : public Foo {}; // derived from a type that X is a typedef of7728</pre></td></tr>7729 7730 7731<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isSameOrDerivedFrom0')"><a name="isSameOrDerivedFrom0Anchor">isSameOrDerivedFrom</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>> Base</td></tr>7732<tr><td colspan="4" class="doc" id="isSameOrDerivedFrom0"><pre>Similar to isDerivedFrom(), but also matches classes that directly7733match Base.7734</pre></td></tr>7735 7736 7737<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRewrittenBinaryOperator.html">CXXRewrittenBinaryOperator</a>></td><td class="name" onclick="toggle('hasEitherOperand3')"><a name="hasEitherOperand3Anchor">hasEitherOperand</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>7738<tr><td colspan="4" class="doc" id="hasEitherOperand3"><pre>Matches if either the left hand side or the right hand side of a7739binary operator or fold expression matches.7740</pre></td></tr>7741 7742 7743<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRewrittenBinaryOperator.html">CXXRewrittenBinaryOperator</a>></td><td class="name" onclick="toggle('hasLHS2')"><a name="hasLHS2Anchor">hasLHS</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>7744<tr><td colspan="4" class="doc" id="hasLHS2"><pre>Matches the left hand side of binary operator expressions.7745 7746Example matches a (matcher = binaryOperator(hasLHS()))7747 a || b7748</pre></td></tr>7749 7750 7751<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRewrittenBinaryOperator.html">CXXRewrittenBinaryOperator</a>></td><td class="name" onclick="toggle('hasOperands3')"><a name="hasOperands3Anchor">hasOperands</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> Matcher1, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> Matcher2</td></tr>7752<tr><td colspan="4" class="doc" id="hasOperands3"><pre>Matches if both matchers match with opposite sides of the binary operator7753or fold expression.7754 7755Example matcher = binaryOperator(hasOperands(integerLiteral(equals(1),7756 integerLiteral(equals(2)))7757 1 + 2 // Match7758 2 + 1 // Match7759 1 + 1 // No match7760 2 + 2 // No match7761</pre></td></tr>7762 7763 7764<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRewrittenBinaryOperator.html">CXXRewrittenBinaryOperator</a>></td><td class="name" onclick="toggle('hasRHS2')"><a name="hasRHS2Anchor">hasRHS</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>7765<tr><td colspan="4" class="doc" id="hasRHS2"><pre>Matches the right hand side of binary operator expressions.7766 7767Example matches b (matcher = binaryOperator(hasRHS()))7768 a || b7769</pre></td></tr>7770 7771 7772<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXTemporaryObjectExpr.html">CXXTemporaryObjectExpr</a>></td><td class="name" onclick="toggle('hasTypeLoc5')"><a name="hasTypeLoc5Anchor">hasTypeLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> Inner</td></tr>7773<tr><td colspan="4" class="doc" id="hasTypeLoc5"><pre>Matches if the type location of a node matches the inner matcher.7774 7775Examples:7776 int x;7777declaratorDecl(hasTypeLoc(loc(asString("int"))))7778 matches int x7779 7780auto x = int(3);7781cxxTemporaryObjectExpr(hasTypeLoc(loc(asString("int"))))7782 matches int(3)7783 7784struct Foo { Foo(int, int); };7785auto x = Foo(1, 2);7786cxxFunctionalCastExpr(hasTypeLoc(loc(asString("struct Foo"))))7787 matches Foo(1, 2)7788 7789Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockDecl.html">BlockDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>>,7790 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFunctionalCastExpr.html">CXXFunctionalCastExpr</a>>,7791 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXTemporaryObjectExpr.html">CXXTemporaryObjectExpr</a>>,7792 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXUnresolvedConstructExpr.html">CXXUnresolvedConstructExpr</a>>,7793 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CompoundLiteralExpr.html">CompoundLiteralExpr</a>>,7794 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclaratorDecl.html">DeclaratorDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ExplicitCastExpr.html">ExplicitCastExpr</a>>,7795 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCPropertyDecl.html">ObjCPropertyDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgumentLoc.html">TemplateArgumentLoc</a>>,7796 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefNameDecl.html">TypedefNameDecl</a>>7797</pre></td></tr>7798 7799 7800<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXUnresolvedConstructExpr.html">CXXUnresolvedConstructExpr</a>></td><td class="name" onclick="toggle('hasAnyArgument2')"><a name="hasAnyArgument2Anchor">hasAnyArgument</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>7801<tr><td colspan="4" class="doc" id="hasAnyArgument2"><pre>Matches any argument of a call expression or a constructor call7802expression, or an ObjC-message-send expression.7803 7804Given7805 void x(int, int, int) { int y; x(1, y, 42); }7806callExpr(hasAnyArgument(declRefExpr()))7807 matches x(1, y, 42)7808with hasAnyArgument(...)7809 matching y7810 7811For ObjectiveC, given7812 @interface I - (void) f:(int) y; @end7813 void foo(I *i) { [i f:12]; }7814objcMessageExpr(hasAnyArgument(integerLiteral(equals(12))))7815 matches [i f:12]7816</pre></td></tr>7817 7818 7819<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXUnresolvedConstructExpr.html">CXXUnresolvedConstructExpr</a>></td><td class="name" onclick="toggle('hasArgument2')"><a name="hasArgument2Anchor">hasArgument</a></td><td>unsigned N, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>7820<tr><td colspan="4" class="doc" id="hasArgument2"><pre>Matches the n'th argument of a call expression or a constructor7821call expression.7822 7823Example matches y in x(y)7824 (matcher = callExpr(hasArgument(0, declRefExpr())))7825 void x(int) { int y; x(y); }7826</pre></td></tr>7827 7828 7829<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXUnresolvedConstructExpr.html">CXXUnresolvedConstructExpr</a>></td><td class="name" onclick="toggle('hasTypeLoc6')"><a name="hasTypeLoc6Anchor">hasTypeLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> Inner</td></tr>7830<tr><td colspan="4" class="doc" id="hasTypeLoc6"><pre>Matches if the type location of a node matches the inner matcher.7831 7832Examples:7833 int x;7834declaratorDecl(hasTypeLoc(loc(asString("int"))))7835 matches int x7836 7837auto x = int(3);7838cxxTemporaryObjectExpr(hasTypeLoc(loc(asString("int"))))7839 matches int(3)7840 7841struct Foo { Foo(int, int); };7842auto x = Foo(1, 2);7843cxxFunctionalCastExpr(hasTypeLoc(loc(asString("struct Foo"))))7844 matches Foo(1, 2)7845 7846Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockDecl.html">BlockDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>>,7847 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFunctionalCastExpr.html">CXXFunctionalCastExpr</a>>,7848 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXTemporaryObjectExpr.html">CXXTemporaryObjectExpr</a>>,7849 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXUnresolvedConstructExpr.html">CXXUnresolvedConstructExpr</a>>,7850 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CompoundLiteralExpr.html">CompoundLiteralExpr</a>>,7851 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclaratorDecl.html">DeclaratorDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ExplicitCastExpr.html">ExplicitCastExpr</a>>,7852 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCPropertyDecl.html">ObjCPropertyDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgumentLoc.html">TemplateArgumentLoc</a>>,7853 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefNameDecl.html">TypedefNameDecl</a>>7854</pre></td></tr>7855 7856 7857<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>></td><td class="name" onclick="toggle('callee3')"><a name="callee3Anchor">callee</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>7858<tr><td colspan="4" class="doc" id="callee3"><pre>Matches 1) if the call expression's callee's declaration matches the7859given matcher; or 2) if the Obj-C message expression's callee's method7860declaration matches the given matcher.7861 7862Example matches y.x() (matcher = callExpr(callee(7863 cxxMethodDecl(hasName("x")))))7864 class Y { public: void x(); };7865 void z() { Y y; y.x(); }7866 7867Example 2. Matches [I foo] with7868objcMessageExpr(callee(objcMethodDecl(hasName("foo"))))7869 7870 @interface I: NSObject7871 +(void)foo;7872 @end7873 ...7874 [I foo]7875</pre></td></tr>7876 7877 7878<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>></td><td class="name" onclick="toggle('callee0')"><a name="callee0Anchor">callee</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr>7879<tr><td colspan="4" class="doc" id="callee0"><pre>Matches if the call or fold expression's callee expression matches.7880 7881Given7882 class Y { void x() { this->x(); x(); Y y; y.x(); } };7883 void f() { f(); }7884callExpr(callee(expr()))7885 matches this->x(), x(), y.x(), f()7886with callee(...)7887 matching this->x, x, y.x, f respectively7888 7889Given7890 template <typename... Args>7891 auto sum(Args... args) {7892 return (0 + ... + args);7893 }7894 7895 template <typename... Args>7896 auto multiply(Args... args) {7897 return (args * ... * 1);7898 }7899cxxFoldExpr(callee(expr()))7900 matches (args * ... * 1)7901with callee(...)7902 matching *7903 7904Note: Callee cannot take the more general internal::Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>>7905because this introduces ambiguous overloads with calls to Callee taking a7906internal::Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, as the matcher hierarchy is purely7907implemented in terms of implicit casts.7908</pre></td></tr>7909 7910 7911<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>></td><td class="name" onclick="toggle('forEachArgumentWithParam0')"><a name="forEachArgumentWithParam0Anchor">forEachArgumentWithParam</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> ArgMatcher, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html">ParmVarDecl</a>> ParamMatcher</td></tr>7912<tr><td colspan="4" class="doc" id="forEachArgumentWithParam0"><pre>Matches all arguments and their respective ParmVarDecl.7913 7914Given7915 void f(int i);7916 int y;7917 f(y);7918callExpr(7919 forEachArgumentWithParam(7920 declRefExpr(to(varDecl(hasName("y")))),7921 parmVarDecl(hasType(isInteger()))7922))7923 matches f(y);7924with declRefExpr(...)7925 matching int y7926and parmVarDecl(...)7927 matching int i7928</pre></td></tr>7929 7930 7931<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>></td><td class="name" onclick="toggle('forEachArgumentWithParamType0')"><a name="forEachArgumentWithParamType0Anchor">forEachArgumentWithParamType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> ArgMatcher, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> ParamMatcher</td></tr>7932<tr><td colspan="4" class="doc" id="forEachArgumentWithParamType0"><pre>Matches all arguments and their respective types for a CallExpr or7933CXXConstructExpr. It is very similar to forEachArgumentWithParam but7934it works on calls through function pointers as well.7935 7936The difference is, that function pointers do not provide access to a7937ParmVarDecl, but only the QualType for each argument.7938 7939Given7940 void f(int i);7941 int y;7942 f(y);7943 void (*f_ptr)(int) = f;7944 f_ptr(y);7945callExpr(7946 forEachArgumentWithParamType(7947 declRefExpr(to(varDecl(hasName("y")))),7948 qualType(isInteger()).bind("type)7949))7950 matches f(y) and f_ptr(y)7951with declRefExpr(...)7952 matching int y7953and qualType(...)7954 matching int7955</pre></td></tr>7956 7957 7958<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>></td><td class="name" onclick="toggle('hasAnyArgument0')"><a name="hasAnyArgument0Anchor">hasAnyArgument</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>7959<tr><td colspan="4" class="doc" id="hasAnyArgument0"><pre>Matches any argument of a call expression or a constructor call7960expression, or an ObjC-message-send expression.7961 7962Given7963 void x(int, int, int) { int y; x(1, y, 42); }7964callExpr(hasAnyArgument(declRefExpr()))7965 matches x(1, y, 42)7966with hasAnyArgument(...)7967 matching y7968 7969For ObjectiveC, given7970 @interface I - (void) f:(int) y; @end7971 void foo(I *i) { [i f:12]; }7972objcMessageExpr(hasAnyArgument(integerLiteral(equals(12))))7973 matches [i f:12]7974</pre></td></tr>7975 7976 7977<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>></td><td class="name" onclick="toggle('hasArgument0')"><a name="hasArgument0Anchor">hasArgument</a></td><td>unsigned N, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>7978<tr><td colspan="4" class="doc" id="hasArgument0"><pre>Matches the n'th argument of a call expression or a constructor7979call expression.7980 7981Example matches y in x(y)7982 (matcher = callExpr(hasArgument(0, declRefExpr())))7983 void x(int) { int y; x(y); }7984</pre></td></tr>7985 7986 7987<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>></td><td class="name" onclick="toggle('hasDeclaration15')"><a name="hasDeclaration15Anchor">hasDeclaration</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>7988<tr><td colspan="4" class="doc" id="hasDeclaration15"><pre>Matches a node if the declaration associated with that node7989matches the given matcher.7990 7991The associated declaration is:7992- for type nodes, the declaration of the underlying type7993- for CallExpr, the declaration of the callee7994- for MemberExpr, the declaration of the referenced member7995- for CXXConstructExpr, the declaration of the constructor7996- for CXXNewExpr, the declaration of the operator new7997- for ObjCIvarExpr, the declaration of the ivar7998 7999For type nodes, hasDeclaration will generally match the declaration of the8000sugared type. Given8001 class X {};8002 typedef X Y;8003 Y y;8004in varDecl(hasType(hasDeclaration(decl()))) the decl will match the8005typedefDecl. A common use case is to match the underlying, desugared type.8006This can be achieved by using the hasUnqualifiedDesugaredType matcher:8007 varDecl(hasType(hasUnqualifiedDesugaredType(8008 recordType(hasDeclaration(decl())))))8009In this matcher, the decl will match the CXXRecordDecl of class X.8010 8011Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>,8012 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>,8013 Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>,8014 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<RecordType>,8015 Matcher<TagType>, Matcher<TemplateSpecializationType>,8016 Matcher<TemplateTypeParmType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>,8017 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingType.html">UsingType</a>>8018</pre></td></tr>8019 8020 8021<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CaseStmt.html">CaseStmt</a>></td><td class="name" onclick="toggle('hasCaseConstant0')"><a name="hasCaseConstant0Anchor">hasCaseConstant</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>8022<tr><td colspan="4" class="doc" id="hasCaseConstant0"><pre>If the given case statement does not use the GNU case range8023extension, matches the constant given in the statement.8024 8025Given8026 switch (1) { case 1: case 1+1: case 3 ... 4: ; }8027caseStmt(hasCaseConstant(integerLiteral()))8028 matches "case 1:"8029</pre></td></tr>8030 8031 8032<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CastExpr.html">CastExpr</a>></td><td class="name" onclick="toggle('hasSourceExpression0')"><a name="hasSourceExpression0Anchor">hasSourceExpression</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>8033<tr><td colspan="4" class="doc" id="hasSourceExpression0"><pre>Matches if the cast's source expression8034or opaque value's source expression matches the given matcher.8035 8036Example 1: matches "a string"8037(matcher = castExpr(hasSourceExpression(cxxConstructExpr())))8038class URL { URL(string); };8039URL url = "a string";8040 8041Example 2: matches 'b' (matcher =8042opaqueValueExpr(hasSourceExpression(implicitCastExpr(declRefExpr())))8043int a = b ?: 1;8044</pre></td></tr>8045 8046 8047<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html">ClassTemplateSpecializationDecl</a>></td><td class="name" onclick="toggle('forEachTemplateArgument0')"><a name="forEachTemplateArgument0Anchor">forEachTemplateArgument</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr>8048<tr><td colspan="4" class="doc" id="forEachTemplateArgument0"><pre>Matches templateSpecializationType, class template specialization,8049variable template specialization, and function template specialization8050nodes where the template argument matches the inner matcher. This matcher8051may produce multiple matches.8052 8053Given8054 template <typename T, unsigned N, unsigned M>8055 struct Matrix {};8056 8057 constexpr unsigned R = 2;8058 Matrix<int, R * 2, R * 4> M;8059 8060 template <typename T, typename U>8061 void f(T&& t, U&& u) {}8062 8063 bool B = false;8064 f(R, B);8065templateSpecializationType(forEachTemplateArgument(isExpr(expr())))8066 matches twice, with expr() matching 'R * 2' and 'R * 4'8067functionDecl(forEachTemplateArgument(refersToType(builtinType())))8068 matches the specialization f<unsigned, bool> twice, for 'unsigned'8069 and 'bool'8070</pre></td></tr>8071 8072 8073<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html">ClassTemplateSpecializationDecl</a>></td><td class="name" onclick="toggle('hasAnyTemplateArgumentLoc0')"><a name="hasAnyTemplateArgumentLoc0Anchor">hasAnyTemplateArgumentLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgumentLoc.html">TemplateArgumentLoc</a>> InnerMatcher</td></tr>8074<tr><td colspan="4" class="doc" id="hasAnyTemplateArgumentLoc0"><pre>Matches template specialization `TypeLoc`s, class template specializations,8075variable template specializations, and function template specializations8076that have at least one `TemplateArgumentLoc` matching the given8077`InnerMatcher`.8078 8079Given8080 template<typename T> class A {};8081 A<int> a;8082varDecl(hasTypeLoc(templateSpecializationTypeLoc(hasAnyTemplateArgumentLoc(8083 hasTypeLoc(loc(asString("int")))))))8084 matches `A<int> a`.8085</pre></td></tr>8086 8087 8088<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html">ClassTemplateSpecializationDecl</a>></td><td class="name" onclick="toggle('hasAnyTemplateArgument0')"><a name="hasAnyTemplateArgument0Anchor">hasAnyTemplateArgument</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr>8089<tr><td colspan="4" class="doc" id="hasAnyTemplateArgument0"><pre>Matches templateSpecializationTypes, class template specializations,8090variable template specializations, and function template specializations8091that have at least one TemplateArgument matching the given InnerMatcher.8092 8093Given8094 template<typename T> class A {};8095 template<> class A<double> {};8096 A<int> a;8097 8098 template<typename T> f() {};8099 void func() { f<int>(); };8100 8101classTemplateSpecializationDecl(hasAnyTemplateArgument(8102 refersToType(asString("int"))))8103 matches the specialization A<int>8104 8105functionDecl(hasAnyTemplateArgument(refersToType(asString("int"))))8106 matches the specialization f<int>8107</pre></td></tr>8108 8109 8110<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html">ClassTemplateSpecializationDecl</a>></td><td class="name" onclick="toggle('hasSpecializedTemplate0')"><a name="hasSpecializedTemplate0Anchor">hasSpecializedTemplate</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ClassTemplateDecl.html">ClassTemplateDecl</a>> InnerMatcher</td></tr>8111<tr><td colspan="4" class="doc" id="hasSpecializedTemplate0"><pre>Matches the specialized template of a specialization declaration.8112 8113Given8114 template<typename T> class A {}; #18115 template<> class A<int> {}; #28116classTemplateSpecializationDecl(hasSpecializedTemplate(classTemplateDecl()))8117 matches '#2' with classTemplateDecl() matching the class template8118 declaration of 'A' at #1.8119</pre></td></tr>8120 8121 8122<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html">ClassTemplateSpecializationDecl</a>></td><td class="name" onclick="toggle('hasTemplateArgumentLoc0')"><a name="hasTemplateArgumentLoc0Anchor">hasTemplateArgumentLoc</a></td><td>unsigned Index, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgumentLoc.html">TemplateArgumentLoc</a>> InnerMatcher</td></tr>8123<tr><td colspan="4" class="doc" id="hasTemplateArgumentLoc0"><pre>Matches template specialization `TypeLoc`s, class template specializations,8124variable template specializations, and function template specializations8125where the n'th `TemplateArgumentLoc` matches the given `InnerMatcher`.8126 8127Given8128 template<typename T, typename U> class A {};8129 A<double, int> b;8130 A<int, double> c;8131varDecl(hasTypeLoc(templateSpecializationTypeLoc(hasTemplateArgumentLoc(0,8132 hasTypeLoc(loc(asString("double")))))))8133 matches `A<double, int> b`, but not `A<int, double> c`.8134</pre></td></tr>8135 8136 8137<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html">ClassTemplateSpecializationDecl</a>></td><td class="name" onclick="toggle('hasTemplateArgument0')"><a name="hasTemplateArgument0Anchor">hasTemplateArgument</a></td><td>unsigned N, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr>8138<tr><td colspan="4" class="doc" id="hasTemplateArgument0"><pre>Matches templateSpecializationType, class template specializations,8139variable template specializations, and function template specializations8140where the n'th TemplateArgument matches the given InnerMatcher.8141 8142Given8143 template<typename T, typename U> class A {};8144 A<bool, int> b;8145 A<int, bool> c;8146 8147 template<typename T> void f() {}8148 void func() { f<int>(); };8149classTemplateSpecializationDecl(hasTemplateArgument(8150 1, refersToType(asString("int"))))8151 matches the specialization A<bool, int>8152 8153functionDecl(hasTemplateArgument(0, refersToType(asString("int"))))8154 matches the specialization f<int>8155</pre></td></tr>8156 8157 8158<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ComplexType.html">ComplexType</a>></td><td class="name" onclick="toggle('hasElementType1')"><a name="hasElementType1Anchor">hasElementType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr>8159<tr><td colspan="4" class="doc" id="hasElementType1"><pre>Matches arrays and C99 complex types that have a specific element8160type.8161 8162Given8163 struct A {};8164 A a[7];8165 int b[7];8166arrayType(hasElementType(builtinType()))8167 matches "int b[7]"8168 8169Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ArrayType.html">ArrayType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ComplexType.html">ComplexType</a>>8170</pre></td></tr>8171 8172 8173<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CompoundLiteralExpr.html">CompoundLiteralExpr</a>></td><td class="name" onclick="toggle('hasTypeLoc7')"><a name="hasTypeLoc7Anchor">hasTypeLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> Inner</td></tr>8174<tr><td colspan="4" class="doc" id="hasTypeLoc7"><pre>Matches if the type location of a node matches the inner matcher.8175 8176Examples:8177 int x;8178declaratorDecl(hasTypeLoc(loc(asString("int"))))8179 matches int x8180 8181auto x = int(3);8182cxxTemporaryObjectExpr(hasTypeLoc(loc(asString("int"))))8183 matches int(3)8184 8185struct Foo { Foo(int, int); };8186auto x = Foo(1, 2);8187cxxFunctionalCastExpr(hasTypeLoc(loc(asString("struct Foo"))))8188 matches Foo(1, 2)8189 8190Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockDecl.html">BlockDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>>,8191 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFunctionalCastExpr.html">CXXFunctionalCastExpr</a>>,8192 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXTemporaryObjectExpr.html">CXXTemporaryObjectExpr</a>>,8193 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXUnresolvedConstructExpr.html">CXXUnresolvedConstructExpr</a>>,8194 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CompoundLiteralExpr.html">CompoundLiteralExpr</a>>,8195 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclaratorDecl.html">DeclaratorDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ExplicitCastExpr.html">ExplicitCastExpr</a>>,8196 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCPropertyDecl.html">ObjCPropertyDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgumentLoc.html">TemplateArgumentLoc</a>>,8197 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefNameDecl.html">TypedefNameDecl</a>>8198</pre></td></tr>8199 8200 8201<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CompoundStmt.html">CompoundStmt</a>></td><td class="name" onclick="toggle('hasAnySubstatement0')"><a name="hasAnySubstatement0Anchor">hasAnySubstatement</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr>8202<tr><td colspan="4" class="doc" id="hasAnySubstatement0"><pre>Matches compound statements where at least one substatement matches8203a given matcher. Also matches StmtExprs that have CompoundStmt as children.8204 8205Given8206 { {}; 1+2; }8207hasAnySubstatement(compoundStmt())8208 matches '{ {}; 1+2; }'8209with compoundStmt()8210 matching '{}'8211</pre></td></tr>8212 8213 8214<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CoroutineBodyStmt.html">CoroutineBodyStmt</a>></td><td class="name" onclick="toggle('hasBody5')"><a name="hasBody5Anchor">hasBody</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr>8215<tr><td colspan="4" class="doc" id="hasBody5"><pre>Matches a 'for', 'while', 'while' statement or a function or coroutine8216definition that has a given body. Note that in case of functions or8217coroutines this matcher only matches the definition itself and not the8218other declarations of the same function or coroutine.8219 8220Given8221 for (;;) {}8222forStmt(hasBody(compoundStmt()))8223 matches 'for (;;) {}'8224with compoundStmt()8225 matching '{}'8226 8227Given8228 void f();8229 void f() {}8230functionDecl(hasBody(compoundStmt()))8231 matches 'void f() {}'8232with compoundStmt()8233 matching '{}'8234 but does not match 'void f();'8235</pre></td></tr>8236 8237 8238<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DecayedType.html">DecayedType</a>></td><td class="name" onclick="toggle('hasDecayedType0')"><a name="hasDecayedType0Anchor">hasDecayedType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerType</td></tr>8239<tr><td colspan="4" class="doc" id="hasDecayedType0"><pre>Matches the decayed type, whose decayed type matches InnerMatcher8240</pre></td></tr>8241 8242 8243<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>></td><td class="name" onclick="toggle('hasAnyTemplateArgumentLoc3')"><a name="hasAnyTemplateArgumentLoc3Anchor">hasAnyTemplateArgumentLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgumentLoc.html">TemplateArgumentLoc</a>> InnerMatcher</td></tr>8244<tr><td colspan="4" class="doc" id="hasAnyTemplateArgumentLoc3"><pre>Matches template specialization `TypeLoc`s, class template specializations,8245variable template specializations, and function template specializations8246that have at least one `TemplateArgumentLoc` matching the given8247`InnerMatcher`.8248 8249Given8250 template<typename T> class A {};8251 A<int> a;8252varDecl(hasTypeLoc(templateSpecializationTypeLoc(hasAnyTemplateArgumentLoc(8253 hasTypeLoc(loc(asString("int")))))))8254 matches `A<int> a`.8255</pre></td></tr>8256 8257 8258<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>></td><td class="name" onclick="toggle('hasDeclaration12')"><a name="hasDeclaration12Anchor">hasDeclaration</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>8259<tr><td colspan="4" class="doc" id="hasDeclaration12"><pre>Matches a node if the declaration associated with that node8260matches the given matcher.8261 8262The associated declaration is:8263- for type nodes, the declaration of the underlying type8264- for CallExpr, the declaration of the callee8265- for MemberExpr, the declaration of the referenced member8266- for CXXConstructExpr, the declaration of the constructor8267- for CXXNewExpr, the declaration of the operator new8268- for ObjCIvarExpr, the declaration of the ivar8269 8270For type nodes, hasDeclaration will generally match the declaration of the8271sugared type. Given8272 class X {};8273 typedef X Y;8274 Y y;8275in varDecl(hasType(hasDeclaration(decl()))) the decl will match the8276typedefDecl. A common use case is to match the underlying, desugared type.8277This can be achieved by using the hasUnqualifiedDesugaredType matcher:8278 varDecl(hasType(hasUnqualifiedDesugaredType(8279 recordType(hasDeclaration(decl())))))8280In this matcher, the decl will match the CXXRecordDecl of class X.8281 8282Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>,8283 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>,8284 Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>,8285 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<RecordType>,8286 Matcher<TagType>, Matcher<TemplateSpecializationType>,8287 Matcher<TemplateTypeParmType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>,8288 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingType.html">UsingType</a>>8289</pre></td></tr>8290 8291 8292<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>></td><td class="name" onclick="toggle('hasTemplateArgumentLoc3')"><a name="hasTemplateArgumentLoc3Anchor">hasTemplateArgumentLoc</a></td><td>unsigned Index, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgumentLoc.html">TemplateArgumentLoc</a>> InnerMatcher</td></tr>8293<tr><td colspan="4" class="doc" id="hasTemplateArgumentLoc3"><pre>Matches template specialization `TypeLoc`s, class template specializations,8294variable template specializations, and function template specializations8295where the n'th `TemplateArgumentLoc` matches the given `InnerMatcher`.8296 8297Given8298 template<typename T, typename U> class A {};8299 A<double, int> b;8300 A<int, double> c;8301varDecl(hasTypeLoc(templateSpecializationTypeLoc(hasTemplateArgumentLoc(0,8302 hasTypeLoc(loc(asString("double")))))))8303 matches `A<double, int> b`, but not `A<int, double> c`.8304</pre></td></tr>8305 8306 8307<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>></td><td class="name" onclick="toggle('throughUsingDecl0')"><a name="throughUsingDecl0Anchor">throughUsingDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingShadowDecl.html">UsingShadowDecl</a>> Inner</td></tr>8308<tr><td colspan="4" class="doc" id="throughUsingDecl0"><pre>Matches if a node refers to a declaration through a specific8309using shadow declaration.8310 8311Examples:8312 namespace a { int f(); }8313 using a::f;8314 int x = f();8315declRefExpr(throughUsingDecl(anything()))8316 matches f8317 8318 namespace a { class X{}; }8319 using a::X;8320 X x;8321typeLoc(loc(usingType(throughUsingDecl(anything()))))8322 matches X8323 8324Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingType.html">UsingType</a>>8325</pre></td></tr>8326 8327 8328<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>></td><td class="name" onclick="toggle('to0')"><a name="to0Anchor">to</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>8329<tr><td colspan="4" class="doc" id="to0"><pre>Matches a DeclRefExpr that refers to a declaration that matches the8330specified matcher.8331 8332Example matches x in if(x)8333 (matcher = declRefExpr(to(varDecl(hasName("x")))))8334 bool x;8335 if (x) {}8336</pre></td></tr>8337 8338 8339<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html">DeclStmt</a>></td><td class="name" onclick="toggle('containsDeclaration0')"><a name="containsDeclaration0Anchor">containsDeclaration</a></td><td>unsigned N, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>8340<tr><td colspan="4" class="doc" id="containsDeclaration0"><pre>Matches the n'th declaration of a declaration statement.8341 8342Note that this does not work for global declarations because the AST8343breaks up multiple-declaration DeclStmt's into multiple single-declaration8344DeclStmt's.8345Example: Given non-global declarations8346 int a, b = 0;8347 int c;8348 int d = 2, e;8349declStmt(containsDeclaration(8350 0, varDecl(hasInitializer(anything()))))8351 matches only 'int d = 2, e;', and8352declStmt(containsDeclaration(1, varDecl()))8353 matches 'int a, b = 0' as well as 'int d = 2, e;'8354 but 'int c;' is not matched.8355</pre></td></tr>8356 8357 8358<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html">DeclStmt</a>></td><td class="name" onclick="toggle('hasSingleDecl0')"><a name="hasSingleDecl0Anchor">hasSingleDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>8359<tr><td colspan="4" class="doc" id="hasSingleDecl0"><pre>Matches the Decl of a DeclStmt which has a single declaration.8360 8361Given8362 int a, b;8363 int c;8364declStmt(hasSingleDecl(anything()))8365 matches 'int c;' but not 'int a, b;'.8366</pre></td></tr>8367 8368 8369<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclaratorDecl.html">DeclaratorDecl</a>></td><td class="name" onclick="toggle('hasTypeLoc8')"><a name="hasTypeLoc8Anchor">hasTypeLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> Inner</td></tr>8370<tr><td colspan="4" class="doc" id="hasTypeLoc8"><pre>Matches if the type location of a node matches the inner matcher.8371 8372Examples:8373 int x;8374declaratorDecl(hasTypeLoc(loc(asString("int"))))8375 matches int x8376 8377auto x = int(3);8378cxxTemporaryObjectExpr(hasTypeLoc(loc(asString("int"))))8379 matches int(3)8380 8381struct Foo { Foo(int, int); };8382auto x = Foo(1, 2);8383cxxFunctionalCastExpr(hasTypeLoc(loc(asString("struct Foo"))))8384 matches Foo(1, 2)8385 8386Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockDecl.html">BlockDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>>,8387 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFunctionalCastExpr.html">CXXFunctionalCastExpr</a>>,8388 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXTemporaryObjectExpr.html">CXXTemporaryObjectExpr</a>>,8389 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXUnresolvedConstructExpr.html">CXXUnresolvedConstructExpr</a>>,8390 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CompoundLiteralExpr.html">CompoundLiteralExpr</a>>,8391 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclaratorDecl.html">DeclaratorDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ExplicitCastExpr.html">ExplicitCastExpr</a>>,8392 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCPropertyDecl.html">ObjCPropertyDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgumentLoc.html">TemplateArgumentLoc</a>>,8393 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefNameDecl.html">TypedefNameDecl</a>>8394</pre></td></tr>8395 8396 8397<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('hasDeclContext0')"><a name="hasDeclContext0Anchor">hasDeclContext</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>8398<tr><td colspan="4" class="doc" id="hasDeclContext0"><pre>Matches declarations whose declaration context, interpreted as a8399Decl, matches InnerMatcher.8400 8401Given8402 namespace N {8403 namespace M {8404 class D {};8405 }8406 }8407 8408cxxRecordDecl(hasDeclContext(namedDecl(hasName("M")))) matches the8409declaration of class D.8410</pre></td></tr>8411 8412 8413<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DecompositionDecl.html">DecompositionDecl</a>></td><td class="name" onclick="toggle('hasAnyBinding0')"><a name="hasAnyBinding0Anchor">hasAnyBinding</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BindingDecl.html">BindingDecl</a>> InnerMatcher</td></tr>8414<tr><td colspan="4" class="doc" id="hasAnyBinding0"><pre>Matches any binding of a DecompositionDecl.8415 8416For example, in:8417void foo()8418{8419 int arr[3];8420 auto &[f, s, t] = arr;8421 8422 f = 42;8423}8424The matcher:8425 decompositionDecl(hasAnyBinding(bindingDecl(hasName("f").bind("fBinding"))))8426matches the decomposition decl with 'f' bound to "fBinding".8427</pre></td></tr>8428 8429 8430<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DecompositionDecl.html">DecompositionDecl</a>></td><td class="name" onclick="toggle('hasBinding0')"><a name="hasBinding0Anchor">hasBinding</a></td><td>unsigned N, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BindingDecl.html">BindingDecl</a>> InnerMatcher</td></tr>8431<tr><td colspan="4" class="doc" id="hasBinding0"><pre>Matches the Nth binding of a DecompositionDecl.8432 8433For example, in:8434void foo()8435{8436 int arr[3];8437 auto &[f, s, t] = arr;8438 8439 f = 42;8440}8441The matcher:8442 decompositionDecl(hasBinding(0,8443 bindingDecl(hasName("f").bind("fBinding"))))8444matches the decomposition decl with 'f' bound to "fBinding".8445</pre></td></tr>8446 8447 8448<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DoStmt.html">DoStmt</a>></td><td class="name" onclick="toggle('hasBody0')"><a name="hasBody0Anchor">hasBody</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr>8449<tr><td colspan="4" class="doc" id="hasBody0"><pre>Matches a 'for', 'while', 'while' statement or a function or coroutine8450definition that has a given body. Note that in case of functions or8451coroutines this matcher only matches the definition itself and not the8452other declarations of the same function or coroutine.8453 8454Given8455 for (;;) {}8456forStmt(hasBody(compoundStmt()))8457 matches 'for (;;) {}'8458with compoundStmt()8459 matching '{}'8460 8461Given8462 void f();8463 void f() {}8464functionDecl(hasBody(compoundStmt()))8465 matches 'void f() {}'8466with compoundStmt()8467 matching '{}'8468 but does not match 'void f();'8469</pre></td></tr>8470 8471 8472<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DoStmt.html">DoStmt</a>></td><td class="name" onclick="toggle('hasCondition3')"><a name="hasCondition3Anchor">hasCondition</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>8473<tr><td colspan="4" class="doc" id="hasCondition3"><pre>Matches the condition expression of an if statement, for loop, while loop,8474do-while loop, switch statement or conditional operator.8475 8476Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true))))8477 if (true) {}8478</pre></td></tr>8479 8480 8481<tr><td>Matcher<EnumType></td><td class="name" onclick="toggle('hasDeclaration11')"><a name="hasDeclaration11Anchor">hasDeclaration</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>8482<tr><td colspan="4" class="doc" id="hasDeclaration11"><pre>Matches a node if the declaration associated with that node8483matches the given matcher.8484 8485The associated declaration is:8486- for type nodes, the declaration of the underlying type8487- for CallExpr, the declaration of the callee8488- for MemberExpr, the declaration of the referenced member8489- for CXXConstructExpr, the declaration of the constructor8490- for CXXNewExpr, the declaration of the operator new8491- for ObjCIvarExpr, the declaration of the ivar8492 8493For type nodes, hasDeclaration will generally match the declaration of the8494sugared type. Given8495 class X {};8496 typedef X Y;8497 Y y;8498in varDecl(hasType(hasDeclaration(decl()))) the decl will match the8499typedefDecl. A common use case is to match the underlying, desugared type.8500This can be achieved by using the hasUnqualifiedDesugaredType matcher:8501 varDecl(hasType(hasUnqualifiedDesugaredType(8502 recordType(hasDeclaration(decl())))))8503In this matcher, the decl will match the CXXRecordDecl of class X.8504 8505Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>,8506 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>,8507 Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>,8508 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<RecordType>,8509 Matcher<TagType>, Matcher<TemplateSpecializationType>,8510 Matcher<TemplateTypeParmType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>,8511 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingType.html">UsingType</a>>8512</pre></td></tr>8513 8514 8515<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ExplicitCastExpr.html">ExplicitCastExpr</a>></td><td class="name" onclick="toggle('hasDestinationType0')"><a name="hasDestinationType0Anchor">hasDestinationType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr>8516<tr><td colspan="4" class="doc" id="hasDestinationType0"><pre>Matches casts whose destination type matches a given matcher.8517 8518(Note: Clang's AST refers to other conversions as "casts" too, and calls8519actual casts "explicit" casts.)8520</pre></td></tr>8521 8522 8523<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ExplicitCastExpr.html">ExplicitCastExpr</a>></td><td class="name" onclick="toggle('hasTypeLoc9')"><a name="hasTypeLoc9Anchor">hasTypeLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> Inner</td></tr>8524<tr><td colspan="4" class="doc" id="hasTypeLoc9"><pre>Matches if the type location of a node matches the inner matcher.8525 8526Examples:8527 int x;8528declaratorDecl(hasTypeLoc(loc(asString("int"))))8529 matches int x8530 8531auto x = int(3);8532cxxTemporaryObjectExpr(hasTypeLoc(loc(asString("int"))))8533 matches int(3)8534 8535struct Foo { Foo(int, int); };8536auto x = Foo(1, 2);8537cxxFunctionalCastExpr(hasTypeLoc(loc(asString("struct Foo"))))8538 matches Foo(1, 2)8539 8540Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockDecl.html">BlockDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>>,8541 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFunctionalCastExpr.html">CXXFunctionalCastExpr</a>>,8542 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXTemporaryObjectExpr.html">CXXTemporaryObjectExpr</a>>,8543 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXUnresolvedConstructExpr.html">CXXUnresolvedConstructExpr</a>>,8544 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CompoundLiteralExpr.html">CompoundLiteralExpr</a>>,8545 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclaratorDecl.html">DeclaratorDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ExplicitCastExpr.html">ExplicitCastExpr</a>>,8546 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCPropertyDecl.html">ObjCPropertyDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgumentLoc.html">TemplateArgumentLoc</a>>,8547 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefNameDecl.html">TypedefNameDecl</a>>8548</pre></td></tr>8549 8550 8551<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>></td><td class="name" onclick="toggle('hasType5')"><a name="hasType5Anchor">hasType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>8552<tr><td colspan="4" class="doc" id="hasType5"><pre>Overloaded to match the declaration of the expression's or value8553declaration's type.8554 8555In case of a value declaration (for example a variable declaration),8556this resolves one layer of indirection. For example, in the value8557declaration "X x;", cxxRecordDecl(hasName("X")) matches the declaration of8558X, while varDecl(hasType(cxxRecordDecl(hasName("X")))) matches the8559declaration of x.8560 8561Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X")))))8562 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X")))))8563 and friend class X (matcher = friendDecl(hasType("X"))8564 and public virtual X (matcher = cxxBaseSpecifier(hasType(8565 cxxRecordDecl(hasName("X"))))8566 class X {};8567 void y(X &x) { x; X z; }8568 class Y { friend class X; };8569 class Z : public virtual X {};8570 8571Example matches class Derived8572(matcher = cxxRecordDecl(hasAnyBase(hasType(cxxRecordDecl(hasName("Base"))))))8573class Base {};8574class Derived : Base {};8575 8576Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FriendDecl.html">FriendDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</a>>,8577Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>>8578</pre></td></tr>8579 8580 8581<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>></td><td class="name" onclick="toggle('hasType0')"><a name="hasType0Anchor">hasType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr>8582<tr><td colspan="4" class="doc" id="hasType0"><pre>Matches if the expression's or declaration's type matches a type8583matcher.8584 8585Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X")))))8586 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X")))))8587 and U (matcher = typedefDecl(hasType(asString("int")))8588 and friend class X (matcher = friendDecl(hasType("X"))8589 and public virtual X (matcher = cxxBaseSpecifier(hasType(8590 asString("class X")))8591 class X {};8592 void y(X &x) { x; X z; }8593 typedef int U;8594 class Y { friend class X; };8595 class Z : public virtual X {};8596</pre></td></tr>8597 8598 8599<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>></td><td class="name" onclick="toggle('ignoringElidableConstructorCall0')"><a name="ignoringElidableConstructorCall0Anchor">ignoringElidableConstructorCall</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>8600<tr><td colspan="4" class="doc" id="ignoringElidableConstructorCall0"><pre>Matches expressions that match InnerMatcher that are possibly wrapped in an8601elidable constructor and other corresponding bookkeeping nodes.8602 8603In C++17, elidable copy constructors are no longer being generated in the8604AST as it is not permitted by the standard. They are, however, part of the8605AST in C++14 and earlier. So, a matcher must abstract over these differences8606to work in all language modes. This matcher skips elidable constructor-call8607AST nodes, `ExprWithCleanups` nodes wrapping elidable constructor-calls and8608various implicit nodes inside the constructor calls, all of which will not8609appear in the C++17 AST.8610 8611Given8612 8613struct H {};8614H G();8615void f() {8616 H D = G();8617}8618 8619``varDecl(hasInitializer(ignoringElidableConstructorCall(callExpr())))``8620matches ``H D = G()`` in C++11 through C++17 (and beyond).8621</pre></td></tr>8622 8623 8624<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>></td><td class="name" onclick="toggle('ignoringImpCasts0')"><a name="ignoringImpCasts0Anchor">ignoringImpCasts</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>8625<tr><td colspan="4" class="doc" id="ignoringImpCasts0"><pre>Matches expressions that match InnerMatcher after any implicit casts8626are stripped off.8627 8628Parentheses and explicit casts are not discarded.8629Given8630 int arr[5];8631 int a = 0;8632 char b = 0;8633 const int c = a;8634 int *d = arr;8635 long e = (long) 0l;8636The matchers8637 varDecl(hasInitializer(ignoringImpCasts(integerLiteral())))8638 varDecl(hasInitializer(ignoringImpCasts(declRefExpr())))8639would match the declarations for a, b, c, and d, but not e.8640While8641 varDecl(hasInitializer(integerLiteral()))8642 varDecl(hasInitializer(declRefExpr()))8643only match the declarations for a.8644</pre></td></tr>8645 8646 8647<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>></td><td class="name" onclick="toggle('ignoringImplicit0')"><a name="ignoringImplicit0Anchor">ignoringImplicit</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>8648<tr><td colspan="4" class="doc" id="ignoringImplicit0"><pre>Matches expressions that match InnerMatcher after any implicit AST8649nodes are stripped off.8650 8651Parentheses and explicit casts are not discarded.8652Given8653 class C {};8654 C a = C();8655 C b;8656 C c = b;8657The matchers8658 varDecl(hasInitializer(ignoringImplicit(cxxConstructExpr())))8659would match the declarations for a, b, and c.8660While8661 varDecl(hasInitializer(cxxConstructExpr()))8662only match the declarations for b and c.8663</pre></td></tr>8664 8665 8666<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>></td><td class="name" onclick="toggle('ignoringParenCasts0')"><a name="ignoringParenCasts0Anchor">ignoringParenCasts</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>8667<tr><td colspan="4" class="doc" id="ignoringParenCasts0"><pre>Matches expressions that match InnerMatcher after parentheses and8668casts are stripped off.8669 8670Implicit and non-C Style casts are also discarded.8671Given8672 int a = 0;8673 char b = (0);8674 void* c = reinterpret_cast<char*>(0);8675 char d = char(0);8676The matcher8677 varDecl(hasInitializer(ignoringParenCasts(integerLiteral())))8678would match the declarations for a, b, c, and d.8679while8680 varDecl(hasInitializer(integerLiteral()))8681only match the declaration for a.8682</pre></td></tr>8683 8684 8685<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>></td><td class="name" onclick="toggle('ignoringParenImpCasts0')"><a name="ignoringParenImpCasts0Anchor">ignoringParenImpCasts</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>8686<tr><td colspan="4" class="doc" id="ignoringParenImpCasts0"><pre>Matches expressions that match InnerMatcher after implicit casts and8687parentheses are stripped off.8688 8689Explicit casts are not discarded.8690Given8691 int arr[5];8692 int a = 0;8693 char b = (0);8694 const int c = a;8695 int *d = (arr);8696 long e = ((long) 0l);8697The matchers8698 varDecl(hasInitializer(ignoringParenImpCasts(integerLiteral())))8699 varDecl(hasInitializer(ignoringParenImpCasts(declRefExpr())))8700would match the declarations for a, b, c, and d, but not e.8701while8702 varDecl(hasInitializer(integerLiteral()))8703 varDecl(hasInitializer(declRefExpr()))8704would only match the declaration for a.8705</pre></td></tr>8706 8707 8708<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>></td><td class="name" onclick="toggle('ignoringParens1')"><a name="ignoringParens1Anchor">ignoringParens</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>8709<tr><td colspan="4" class="doc" id="ignoringParens1"><pre>Overload ignoringParens for Expr.8710 8711Given8712 const char* str = ("my-string");8713The matcher8714 implicitCastExpr(hasSourceExpression(ignoringParens(stringLiteral())))8715would match the implicit cast resulting from the assignment.8716</pre></td></tr>8717 8718 8719<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html">FieldDecl</a>></td><td class="name" onclick="toggle('hasInClassInitializer0')"><a name="hasInClassInitializer0Anchor">hasInClassInitializer</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>8720<tr><td colspan="4" class="doc" id="hasInClassInitializer0"><pre>Matches non-static data members that have an in-class initializer.8721 8722Given8723 class C {8724 int a = 2;8725 int b = 3;8726 int c;8727 };8728fieldDecl(hasInClassInitializer(integerLiteral(equals(2))))8729 matches 'int a;' but not 'int b;'.8730fieldDecl(hasInClassInitializer(anything()))8731 matches 'int a;' and 'int b;' but not 'int c;'.8732</pre></td></tr>8733 8734 8735<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ForStmt.html">ForStmt</a>></td><td class="name" onclick="toggle('hasBody1')"><a name="hasBody1Anchor">hasBody</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr>8736<tr><td colspan="4" class="doc" id="hasBody1"><pre>Matches a 'for', 'while', 'while' statement or a function or coroutine8737definition that has a given body. Note that in case of functions or8738coroutines this matcher only matches the definition itself and not the8739other declarations of the same function or coroutine.8740 8741Given8742 for (;;) {}8743forStmt(hasBody(compoundStmt()))8744 matches 'for (;;) {}'8745with compoundStmt()8746 matching '{}'8747 8748Given8749 void f();8750 void f() {}8751functionDecl(hasBody(compoundStmt()))8752 matches 'void f() {}'8753with compoundStmt()8754 matching '{}'8755 but does not match 'void f();'8756</pre></td></tr>8757 8758 8759<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ForStmt.html">ForStmt</a>></td><td class="name" onclick="toggle('hasCondition1')"><a name="hasCondition1Anchor">hasCondition</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>8760<tr><td colspan="4" class="doc" id="hasCondition1"><pre>Matches the condition expression of an if statement, for loop, while loop,8761do-while loop, switch statement or conditional operator.8762 8763Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true))))8764 if (true) {}8765</pre></td></tr>8766 8767 8768<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ForStmt.html">ForStmt</a>></td><td class="name" onclick="toggle('hasConditionVariableStatement1')"><a name="hasConditionVariableStatement1Anchor">hasConditionVariableStatement</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html">DeclStmt</a>> InnerMatcher</td></tr>8769<tr><td colspan="4" class="doc" id="hasConditionVariableStatement1"><pre>Matches the condition variable statement in an if statement, for loop,8770while loop or switch statement.8771 8772Given8773 if (A* a = GetAPointer()) {}8774 for (; A* a = GetAPointer(); ) {}8775hasConditionVariableStatement(...)8776 matches both 'A* a = GetAPointer()'.8777</pre></td></tr>8778 8779 8780<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ForStmt.html">ForStmt</a>></td><td class="name" onclick="toggle('hasIncrement0')"><a name="hasIncrement0Anchor">hasIncrement</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr>8781<tr><td colspan="4" class="doc" id="hasIncrement0"><pre>Matches the increment statement of a for loop.8782 8783Example:8784 forStmt(hasIncrement(unaryOperator(hasOperatorName("++"))))8785matches '++x' in8786 for (x; x < N; ++x) { }8787</pre></td></tr>8788 8789 8790<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ForStmt.html">ForStmt</a>></td><td class="name" onclick="toggle('hasLoopInit0')"><a name="hasLoopInit0Anchor">hasLoopInit</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr>8791<tr><td colspan="4" class="doc" id="hasLoopInit0"><pre>Matches the initialization statement of a for loop.8792 8793Example:8794 forStmt(hasLoopInit(declStmt()))8795matches 'int x = 0' in8796 for (int x = 0; x < N; ++x) { }8797</pre></td></tr>8798 8799 8800<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FriendDecl.html">FriendDecl</a>></td><td class="name" onclick="toggle('hasType6')"><a name="hasType6Anchor">hasType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>8801<tr><td colspan="4" class="doc" id="hasType6"><pre>Overloaded to match the declaration of the expression's or value8802declaration's type.8803 8804In case of a value declaration (for example a variable declaration),8805this resolves one layer of indirection. For example, in the value8806declaration "X x;", cxxRecordDecl(hasName("X")) matches the declaration of8807X, while varDecl(hasType(cxxRecordDecl(hasName("X")))) matches the8808declaration of x.8809 8810Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X")))))8811 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X")))))8812 and friend class X (matcher = friendDecl(hasType("X"))8813 and public virtual X (matcher = cxxBaseSpecifier(hasType(8814 cxxRecordDecl(hasName("X"))))8815 class X {};8816 void y(X &x) { x; X z; }8817 class Y { friend class X; };8818 class Z : public virtual X {};8819 8820Example matches class Derived8821(matcher = cxxRecordDecl(hasAnyBase(hasType(cxxRecordDecl(hasName("Base"))))))8822class Base {};8823class Derived : Base {};8824 8825Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FriendDecl.html">FriendDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</a>>,8826Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>>8827</pre></td></tr>8828 8829 8830<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FriendDecl.html">FriendDecl</a>></td><td class="name" onclick="toggle('hasType1')"><a name="hasType1Anchor">hasType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr>8831<tr><td colspan="4" class="doc" id="hasType1"><pre>Matches if the expression's or declaration's type matches a type8832matcher.8833 8834Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X")))))8835 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X")))))8836 and U (matcher = typedefDecl(hasType(asString("int")))8837 and friend class X (matcher = friendDecl(hasType("X"))8838 and public virtual X (matcher = cxxBaseSpecifier(hasType(8839 asString("class X")))8840 class X {};8841 void y(X &x) { x; X z; }8842 typedef int U;8843 class Y { friend class X; };8844 class Z : public virtual X {};8845</pre></td></tr>8846 8847 8848<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('forEachTemplateArgument2')"><a name="forEachTemplateArgument2Anchor">forEachTemplateArgument</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr>8849<tr><td colspan="4" class="doc" id="forEachTemplateArgument2"><pre>Matches templateSpecializationType, class template specialization,8850variable template specialization, and function template specialization8851nodes where the template argument matches the inner matcher. This matcher8852may produce multiple matches.8853 8854Given8855 template <typename T, unsigned N, unsigned M>8856 struct Matrix {};8857 8858 constexpr unsigned R = 2;8859 Matrix<int, R * 2, R * 4> M;8860 8861 template <typename T, typename U>8862 void f(T&& t, U&& u) {}8863 8864 bool B = false;8865 f(R, B);8866templateSpecializationType(forEachTemplateArgument(isExpr(expr())))8867 matches twice, with expr() matching 'R * 2' and 'R * 4'8868functionDecl(forEachTemplateArgument(refersToType(builtinType())))8869 matches the specialization f<unsigned, bool> twice, for 'unsigned'8870 and 'bool'8871</pre></td></tr>8872 8873 8874<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('hasAnyBody0')"><a name="hasAnyBody0Anchor">hasAnyBody</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr>8875<tr><td colspan="4" class="doc" id="hasAnyBody0"><pre>Matches a function declaration that has a given body present in the AST.8876Note that this matcher matches all the declarations of a function whose8877body is present in the AST.8878 8879Given8880 void f();8881 void f() {}8882 void g();8883functionDecl(hasAnyBody(compoundStmt()))8884 matches both 'void f();'8885 and 'void f() {}'8886with compoundStmt()8887 matching '{}'8888 but does not match 'void g();'8889</pre></td></tr>8890 8891 8892<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('hasAnyParameter0')"><a name="hasAnyParameter0Anchor">hasAnyParameter</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html">ParmVarDecl</a>> InnerMatcher</td></tr>8893<tr><td colspan="4" class="doc" id="hasAnyParameter0"><pre>Matches any parameter of a function or an ObjC method declaration or a8894block.8895 8896Does not match the 'this' parameter of a method.8897 8898Given8899 class X { void f(int x, int y, int z) {} };8900cxxMethodDecl(hasAnyParameter(hasName("y")))8901 matches f(int x, int y, int z) {}8902with hasAnyParameter(...)8903 matching int y8904 8905For ObjectiveC, given8906 @interface I - (void) f:(int) y; @end8907 8908the matcher objcMethodDecl(hasAnyParameter(hasName("y")))8909matches the declaration of method f with hasParameter8910matching y.8911 8912For blocks, given8913 b = ^(int y) { printf("%d", y) };8914 8915the matcher blockDecl(hasAnyParameter(hasName("y")))8916matches the declaration of the block b with hasParameter8917matching y.8918</pre></td></tr>8919 8920 8921<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('hasAnyTemplateArgumentLoc2')"><a name="hasAnyTemplateArgumentLoc2Anchor">hasAnyTemplateArgumentLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgumentLoc.html">TemplateArgumentLoc</a>> InnerMatcher</td></tr>8922<tr><td colspan="4" class="doc" id="hasAnyTemplateArgumentLoc2"><pre>Matches template specialization `TypeLoc`s, class template specializations,8923variable template specializations, and function template specializations8924that have at least one `TemplateArgumentLoc` matching the given8925`InnerMatcher`.8926 8927Given8928 template<typename T> class A {};8929 A<int> a;8930varDecl(hasTypeLoc(templateSpecializationTypeLoc(hasAnyTemplateArgumentLoc(8931 hasTypeLoc(loc(asString("int")))))))8932 matches `A<int> a`.8933</pre></td></tr>8934 8935 8936<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('hasAnyTemplateArgument2')"><a name="hasAnyTemplateArgument2Anchor">hasAnyTemplateArgument</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr>8937<tr><td colspan="4" class="doc" id="hasAnyTemplateArgument2"><pre>Matches templateSpecializationTypes, class template specializations,8938variable template specializations, and function template specializations8939that have at least one TemplateArgument matching the given InnerMatcher.8940 8941Given8942 template<typename T> class A {};8943 template<> class A<double> {};8944 A<int> a;8945 8946 template<typename T> f() {};8947 void func() { f<int>(); };8948 8949classTemplateSpecializationDecl(hasAnyTemplateArgument(8950 refersToType(asString("int"))))8951 matches the specialization A<int>8952 8953functionDecl(hasAnyTemplateArgument(refersToType(asString("int"))))8954 matches the specialization f<int>8955</pre></td></tr>8956 8957 8958<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('hasBody4')"><a name="hasBody4Anchor">hasBody</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr>8959<tr><td colspan="4" class="doc" id="hasBody4"><pre>Matches a 'for', 'while', 'while' statement or a function or coroutine8960definition that has a given body. Note that in case of functions or8961coroutines this matcher only matches the definition itself and not the8962other declarations of the same function or coroutine.8963 8964Given8965 for (;;) {}8966forStmt(hasBody(compoundStmt()))8967 matches 'for (;;) {}'8968with compoundStmt()8969 matching '{}'8970 8971Given8972 void f();8973 void f() {}8974functionDecl(hasBody(compoundStmt()))8975 matches 'void f() {}'8976with compoundStmt()8977 matching '{}'8978 but does not match 'void f();'8979</pre></td></tr>8980 8981 8982<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('hasExplicitSpecifier0')"><a name="hasExplicitSpecifier0Anchor">hasExplicitSpecifier</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>8983<tr><td colspan="4" class="doc" id="hasExplicitSpecifier0"><pre>Matches the expression in an explicit specifier if present in the given8984declaration.8985 8986Given8987 template<bool b>8988 struct S {8989 S(int); // #18990 explicit S(double); // #28991 operator int(); // #38992 explicit operator bool(); // #48993 explicit(false) S(bool) // # 78994 explicit(true) S(char) // # 88995 explicit(b) S(S) // # 98996 };8997 S(int) -> S<true> // #58998 explicit S(double) -> S<false> // #68999cxxConstructorDecl(hasExplicitSpecifier(constantExpr())) will match #7, #8 and #9, but not #1 or #2.9000cxxConversionDecl(hasExplicitSpecifier(constantExpr())) will not match #3 or #4.9001cxxDeductionGuideDecl(hasExplicitSpecifier(constantExpr())) will not match #5 or #6.9002</pre></td></tr>9003 9004 9005<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('hasParameter0')"><a name="hasParameter0Anchor">hasParameter</a></td><td>unsigned N, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html">ParmVarDecl</a>> InnerMatcher</td></tr>9006<tr><td colspan="4" class="doc" id="hasParameter0"><pre>Matches the n'th parameter of a function or an ObjC method9007declaration or a block.9008 9009Given9010 class X { void f(int x) {} };9011cxxMethodDecl(hasParameter(0, hasType(varDecl())))9012 matches f(int x) {}9013with hasParameter(...)9014 matching int x9015 9016For ObjectiveC, given9017 @interface I - (void) f:(int) y; @end9018 9019the matcher objcMethodDecl(hasParameter(0, hasName("y")))9020matches the declaration of method f with hasParameter9021matching y.9022</pre></td></tr>9023 9024 9025<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('hasReturnTypeLoc0')"><a name="hasReturnTypeLoc0Anchor">hasReturnTypeLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> ReturnMatcher</td></tr>9026<tr><td colspan="4" class="doc" id="hasReturnTypeLoc0"><pre>Matches a function declared with the specified return `TypeLoc`.9027 9028Given9029 int f() { return 5; }9030 void g() {}9031functionDecl(hasReturnTypeLoc(loc(asString("int"))))9032 matches the declaration of `f`, but not `g`.9033</pre></td></tr>9034 9035 9036<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('hasTemplateArgumentLoc2')"><a name="hasTemplateArgumentLoc2Anchor">hasTemplateArgumentLoc</a></td><td>unsigned Index, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgumentLoc.html">TemplateArgumentLoc</a>> InnerMatcher</td></tr>9037<tr><td colspan="4" class="doc" id="hasTemplateArgumentLoc2"><pre>Matches template specialization `TypeLoc`s, class template specializations,9038variable template specializations, and function template specializations9039where the n'th `TemplateArgumentLoc` matches the given `InnerMatcher`.9040 9041Given9042 template<typename T, typename U> class A {};9043 A<double, int> b;9044 A<int, double> c;9045varDecl(hasTypeLoc(templateSpecializationTypeLoc(hasTemplateArgumentLoc(0,9046 hasTypeLoc(loc(asString("double")))))))9047 matches `A<double, int> b`, but not `A<int, double> c`.9048</pre></td></tr>9049 9050 9051<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('hasTemplateArgument2')"><a name="hasTemplateArgument2Anchor">hasTemplateArgument</a></td><td>unsigned N, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr>9052<tr><td colspan="4" class="doc" id="hasTemplateArgument2"><pre>Matches templateSpecializationType, class template specializations,9053variable template specializations, and function template specializations9054where the n'th TemplateArgument matches the given InnerMatcher.9055 9056Given9057 template<typename T, typename U> class A {};9058 A<bool, int> b;9059 A<int, bool> c;9060 9061 template<typename T> void f() {}9062 void func() { f<int>(); };9063classTemplateSpecializationDecl(hasTemplateArgument(9064 1, refersToType(asString("int"))))9065 matches the specialization A<bool, int>9066 9067functionDecl(hasTemplateArgument(0, refersToType(asString("int"))))9068 matches the specialization f<int>9069</pre></td></tr>9070 9071 9072<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('returns0')"><a name="returns0Anchor">returns</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr>9073<tr><td colspan="4" class="doc" id="returns0"><pre>Matches the return type of a function declaration.9074 9075Given:9076 class X { int f() { return 1; } };9077cxxMethodDecl(returns(asString("int")))9078 matches int f() { return 1; }9079</pre></td></tr>9080 9081 9082<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IfStmt.html">IfStmt</a>></td><td class="name" onclick="toggle('hasCondition0')"><a name="hasCondition0Anchor">hasCondition</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>9083<tr><td colspan="4" class="doc" id="hasCondition0"><pre>Matches the condition expression of an if statement, for loop, while loop,9084do-while loop, switch statement or conditional operator.9085 9086Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true))))9087 if (true) {}9088</pre></td></tr>9089 9090 9091<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IfStmt.html">IfStmt</a>></td><td class="name" onclick="toggle('hasConditionVariableStatement0')"><a name="hasConditionVariableStatement0Anchor">hasConditionVariableStatement</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html">DeclStmt</a>> InnerMatcher</td></tr>9092<tr><td colspan="4" class="doc" id="hasConditionVariableStatement0"><pre>Matches the condition variable statement in an if statement, for loop,9093while loop or switch statement.9094 9095Given9096 if (A* a = GetAPointer()) {}9097 for (; A* a = GetAPointer(); ) {}9098hasConditionVariableStatement(...)9099 matches both 'A* a = GetAPointer()'.9100</pre></td></tr>9101 9102 9103<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IfStmt.html">IfStmt</a>></td><td class="name" onclick="toggle('hasElse0')"><a name="hasElse0Anchor">hasElse</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr>9104<tr><td colspan="4" class="doc" id="hasElse0"><pre>Matches the else-statement of an if statement.9105 9106Examples matches the if statement9107 (matcher = ifStmt(hasElse(cxxBoolLiteral(equals(true)))))9108 if (false) false; else true;9109</pre></td></tr>9110 9111 9112<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IfStmt.html">IfStmt</a>></td><td class="name" onclick="toggle('hasInitStatement0')"><a name="hasInitStatement0Anchor">hasInitStatement</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr>9113<tr><td colspan="4" class="doc" id="hasInitStatement0"><pre>Matches selection statements with initializer.9114 9115Given:9116 void foo() {9117 if (int i = foobar(); i > 0) {}9118 switch (int i = foobar(); i) {}9119 for (auto& a = get_range(); auto& x : a) {}9120 }9121 void bar() {9122 if (foobar() > 0) {}9123 switch (foobar()) {}9124 for (auto& x : get_range()) {}9125 }9126ifStmt(hasInitStatement(anything()))9127 matches the if statement in foo but not in bar.9128switchStmt(hasInitStatement(anything()))9129 matches the switch statement in foo but not in bar.9130cxxForRangeStmt(hasInitStatement(anything()))9131 matches the range for statement in foo but not in bar.9132</pre></td></tr>9133 9134 9135<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IfStmt.html">IfStmt</a>></td><td class="name" onclick="toggle('hasThen0')"><a name="hasThen0Anchor">hasThen</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr>9136<tr><td colspan="4" class="doc" id="hasThen0"><pre>Matches the then-statement of an if statement.9137 9138Examples matches the if statement9139 (matcher = ifStmt(hasThen(cxxBoolLiteral(equals(true)))))9140 if (false) true; else false;9141</pre></td></tr>9142 9143 9144<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ImplicitCastExpr.html">ImplicitCastExpr</a>></td><td class="name" onclick="toggle('hasImplicitDestinationType0')"><a name="hasImplicitDestinationType0Anchor">hasImplicitDestinationType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr>9145<tr><td colspan="4" class="doc" id="hasImplicitDestinationType0"><pre>Matches implicit casts whose destination type matches a given9146matcher.9147</pre></td></tr>9148 9149 9150<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1InitListExpr.html">InitListExpr</a>></td><td class="name" onclick="toggle('hasInit0')"><a name="hasInit0Anchor">hasInit</a></td><td>unsigned N, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>9151<tr><td colspan="4" class="doc" id="hasInit0"><pre>Matches the n'th item of an initializer list expression.9152 9153Example matches y.9154 (matcher = initListExpr(hasInit(0, expr())))9155 int x{y}.9156</pre></td></tr>9157 9158 9159<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1InitListExpr.html">InitListExpr</a>></td><td class="name" onclick="toggle('hasSyntacticForm0')"><a name="hasSyntacticForm0Anchor">hasSyntacticForm</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>9160<tr><td colspan="4" class="doc" id="hasSyntacticForm0"><pre>Matches the syntactic form of init list expressions9161(if expression have it).9162</pre></td></tr>9163 9164 9165<tr><td>Matcher<InjectedClassNameType></td><td class="name" onclick="toggle('hasDeclaration10')"><a name="hasDeclaration10Anchor">hasDeclaration</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>9166<tr><td colspan="4" class="doc" id="hasDeclaration10"><pre>Matches a node if the declaration associated with that node9167matches the given matcher.9168 9169The associated declaration is:9170- for type nodes, the declaration of the underlying type9171- for CallExpr, the declaration of the callee9172- for MemberExpr, the declaration of the referenced member9173- for CXXConstructExpr, the declaration of the constructor9174- for CXXNewExpr, the declaration of the operator new9175- for ObjCIvarExpr, the declaration of the ivar9176 9177For type nodes, hasDeclaration will generally match the declaration of the9178sugared type. Given9179 class X {};9180 typedef X Y;9181 Y y;9182in varDecl(hasType(hasDeclaration(decl()))) the decl will match the9183typedefDecl. A common use case is to match the underlying, desugared type.9184This can be achieved by using the hasUnqualifiedDesugaredType matcher:9185 varDecl(hasType(hasUnqualifiedDesugaredType(9186 recordType(hasDeclaration(decl())))))9187In this matcher, the decl will match the CXXRecordDecl of class X.9188 9189Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>,9190 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>,9191 Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>,9192 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<RecordType>,9193 Matcher<TagType>, Matcher<TemplateSpecializationType>,9194 Matcher<TemplateTypeParmType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>,9195 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingType.html">UsingType</a>>9196</pre></td></tr>9197 9198 9199<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>></td><td class="name" onclick="toggle('hasDeclaration9')"><a name="hasDeclaration9Anchor">hasDeclaration</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>9200<tr><td colspan="4" class="doc" id="hasDeclaration9"><pre>Matches a node if the declaration associated with that node9201matches the given matcher.9202 9203The associated declaration is:9204- for type nodes, the declaration of the underlying type9205- for CallExpr, the declaration of the callee9206- for MemberExpr, the declaration of the referenced member9207- for CXXConstructExpr, the declaration of the constructor9208- for CXXNewExpr, the declaration of the operator new9209- for ObjCIvarExpr, the declaration of the ivar9210 9211For type nodes, hasDeclaration will generally match the declaration of the9212sugared type. Given9213 class X {};9214 typedef X Y;9215 Y y;9216in varDecl(hasType(hasDeclaration(decl()))) the decl will match the9217typedefDecl. A common use case is to match the underlying, desugared type.9218This can be achieved by using the hasUnqualifiedDesugaredType matcher:9219 varDecl(hasType(hasUnqualifiedDesugaredType(9220 recordType(hasDeclaration(decl())))))9221In this matcher, the decl will match the CXXRecordDecl of class X.9222 9223Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>,9224 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>,9225 Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>,9226 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<RecordType>,9227 Matcher<TagType>, Matcher<TemplateSpecializationType>,9228 Matcher<TemplateTypeParmType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>,9229 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingType.html">UsingType</a>>9230</pre></td></tr>9231 9232 9233<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LambdaCapture.html">LambdaCapture</a>></td><td class="name" onclick="toggle('capturesVar0')"><a name="capturesVar0Anchor">capturesVar</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</a>> InnerMatcher</td></tr>9234<tr><td colspan="4" class="doc" id="capturesVar0"><pre>Matches a `LambdaCapture` that refers to the specified `VarDecl`. The9235`VarDecl` can be a separate variable that is captured by value or9236reference, or a synthesized variable if the capture has an initializer.9237 9238Given9239 void foo() {9240 int x;9241 auto f = [x](){};9242 auto g = [x = 1](){};9243 }9244In the matcher9245lambdaExpr(hasAnyCapture(lambdaCapture(capturesVar(hasName("x")))),9246capturesVar(hasName("x")) matches `x` and `x = 1`.9247</pre></td></tr>9248 9249 9250<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LambdaExpr.html">LambdaExpr</a>></td><td class="name" onclick="toggle('forEachLambdaCapture0')"><a name="forEachLambdaCapture0Anchor">forEachLambdaCapture</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LambdaCapture.html">LambdaCapture</a>> InnerMatcher</td></tr>9251<tr><td colspan="4" class="doc" id="forEachLambdaCapture0"><pre>Matches each lambda capture in a lambda expression.9252 9253Given9254 int main() {9255 int x, y;9256 float z;9257 auto f = [=]() { return x + y + z; };9258 }9259lambdaExpr(forEachLambdaCapture(9260 lambdaCapture(capturesVar(varDecl(hasType(isInteger()))))))9261will trigger two matches, binding for 'x' and 'y' respectively.9262</pre></td></tr>9263 9264 9265<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LambdaExpr.html">LambdaExpr</a>></td><td class="name" onclick="toggle('hasAnyCapture0')"><a name="hasAnyCapture0Anchor">hasAnyCapture</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LambdaCapture.html">LambdaCapture</a>> InnerMatcher</td></tr>9266<tr><td colspan="4" class="doc" id="hasAnyCapture0"><pre>Matches any capture in a lambda expression.9267 9268Given9269 void foo() {9270 int t = 5;9271 auto f = [=](){ return t; };9272 }9273lambdaExpr(hasAnyCapture(lambdaCapture())) and9274lambdaExpr(hasAnyCapture(lambdaCapture(refersToVarDecl(hasName("t")))))9275 both match `[=](){ return t; }`.9276</pre></td></tr>9277 9278 9279<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>></td><td class="name" onclick="toggle('hasDeclaration8')"><a name="hasDeclaration8Anchor">hasDeclaration</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>9280<tr><td colspan="4" class="doc" id="hasDeclaration8"><pre>Matches a node if the declaration associated with that node9281matches the given matcher.9282 9283The associated declaration is:9284- for type nodes, the declaration of the underlying type9285- for CallExpr, the declaration of the callee9286- for MemberExpr, the declaration of the referenced member9287- for CXXConstructExpr, the declaration of the constructor9288- for CXXNewExpr, the declaration of the operator new9289- for ObjCIvarExpr, the declaration of the ivar9290 9291For type nodes, hasDeclaration will generally match the declaration of the9292sugared type. Given9293 class X {};9294 typedef X Y;9295 Y y;9296in varDecl(hasType(hasDeclaration(decl()))) the decl will match the9297typedefDecl. A common use case is to match the underlying, desugared type.9298This can be achieved by using the hasUnqualifiedDesugaredType matcher:9299 varDecl(hasType(hasUnqualifiedDesugaredType(9300 recordType(hasDeclaration(decl())))))9301In this matcher, the decl will match the CXXRecordDecl of class X.9302 9303Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>,9304 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>,9305 Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>,9306 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<RecordType>,9307 Matcher<TagType>, Matcher<TemplateSpecializationType>,9308 Matcher<TemplateTypeParmType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>,9309 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingType.html">UsingType</a>>9310</pre></td></tr>9311 9312 9313<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>></td><td class="name" onclick="toggle('hasObjectExpression0')"><a name="hasObjectExpression0Anchor">hasObjectExpression</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>9314<tr><td colspan="4" class="doc" id="hasObjectExpression0"><pre>Matches a member expression where the object expression is matched by a9315given matcher. Implicit object expressions are included; that is, it matches9316use of implicit `this`.9317 9318Given9319 struct X {9320 int m;9321 int f(X x) { x.m; return m; }9322 };9323memberExpr(hasObjectExpression(hasType(cxxRecordDecl(hasName("X")))))9324 matches `x.m`, but not `m`; however,9325memberExpr(hasObjectExpression(hasType(pointsTo(9326 cxxRecordDecl(hasName("X"))))))9327 matches `m` (aka. `this->m`), but not `x.m`.9328</pre></td></tr>9329 9330 9331<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>></td><td class="name" onclick="toggle('member0')"><a name="member0Anchor">member</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</a>> InnerMatcher</td></tr>9332<tr><td colspan="4" class="doc" id="member0"><pre>Matches a member expression where the member is matched by a9333given matcher.9334 9335Given9336 struct { int first, second; } first, second;9337 int i(second.first);9338 int j(first.second);9339memberExpr(member(hasName("first")))9340 matches second.first9341 but not first.second (because the member name there is "second").9342</pre></td></tr>9343 9344 9345<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberPointerType.html">MemberPointerType</a>></td><td class="name" onclick="toggle('pointee1')"><a name="pointee1Anchor">pointee</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr>9346<tr><td colspan="4" class="doc" id="pointee1"><pre>Narrows PointerType (and similar) matchers to those where the9347pointee matches a given matcher.9348 9349Given9350 int *a;9351 int const *b;9352 float const *f;9353pointerType(pointee(isConstQualified(), isInteger()))9354 matches "int const *b"9355 9356Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockPointerType.html">BlockPointerType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberPointerType.html">MemberPointerType</a>>,9357 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1PointerType.html">PointerType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ReferenceType.html">ReferenceType</a>>,9358 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCObjectPointerType.html">ObjCObjectPointerType</a>>9359</pre></td></tr>9360 9361 9362<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>></td><td class="name" onclick="toggle('hasUnderlyingDecl0')"><a name="hasUnderlyingDecl0Anchor">hasUnderlyingDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>> InnerMatcher</td></tr>9363<tr><td colspan="4" class="doc" id="hasUnderlyingDecl0"><pre>Matches a NamedDecl whose underlying declaration matches the given9364matcher.9365 9366Given9367 namespace N { template<class T> void f(T t); }9368 template <class T> void g() { using N::f; f(T()); }9369unresolvedLookupExpr(hasAnyDeclaration(9370 namedDecl(hasUnderlyingDecl(hasName("::N::f")))))9371 matches the use of f in g() .9372</pre></td></tr>9373 9374 9375<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifierLoc.html">NestedNameSpecifierLoc</a>></td><td class="name" onclick="toggle('hasPrefix1')"><a name="hasPrefix1Anchor">hasPrefix</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifierLoc.html">NestedNameSpecifierLoc</a>> InnerMatcher</td></tr>9376<tr><td colspan="4" class="doc" id="hasPrefix1"><pre>Matches on the prefix of a NestedNameSpecifierLoc.9377 9378Given9379 struct A { struct B { struct C {}; }; };9380 A::B::C c;9381nestedNameSpecifierLoc(hasPrefix(loc(specifiesType(asString("struct A")))))9382 matches "A::"9383</pre></td></tr>9384 9385 9386<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifierLoc.html">NestedNameSpecifierLoc</a>></td><td class="name" onclick="toggle('loc1')"><a name="loc1Anchor">loc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifier.html">NestedNameSpecifier</a>> InnerMatcher</td></tr>9387<tr><td colspan="4" class="doc" id="loc1"><pre>Matches NestedNameSpecifierLocs for which the given inner9388NestedNameSpecifier-matcher matches.9389</pre></td></tr>9390 9391 9392<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifierLoc.html">NestedNameSpecifierLoc</a>></td><td class="name" onclick="toggle('specifiesTypeLoc0')"><a name="specifiesTypeLoc0Anchor">specifiesTypeLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> InnerMatcher</td></tr>9393<tr><td colspan="4" class="doc" id="specifiesTypeLoc0"><pre>Matches nested name specifier locs that specify a type matching the9394given TypeLoc.9395 9396Given9397 struct A { struct B { struct C {}; }; };9398 A::B::C c;9399nestedNameSpecifierLoc(specifiesTypeLoc(loc(type(9400 hasDeclaration(cxxRecordDecl(hasName("A")))))))9401 matches "A::"9402</pre></td></tr>9403 9404 9405<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifier.html">NestedNameSpecifier</a>></td><td class="name" onclick="toggle('hasPrefix0')"><a name="hasPrefix0Anchor">hasPrefix</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifier.html">NestedNameSpecifier</a>> InnerMatcher</td></tr>9406<tr><td colspan="4" class="doc" id="hasPrefix0"><pre>Matches on the prefix of a NestedNameSpecifier.9407 9408Given9409 struct A { struct B { struct C {}; }; };9410 A::B::C c;9411nestedNameSpecifier(hasPrefix(specifiesType(asString("struct A")))) and9412 matches "A::"9413</pre></td></tr>9414 9415 9416<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifier.html">NestedNameSpecifier</a>></td><td class="name" onclick="toggle('specifiesNamespace0')"><a name="specifiesNamespace0Anchor">specifiesNamespace</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamespaceDecl.html">NamespaceDecl</a>> InnerMatcher</td></tr>9417<tr><td colspan="4" class="doc" id="specifiesNamespace0"><pre>Matches nested name specifiers that specify a namespace matching the9418given namespace matcher.9419 9420Given9421 namespace ns { struct A {}; }9422 ns::A a;9423nestedNameSpecifier(specifiesNamespace(hasName("ns")))9424 matches "ns::"9425</pre></td></tr>9426 9427 9428<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifier.html">NestedNameSpecifier</a>></td><td class="name" onclick="toggle('specifiesType0')"><a name="specifiesType0Anchor">specifiesType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr>9429<tr><td colspan="4" class="doc" id="specifiesType0"><pre>Matches nested name specifiers that specify a type matching the9430given QualType matcher without qualifiers.9431 9432Given9433 struct A { struct B { struct C {}; }; };9434 A::B::C c;9435nestedNameSpecifier(specifiesType(9436 hasDeclaration(cxxRecordDecl(hasName("A")))9437))9438 matches "A::"9439</pre></td></tr>9440 9441 9442<tr><td>Matcher<OMPExecutableDirective></td><td class="name" onclick="toggle('hasAnyClause0')"><a name="hasAnyClause0Anchor">hasAnyClause</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPClause.html">OMPClause</a>> InnerMatcher</td></tr>9443<tr><td colspan="4" class="doc" id="hasAnyClause0"><pre>Matches any clause in an OpenMP directive.9444 9445Given9446 9447 #pragma omp parallel9448 #pragma omp parallel default(none)9449 9450``ompExecutableDirective(hasAnyClause(anything()))`` matches9451``omp parallel default(none)``.9452</pre></td></tr>9453 9454 9455<tr><td>Matcher<OMPExecutableDirective></td><td class="name" onclick="toggle('hasStructuredBlock0')"><a name="hasStructuredBlock0Anchor">hasStructuredBlock</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr>9456<tr><td colspan="4" class="doc" id="hasStructuredBlock0"><pre>Matches the structured-block of the OpenMP executable directive9457 9458Prerequisite: the executable directive must not be standalone directive.9459If it is, it will never match.9460 9461Given9462 9463 #pragma omp parallel9464 ;9465 #pragma omp parallel9466 {}9467 9468``ompExecutableDirective(hasStructuredBlock(nullStmt()))`` will match ``;``9469</pre></td></tr>9470 9471 9472<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCInterfaceDecl.html">ObjCInterfaceDecl</a>></td><td class="name" onclick="toggle('hasType9')"><a name="hasType9Anchor">hasType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>9473<tr><td colspan="4" class="doc" id="hasType9"><pre>Overloaded to match the declaration of the expression's or value9474declaration's type.9475 9476In case of a value declaration (for example a variable declaration),9477this resolves one layer of indirection. For example, in the value9478declaration "X x;", cxxRecordDecl(hasName("X")) matches the declaration of9479X, while varDecl(hasType(cxxRecordDecl(hasName("X")))) matches the9480declaration of x.9481 9482Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X")))))9483 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X")))))9484 and friend class X (matcher = friendDecl(hasType("X"))9485 and public virtual X (matcher = cxxBaseSpecifier(hasType(9486 cxxRecordDecl(hasName("X"))))9487 class X {};9488 void y(X &x) { x; X z; }9489 class Y { friend class X; };9490 class Z : public virtual X {};9491 9492Example matches class Derived9493(matcher = cxxRecordDecl(hasAnyBase(hasType(cxxRecordDecl(hasName("Base"))))))9494class Base {};9495class Derived : Base {};9496 9497Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FriendDecl.html">FriendDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</a>>,9498Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>>9499</pre></td></tr>9500 9501 9502<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCInterfaceDecl.html">ObjCInterfaceDecl</a>></td><td class="name" onclick="toggle('isDerivedFrom1')"><a name="isDerivedFrom1Anchor">isDerivedFrom</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>> Base</td></tr>9503<tr><td colspan="4" class="doc" id="isDerivedFrom1"><pre>Matches C++ classes that are directly or indirectly derived from a class9504matching Base, or Objective-C classes that directly or indirectly9505subclass a class matching Base.9506 9507Note that a class is not considered to be derived from itself.9508 9509Example matches Y, Z, C (Base == hasName("X"))9510 class X;9511 class Y : public X {}; // directly derived9512 class Z : public Y {}; // indirectly derived9513 typedef X A;9514 typedef A B;9515 class C : public B {}; // derived from a typedef of X9516 9517In the following example, Bar matches isDerivedFrom(hasName("X")):9518 class Foo;9519 typedef Foo X;9520 class Bar : public Foo {}; // derived from a type that X is a typedef of9521 9522In the following example, Bar matches isDerivedFrom(hasName("NSObject"))9523 @interface NSObject @end9524 @interface Bar : NSObject @end9525 9526Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCInterfaceDecl.html">ObjCInterfaceDecl</a>>9527</pre></td></tr>9528 9529 9530<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCInterfaceDecl.html">ObjCInterfaceDecl</a>></td><td class="name" onclick="toggle('isDirectlyDerivedFrom1')"><a name="isDirectlyDerivedFrom1Anchor">isDirectlyDerivedFrom</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>> Base</td></tr>9531<tr><td colspan="4" class="doc" id="isDirectlyDerivedFrom1"><pre>Matches C++ or Objective-C classes that are directly derived from a class9532matching Base.9533 9534Note that a class is not considered to be derived from itself.9535 9536Example matches Y, C (Base == hasName("X"))9537 class X;9538 class Y : public X {}; // directly derived9539 class Z : public Y {}; // indirectly derived9540 typedef X A;9541 typedef A B;9542 class C : public B {}; // derived from a typedef of X9543 9544In the following example, Bar matches isDerivedFrom(hasName("X")):9545 class Foo;9546 typedef Foo X;9547 class Bar : public Foo {}; // derived from a type that X is a typedef of9548</pre></td></tr>9549 9550 9551<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCInterfaceDecl.html">ObjCInterfaceDecl</a>></td><td class="name" onclick="toggle('isSameOrDerivedFrom1')"><a name="isSameOrDerivedFrom1Anchor">isSameOrDerivedFrom</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>> Base</td></tr>9552<tr><td colspan="4" class="doc" id="isSameOrDerivedFrom1"><pre>Similar to isDerivedFrom(), but also matches classes that directly9553match Base.9554</pre></td></tr>9555 9556 9557<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>></td><td class="name" onclick="toggle('callee2')"><a name="callee2Anchor">callee</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>9558<tr><td colspan="4" class="doc" id="callee2"><pre>Matches 1) if the call expression's callee's declaration matches the9559given matcher; or 2) if the Obj-C message expression's callee's method9560declaration matches the given matcher.9561 9562Example matches y.x() (matcher = callExpr(callee(9563 cxxMethodDecl(hasName("x")))))9564 class Y { public: void x(); };9565 void z() { Y y; y.x(); }9566 9567Example 2. Matches [I foo] with9568objcMessageExpr(callee(objcMethodDecl(hasName("foo"))))9569 9570 @interface I: NSObject9571 +(void)foo;9572 @end9573 ...9574 [I foo]9575</pre></td></tr>9576 9577 9578<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>></td><td class="name" onclick="toggle('hasAnyArgument3')"><a name="hasAnyArgument3Anchor">hasAnyArgument</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>9579<tr><td colspan="4" class="doc" id="hasAnyArgument3"><pre>Matches any argument of a call expression or a constructor call9580expression, or an ObjC-message-send expression.9581 9582Given9583 void x(int, int, int) { int y; x(1, y, 42); }9584callExpr(hasAnyArgument(declRefExpr()))9585 matches x(1, y, 42)9586with hasAnyArgument(...)9587 matching y9588 9589For ObjectiveC, given9590 @interface I - (void) f:(int) y; @end9591 void foo(I *i) { [i f:12]; }9592objcMessageExpr(hasAnyArgument(integerLiteral(equals(12))))9593 matches [i f:12]9594</pre></td></tr>9595 9596 9597<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>></td><td class="name" onclick="toggle('hasArgument3')"><a name="hasArgument3Anchor">hasArgument</a></td><td>unsigned N, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>9598<tr><td colspan="4" class="doc" id="hasArgument3"><pre>Matches the n'th argument of a call expression or a constructor9599call expression.9600 9601Example matches y in x(y)9602 (matcher = callExpr(hasArgument(0, declRefExpr())))9603 void x(int) { int y; x(y); }9604</pre></td></tr>9605 9606 9607<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>></td><td class="name" onclick="toggle('hasReceiver0')"><a name="hasReceiver0Anchor">hasReceiver</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>9608<tr><td colspan="4" class="doc" id="hasReceiver0"><pre>Matches if the Objective-C message is sent to an instance,9609and the inner matcher matches on that instance.9610 9611For example the method call in9612 NSString *x = @"hello";9613 [x containsString:@"h"];9614is matched by9615objcMessageExpr(hasReceiver(declRefExpr(to(varDecl(hasName("x"))))))9616</pre></td></tr>9617 9618 9619<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>></td><td class="name" onclick="toggle('hasReceiverType0')"><a name="hasReceiverType0Anchor">hasReceiverType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr>9620<tr><td colspan="4" class="doc" id="hasReceiverType0"><pre>Matches on the receiver of an ObjectiveC Message expression.9621 9622Example9623matcher = objCMessageExpr(hasReceiverType(asString("UIWebView *")));9624matches the [webView ...] message invocation.9625 NSString *webViewJavaScript = ...9626 UIWebView *webView = ...9627 [webView stringByEvaluatingJavaScriptFromString:webViewJavascript];9628</pre></td></tr>9629 9630 9631<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html">ObjCMethodDecl</a>></td><td class="name" onclick="toggle('hasAnyParameter1')"><a name="hasAnyParameter1Anchor">hasAnyParameter</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html">ParmVarDecl</a>> InnerMatcher</td></tr>9632<tr><td colspan="4" class="doc" id="hasAnyParameter1"><pre>Matches any parameter of a function or an ObjC method declaration or a9633block.9634 9635Does not match the 'this' parameter of a method.9636 9637Given9638 class X { void f(int x, int y, int z) {} };9639cxxMethodDecl(hasAnyParameter(hasName("y")))9640 matches f(int x, int y, int z) {}9641with hasAnyParameter(...)9642 matching int y9643 9644For ObjectiveC, given9645 @interface I - (void) f:(int) y; @end9646 9647the matcher objcMethodDecl(hasAnyParameter(hasName("y")))9648matches the declaration of method f with hasParameter9649matching y.9650 9651For blocks, given9652 b = ^(int y) { printf("%d", y) };9653 9654the matcher blockDecl(hasAnyParameter(hasName("y")))9655matches the declaration of the block b with hasParameter9656matching y.9657</pre></td></tr>9658 9659 9660<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html">ObjCMethodDecl</a>></td><td class="name" onclick="toggle('hasParameter1')"><a name="hasParameter1Anchor">hasParameter</a></td><td>unsigned N, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html">ParmVarDecl</a>> InnerMatcher</td></tr>9661<tr><td colspan="4" class="doc" id="hasParameter1"><pre>Matches the n'th parameter of a function or an ObjC method9662declaration or a block.9663 9664Given9665 class X { void f(int x) {} };9666cxxMethodDecl(hasParameter(0, hasType(varDecl())))9667 matches f(int x) {}9668with hasParameter(...)9669 matching int x9670 9671For ObjectiveC, given9672 @interface I - (void) f:(int) y; @end9673 9674the matcher objcMethodDecl(hasParameter(0, hasName("y")))9675matches the declaration of method f with hasParameter9676matching y.9677</pre></td></tr>9678 9679 9680<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCObjectPointerType.html">ObjCObjectPointerType</a>></td><td class="name" onclick="toggle('pointee4')"><a name="pointee4Anchor">pointee</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr>9681<tr><td colspan="4" class="doc" id="pointee4"><pre>Narrows PointerType (and similar) matchers to those where the9682pointee matches a given matcher.9683 9684Given9685 int *a;9686 int const *b;9687 float const *f;9688pointerType(pointee(isConstQualified(), isInteger()))9689 matches "int const *b"9690 9691Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockPointerType.html">BlockPointerType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberPointerType.html">MemberPointerType</a>>,9692 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1PointerType.html">PointerType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ReferenceType.html">ReferenceType</a>>,9693 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCObjectPointerType.html">ObjCObjectPointerType</a>>9694</pre></td></tr>9695 9696 9697<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCPropertyDecl.html">ObjCPropertyDecl</a>></td><td class="name" onclick="toggle('hasTypeLoc10')"><a name="hasTypeLoc10Anchor">hasTypeLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> Inner</td></tr>9698<tr><td colspan="4" class="doc" id="hasTypeLoc10"><pre>Matches if the type location of a node matches the inner matcher.9699 9700Examples:9701 int x;9702declaratorDecl(hasTypeLoc(loc(asString("int"))))9703 matches int x9704 9705auto x = int(3);9706cxxTemporaryObjectExpr(hasTypeLoc(loc(asString("int"))))9707 matches int(3)9708 9709struct Foo { Foo(int, int); };9710auto x = Foo(1, 2);9711cxxFunctionalCastExpr(hasTypeLoc(loc(asString("struct Foo"))))9712 matches Foo(1, 2)9713 9714Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockDecl.html">BlockDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>>,9715 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFunctionalCastExpr.html">CXXFunctionalCastExpr</a>>,9716 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXTemporaryObjectExpr.html">CXXTemporaryObjectExpr</a>>,9717 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXUnresolvedConstructExpr.html">CXXUnresolvedConstructExpr</a>>,9718 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CompoundLiteralExpr.html">CompoundLiteralExpr</a>>,9719 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclaratorDecl.html">DeclaratorDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ExplicitCastExpr.html">ExplicitCastExpr</a>>,9720 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCPropertyDecl.html">ObjCPropertyDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgumentLoc.html">TemplateArgumentLoc</a>>,9721 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefNameDecl.html">TypedefNameDecl</a>>9722</pre></td></tr>9723 9724 9725<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OpaqueValueExpr.html">OpaqueValueExpr</a>></td><td class="name" onclick="toggle('hasSourceExpression1')"><a name="hasSourceExpression1Anchor">hasSourceExpression</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>9726<tr><td colspan="4" class="doc" id="hasSourceExpression1"><pre>Matches if the cast's source expression9727or opaque value's source expression matches the given matcher.9728 9729Example 1: matches "a string"9730(matcher = castExpr(hasSourceExpression(cxxConstructExpr())))9731class URL { URL(string); };9732URL url = "a string";9733 9734Example 2: matches 'b' (matcher =9735opaqueValueExpr(hasSourceExpression(implicitCastExpr(declRefExpr())))9736int a = b ?: 1;9737</pre></td></tr>9738 9739 9740<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OverloadExpr.html">OverloadExpr</a>></td><td class="name" onclick="toggle('hasAnyDeclaration0')"><a name="hasAnyDeclaration0Anchor">hasAnyDeclaration</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>9741<tr><td colspan="4" class="doc" id="hasAnyDeclaration0"><pre>Matches an OverloadExpr if any of the declarations in the set of9742overloads matches the given matcher.9743 9744Given9745 template <typename T> void foo(T);9746 template <typename T> void bar(T);9747 template <typename T> void baz(T t) {9748 foo(t);9749 bar(t);9750 }9751unresolvedLookupExpr(hasAnyDeclaration(9752 functionTemplateDecl(hasName("foo"))))9753 matches foo in foo(t); but not bar in bar(t);9754</pre></td></tr>9755 9756 9757<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ParenType.html">ParenType</a>></td><td class="name" onclick="toggle('innerType0')"><a name="innerType0Anchor">innerType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr>9758<tr><td colspan="4" class="doc" id="innerType0"><pre>Matches ParenType nodes where the inner type is a specific type.9759 9760Given9761 int (*ptr_to_array)[4];9762 int (*ptr_to_func)(int);9763 9764varDecl(hasType(pointsTo(parenType(innerType(functionType()))))) matches9765ptr_to_func but not ptr_to_array.9766 9767Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ParenType.html">ParenType</a>>9768</pre></td></tr>9769 9770 9771<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1PointerTypeLoc.html">PointerTypeLoc</a>></td><td class="name" onclick="toggle('hasPointeeLoc0')"><a name="hasPointeeLoc0Anchor">hasPointeeLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> PointeeMatcher</td></tr>9772<tr><td colspan="4" class="doc" id="hasPointeeLoc0"><pre>Matches pointer `TypeLoc`s that have a pointee `TypeLoc` matching9773`PointeeMatcher`.9774 9775Given9776 int* x;9777pointerTypeLoc(hasPointeeLoc(loc(asString("int"))))9778 matches `int*`.9779</pre></td></tr>9780 9781 9782<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1PointerType.html">PointerType</a>></td><td class="name" onclick="toggle('pointee2')"><a name="pointee2Anchor">pointee</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr>9783<tr><td colspan="4" class="doc" id="pointee2"><pre>Narrows PointerType (and similar) matchers to those where the9784pointee matches a given matcher.9785 9786Given9787 int *a;9788 int const *b;9789 float const *f;9790pointerType(pointee(isConstQualified(), isInteger()))9791 matches "int const *b"9792 9793Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockPointerType.html">BlockPointerType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberPointerType.html">MemberPointerType</a>>,9794 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1PointerType.html">PointerType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ReferenceType.html">ReferenceType</a>>,9795 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCObjectPointerType.html">ObjCObjectPointerType</a>>9796</pre></td></tr>9797 9798 9799<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('hasCanonicalType0')"><a name="hasCanonicalType0Anchor">hasCanonicalType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr>9800<tr><td colspan="4" class="doc" id="hasCanonicalType0"><pre>Matches QualTypes whose canonical type matches InnerMatcher.9801 9802Given:9803 typedef int &int_ref;9804 int a;9805 int_ref b = a;9806 9807varDecl(hasType(qualType(referenceType()))))) will not match the9808declaration of b but varDecl(hasType(qualType(hasCanonicalType(referenceType())))))) does.9809</pre></td></tr>9810 9811 9812<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('hasDeclaration7')"><a name="hasDeclaration7Anchor">hasDeclaration</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>9813<tr><td colspan="4" class="doc" id="hasDeclaration7"><pre>Matches a node if the declaration associated with that node9814matches the given matcher.9815 9816The associated declaration is:9817- for type nodes, the declaration of the underlying type9818- for CallExpr, the declaration of the callee9819- for MemberExpr, the declaration of the referenced member9820- for CXXConstructExpr, the declaration of the constructor9821- for CXXNewExpr, the declaration of the operator new9822- for ObjCIvarExpr, the declaration of the ivar9823 9824For type nodes, hasDeclaration will generally match the declaration of the9825sugared type. Given9826 class X {};9827 typedef X Y;9828 Y y;9829in varDecl(hasType(hasDeclaration(decl()))) the decl will match the9830typedefDecl. A common use case is to match the underlying, desugared type.9831This can be achieved by using the hasUnqualifiedDesugaredType matcher:9832 varDecl(hasType(hasUnqualifiedDesugaredType(9833 recordType(hasDeclaration(decl())))))9834In this matcher, the decl will match the CXXRecordDecl of class X.9835 9836Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>,9837 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>,9838 Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>,9839 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<RecordType>,9840 Matcher<TagType>, Matcher<TemplateSpecializationType>,9841 Matcher<TemplateTypeParmType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>,9842 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingType.html">UsingType</a>>9843</pre></td></tr>9844 9845 9846<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('ignoringParens0')"><a name="ignoringParens0Anchor">ignoringParens</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr>9847<tr><td colspan="4" class="doc" id="ignoringParens0"><pre>Matches types that match InnerMatcher after any parens are stripped.9848 9849Given9850 void (*fp)(void);9851The matcher9852 varDecl(hasType(pointerType(pointee(ignoringParens(functionType())))))9853would match the declaration for fp.9854</pre></td></tr>9855 9856 9857<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('pointsTo1')"><a name="pointsTo1Anchor">pointsTo</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>9858<tr><td colspan="4" class="doc" id="pointsTo1"><pre>Overloaded to match the pointee type's declaration.9859</pre></td></tr>9860 9861 9862<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('pointsTo0')"><a name="pointsTo0Anchor">pointsTo</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr>9863<tr><td colspan="4" class="doc" id="pointsTo0"><pre>Matches if the matched type is a pointer type and the pointee type9864matches the specified matcher.9865 9866Example matches y->x()9867 (matcher = cxxMemberCallExpr(on(hasType(pointsTo9868 cxxRecordDecl(hasName("Y")))))))9869 class Y { public: void x(); };9870 void z() { Y *y; y->x(); }9871</pre></td></tr>9872 9873 9874<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('references1')"><a name="references1Anchor">references</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>9875<tr><td colspan="4" class="doc" id="references1"><pre>Overloaded to match the referenced type's declaration.9876</pre></td></tr>9877 9878 9879<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('references0')"><a name="references0Anchor">references</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr>9880<tr><td colspan="4" class="doc" id="references0"><pre>Matches if the matched type is a reference type and the referenced9881type matches the specified matcher.9882 9883Example matches X &x and const X &y9884 (matcher = varDecl(hasType(references(cxxRecordDecl(hasName("X"))))))9885 class X {9886 void a(X b) {9887 X &x = b;9888 const X &y = b;9889 }9890 };9891</pre></td></tr>9892 9893 9894<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualifiedTypeLoc.html">QualifiedTypeLoc</a>></td><td class="name" onclick="toggle('hasUnqualifiedLoc0')"><a name="hasUnqualifiedLoc0Anchor">hasUnqualifiedLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> InnerMatcher</td></tr>9895<tr><td colspan="4" class="doc" id="hasUnqualifiedLoc0"><pre>Matches `QualifiedTypeLoc`s that have an unqualified `TypeLoc` matching9896`InnerMatcher`.9897 9898Given9899 int* const x;9900 const int y;9901qualifiedTypeLoc(hasUnqualifiedLoc(pointerTypeLoc()))9902 matches the `TypeLoc` of the variable declaration of `x`, but not `y`.9903</pre></td></tr>9904 9905 9906<tr><td>Matcher<RecordType></td><td class="name" onclick="toggle('hasDeclaration6')"><a name="hasDeclaration6Anchor">hasDeclaration</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>9907<tr><td colspan="4" class="doc" id="hasDeclaration6"><pre>Matches a node if the declaration associated with that node9908matches the given matcher.9909 9910The associated declaration is:9911- for type nodes, the declaration of the underlying type9912- for CallExpr, the declaration of the callee9913- for MemberExpr, the declaration of the referenced member9914- for CXXConstructExpr, the declaration of the constructor9915- for CXXNewExpr, the declaration of the operator new9916- for ObjCIvarExpr, the declaration of the ivar9917 9918For type nodes, hasDeclaration will generally match the declaration of the9919sugared type. Given9920 class X {};9921 typedef X Y;9922 Y y;9923in varDecl(hasType(hasDeclaration(decl()))) the decl will match the9924typedefDecl. A common use case is to match the underlying, desugared type.9925This can be achieved by using the hasUnqualifiedDesugaredType matcher:9926 varDecl(hasType(hasUnqualifiedDesugaredType(9927 recordType(hasDeclaration(decl())))))9928In this matcher, the decl will match the CXXRecordDecl of class X.9929 9930Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>,9931 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>,9932 Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>,9933 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<RecordType>,9934 Matcher<TagType>, Matcher<TemplateSpecializationType>,9935 Matcher<TemplateTypeParmType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>,9936 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingType.html">UsingType</a>>9937</pre></td></tr>9938 9939 9940<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ReferenceTypeLoc.html">ReferenceTypeLoc</a>></td><td class="name" onclick="toggle('hasReferentLoc0')"><a name="hasReferentLoc0Anchor">hasReferentLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> ReferentMatcher</td></tr>9941<tr><td colspan="4" class="doc" id="hasReferentLoc0"><pre>Matches reference `TypeLoc`s that have a referent `TypeLoc` matching9942`ReferentMatcher`.9943 9944Given9945 int x = 3;9946 int& xx = x;9947referenceTypeLoc(hasReferentLoc(loc(asString("int"))))9948 matches `int&`.9949</pre></td></tr>9950 9951 9952<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ReferenceType.html">ReferenceType</a>></td><td class="name" onclick="toggle('pointee3')"><a name="pointee3Anchor">pointee</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr>9953<tr><td colspan="4" class="doc" id="pointee3"><pre>Narrows PointerType (and similar) matchers to those where the9954pointee matches a given matcher.9955 9956Given9957 int *a;9958 int const *b;9959 float const *f;9960pointerType(pointee(isConstQualified(), isInteger()))9961 matches "int const *b"9962 9963Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockPointerType.html">BlockPointerType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberPointerType.html">MemberPointerType</a>>,9964 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1PointerType.html">PointerType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ReferenceType.html">ReferenceType</a>>,9965 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCObjectPointerType.html">ObjCObjectPointerType</a>>9966</pre></td></tr>9967 9968 9969<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ReturnStmt.html">ReturnStmt</a>></td><td class="name" onclick="toggle('hasReturnValue0')"><a name="hasReturnValue0Anchor">hasReturnValue</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>9970<tr><td colspan="4" class="doc" id="hasReturnValue0"><pre>Matches the return value expression of a return statement9971 9972Given9973 return a + b;9974hasReturnValue(binaryOperator())9975 matches 'return a + b'9976with binaryOperator()9977 matching 'a + b'9978</pre></td></tr>9979 9980 9981<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1StmtExpr.html">StmtExpr</a>></td><td class="name" onclick="toggle('hasAnySubstatement1')"><a name="hasAnySubstatement1Anchor">hasAnySubstatement</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr>9982<tr><td colspan="4" class="doc" id="hasAnySubstatement1"><pre>Matches compound statements where at least one substatement matches9983a given matcher. Also matches StmtExprs that have CompoundStmt as children.9984 9985Given9986 { {}; 1+2; }9987hasAnySubstatement(compoundStmt())9988 matches '{ {}; 1+2; }'9989with compoundStmt()9990 matching '{}'9991</pre></td></tr>9992 9993 9994<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('alignOfExpr0')"><a name="alignOfExpr0Anchor">alignOfExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html">UnaryExprOrTypeTraitExpr</a>> InnerMatcher</td></tr>9995<tr><td colspan="4" class="doc" id="alignOfExpr0"><pre>Same as unaryExprOrTypeTraitExpr, but only matching9996alignof.9997</pre></td></tr>9998 9999 10000<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('forCallable0')"><a name="forCallable0Anchor">forCallable</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>10001<tr><td colspan="4" class="doc" id="forCallable0"><pre>Matches declaration of the function, method, or block the statement10002belongs to.10003 10004Given:10005F& operator=(const F& o) {10006 std::copy_if(o.begin(), o.end(), begin(), [](V v) { return v > 0; });10007 return *this;10008}10009returnStmt(forCallable(functionDecl(hasName("operator="))))10010 matches 'return *this'10011 but does not match 'return v > 0'10012 10013Given:10014-(void) foo {10015 int x = 1;10016 dispatch_sync(queue, ^{ int y = 2; });10017}10018declStmt(forCallable(objcMethodDecl()))10019 matches 'int x = 1'10020 but does not match 'int y = 2'.10021whereas declStmt(forCallable(blockDecl()))10022 matches 'int y = 2'10023 but does not match 'int x = 1'.10024</pre></td></tr>10025 10026 10027<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('forFunction0')"><a name="forFunction0Anchor">forFunction</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>> InnerMatcher</td></tr>10028<tr><td colspan="4" class="doc" id="forFunction0"><pre>Matches declaration of the function the statement belongs to.10029 10030Deprecated. Use forCallable() to correctly handle the situation when10031the declaration is not a function (but a block or an Objective-C method).10032forFunction() not only fails to take non-functions into account but also10033may match the wrong declaration in their presence.10034 10035Given:10036F& operator=(const F& o) {10037 std::copy_if(o.begin(), o.end(), begin(), [](V v) { return v > 0; });10038 return *this;10039}10040returnStmt(forFunction(hasName("operator=")))10041 matches 'return *this'10042 but does not match 'return v > 0'10043</pre></td></tr>10044 10045 10046<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('sizeOfExpr0')"><a name="sizeOfExpr0Anchor">sizeOfExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html">UnaryExprOrTypeTraitExpr</a>> InnerMatcher</td></tr>10047<tr><td colspan="4" class="doc" id="sizeOfExpr0"><pre>Same as unaryExprOrTypeTraitExpr, but only matching10048sizeof.10049</pre></td></tr>10050 10051 10052<tr><td>Matcher<SubstTemplateTypeParmType></td><td class="name" onclick="toggle('hasReplacementType0')"><a name="hasReplacementType0Anchor">hasReplacementType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr>10053<tr><td colspan="4" class="doc" id="hasReplacementType0"><pre>Matches template type parameter substitutions that have a replacement10054type that matches the provided matcher.10055 10056Given10057 template <typename T>10058 double F(T t);10059 int i;10060 double j = F(i);10061 10062substTemplateTypeParmType(hasReplacementType(type())) matches int10063</pre></td></tr>10064 10065 10066<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1SwitchStmt.html">SwitchStmt</a>></td><td class="name" onclick="toggle('forEachSwitchCase0')"><a name="forEachSwitchCase0Anchor">forEachSwitchCase</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1SwitchCase.html">SwitchCase</a>> InnerMatcher</td></tr>10067<tr><td colspan="4" class="doc" id="forEachSwitchCase0"><pre>Matches each case or default statement belonging to the given switch10068statement. This matcher may produce multiple matches.10069 10070Given10071 switch (1) { case 1: case 2: default: switch (2) { case 3: case 4: ; } }10072switchStmt(forEachSwitchCase(caseStmt().bind("c"))).bind("s")10073 matches four times, with "c" binding each of "case 1:", "case 2:",10074"case 3:" and "case 4:", and "s" respectively binding "switch (1)",10075"switch (1)", "switch (2)" and "switch (2)".10076</pre></td></tr>10077 10078 10079<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1SwitchStmt.html">SwitchStmt</a>></td><td class="name" onclick="toggle('hasCondition4')"><a name="hasCondition4Anchor">hasCondition</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>10080<tr><td colspan="4" class="doc" id="hasCondition4"><pre>Matches the condition expression of an if statement, for loop, while loop,10081do-while loop, switch statement or conditional operator.10082 10083Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true))))10084 if (true) {}10085</pre></td></tr>10086 10087 10088<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1SwitchStmt.html">SwitchStmt</a>></td><td class="name" onclick="toggle('hasConditionVariableStatement3')"><a name="hasConditionVariableStatement3Anchor">hasConditionVariableStatement</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html">DeclStmt</a>> InnerMatcher</td></tr>10089<tr><td colspan="4" class="doc" id="hasConditionVariableStatement3"><pre>Matches the condition variable statement in an if statement, for loop,10090while loop or switch statement.10091 10092Given10093 if (A* a = GetAPointer()) {}10094 for (; A* a = GetAPointer(); ) {}10095hasConditionVariableStatement(...)10096 matches both 'A* a = GetAPointer()'.10097</pre></td></tr>10098 10099 10100<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1SwitchStmt.html">SwitchStmt</a>></td><td class="name" onclick="toggle('hasInitStatement1')"><a name="hasInitStatement1Anchor">hasInitStatement</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr>10101<tr><td colspan="4" class="doc" id="hasInitStatement1"><pre>Matches selection statements with initializer.10102 10103Given:10104 void foo() {10105 if (int i = foobar(); i > 0) {}10106 switch (int i = foobar(); i) {}10107 for (auto& a = get_range(); auto& x : a) {}10108 }10109 void bar() {10110 if (foobar() > 0) {}10111 switch (foobar()) {}10112 for (auto& x : get_range()) {}10113 }10114ifStmt(hasInitStatement(anything()))10115 matches the if statement in foo but not in bar.10116switchStmt(hasInitStatement(anything()))10117 matches the switch statement in foo but not in bar.10118cxxForRangeStmt(hasInitStatement(anything()))10119 matches the range for statement in foo but not in bar.10120</pre></td></tr>10121 10122 10123<tr><td>Matcher<TagType></td><td class="name" onclick="toggle('hasDeclaration5')"><a name="hasDeclaration5Anchor">hasDeclaration</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>10124<tr><td colspan="4" class="doc" id="hasDeclaration5"><pre>Matches a node if the declaration associated with that node10125matches the given matcher.10126 10127The associated declaration is:10128- for type nodes, the declaration of the underlying type10129- for CallExpr, the declaration of the callee10130- for MemberExpr, the declaration of the referenced member10131- for CXXConstructExpr, the declaration of the constructor10132- for CXXNewExpr, the declaration of the operator new10133- for ObjCIvarExpr, the declaration of the ivar10134 10135For type nodes, hasDeclaration will generally match the declaration of the10136sugared type. Given10137 class X {};10138 typedef X Y;10139 Y y;10140in varDecl(hasType(hasDeclaration(decl()))) the decl will match the10141typedefDecl. A common use case is to match the underlying, desugared type.10142This can be achieved by using the hasUnqualifiedDesugaredType matcher:10143 varDecl(hasType(hasUnqualifiedDesugaredType(10144 recordType(hasDeclaration(decl())))))10145In this matcher, the decl will match the CXXRecordDecl of class X.10146 10147Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>,10148 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>,10149 Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>,10150 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<RecordType>,10151 Matcher<TagType>, Matcher<TemplateSpecializationType>,10152 Matcher<TemplateTypeParmType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>,10153 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingType.html">UsingType</a>>10154</pre></td></tr>10155 10156 10157<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgumentLoc.html">TemplateArgumentLoc</a>></td><td class="name" onclick="toggle('hasTypeLoc11')"><a name="hasTypeLoc11Anchor">hasTypeLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> Inner</td></tr>10158<tr><td colspan="4" class="doc" id="hasTypeLoc11"><pre>Matches if the type location of a node matches the inner matcher.10159 10160Examples:10161 int x;10162declaratorDecl(hasTypeLoc(loc(asString("int"))))10163 matches int x10164 10165auto x = int(3);10166cxxTemporaryObjectExpr(hasTypeLoc(loc(asString("int"))))10167 matches int(3)10168 10169struct Foo { Foo(int, int); };10170auto x = Foo(1, 2);10171cxxFunctionalCastExpr(hasTypeLoc(loc(asString("struct Foo"))))10172 matches Foo(1, 2)10173 10174Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockDecl.html">BlockDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>>,10175 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFunctionalCastExpr.html">CXXFunctionalCastExpr</a>>,10176 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXTemporaryObjectExpr.html">CXXTemporaryObjectExpr</a>>,10177 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXUnresolvedConstructExpr.html">CXXUnresolvedConstructExpr</a>>,10178 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CompoundLiteralExpr.html">CompoundLiteralExpr</a>>,10179 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclaratorDecl.html">DeclaratorDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ExplicitCastExpr.html">ExplicitCastExpr</a>>,10180 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCPropertyDecl.html">ObjCPropertyDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgumentLoc.html">TemplateArgumentLoc</a>>,10181 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefNameDecl.html">TypedefNameDecl</a>>10182</pre></td></tr>10183 10184 10185<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>></td><td class="name" onclick="toggle('isExpr0')"><a name="isExpr0Anchor">isExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>10186<tr><td colspan="4" class="doc" id="isExpr0"><pre>Matches a sugar TemplateArgument that refers to a certain expression.10187 10188Given10189 struct B { int next; };10190 template<int(B::*next_ptr)> struct A {};10191 A<&B::next> a;10192templateSpecializationType(hasAnyTemplateArgument(10193 isExpr(hasDescendant(declRefExpr(to(fieldDecl(hasName("next"))))))))10194 matches the specialization A<&B::next> with fieldDecl(...) matching10195 B::next10196</pre></td></tr>10197 10198 10199<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>></td><td class="name" onclick="toggle('refersToDeclaration0')"><a name="refersToDeclaration0Anchor">refersToDeclaration</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>10200<tr><td colspan="4" class="doc" id="refersToDeclaration0"><pre>Matches a canonical TemplateArgument that refers to a certain10201declaration.10202 10203Given10204 struct B { int next; };10205 template<int(B::*next_ptr)> struct A {};10206 A<&B::next> a;10207classTemplateSpecializationDecl(hasAnyTemplateArgument(10208 refersToDeclaration(fieldDecl(hasName("next")))))10209 matches the specialization A<&B::next> with fieldDecl(...) matching10210 B::next10211</pre></td></tr>10212 10213 10214<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>></td><td class="name" onclick="toggle('refersToIntegralType0')"><a name="refersToIntegralType0Anchor">refersToIntegralType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr>10215<tr><td colspan="4" class="doc" id="refersToIntegralType0"><pre>Matches a TemplateArgument that refers to an integral type.10216 10217Given10218 template<int T> struct C {};10219 C<42> c;10220classTemplateSpecializationDecl(10221 hasAnyTemplateArgument(refersToIntegralType(asString("int"))))10222 matches the implicit instantiation of C in C<42>.10223</pre></td></tr>10224 10225 10226<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>></td><td class="name" onclick="toggle('refersToTemplate0')"><a name="refersToTemplate0Anchor">refersToTemplate</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateName.html">TemplateName</a>> InnerMatcher</td></tr>10227<tr><td colspan="4" class="doc" id="refersToTemplate0"><pre>Matches a TemplateArgument that refers to a certain template.10228 10229Given10230 template<template <typename> class S> class X {};10231 template<typename T> class Y {};10232 X<Y> xi;10233classTemplateSpecializationDecl(hasAnyTemplateArgument(10234 refersToTemplate(templateName())))10235 matches the specialization X<Y>10236</pre></td></tr>10237 10238 10239<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>></td><td class="name" onclick="toggle('refersToType0')"><a name="refersToType0Anchor">refersToType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr>10240<tr><td colspan="4" class="doc" id="refersToType0"><pre>Matches a TemplateArgument that refers to a certain type.10241 10242Given10243 struct X {};10244 template<typename T> struct A {};10245 A<X> a;10246classTemplateSpecializationDecl(hasAnyTemplateArgument(refersToType(10247 recordType(hasDeclaration(recordDecl(hasName("X")))))))10248matches the specialization of struct A generated by A<X>.10249</pre></td></tr>10250 10251 10252<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationTypeLoc.html">TemplateSpecializationTypeLoc</a>></td><td class="name" onclick="toggle('hasAnyTemplateArgumentLoc4')"><a name="hasAnyTemplateArgumentLoc4Anchor">hasAnyTemplateArgumentLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgumentLoc.html">TemplateArgumentLoc</a>> InnerMatcher</td></tr>10253<tr><td colspan="4" class="doc" id="hasAnyTemplateArgumentLoc4"><pre>Matches template specialization `TypeLoc`s, class template specializations,10254variable template specializations, and function template specializations10255that have at least one `TemplateArgumentLoc` matching the given10256`InnerMatcher`.10257 10258Given10259 template<typename T> class A {};10260 A<int> a;10261varDecl(hasTypeLoc(templateSpecializationTypeLoc(hasAnyTemplateArgumentLoc(10262 hasTypeLoc(loc(asString("int")))))))10263 matches `A<int> a`.10264</pre></td></tr>10265 10266 10267<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationTypeLoc.html">TemplateSpecializationTypeLoc</a>></td><td class="name" onclick="toggle('hasTemplateArgumentLoc4')"><a name="hasTemplateArgumentLoc4Anchor">hasTemplateArgumentLoc</a></td><td>unsigned Index, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgumentLoc.html">TemplateArgumentLoc</a>> InnerMatcher</td></tr>10268<tr><td colspan="4" class="doc" id="hasTemplateArgumentLoc4"><pre>Matches template specialization `TypeLoc`s, class template specializations,10269variable template specializations, and function template specializations10270where the n'th `TemplateArgumentLoc` matches the given `InnerMatcher`.10271 10272Given10273 template<typename T, typename U> class A {};10274 A<double, int> b;10275 A<int, double> c;10276varDecl(hasTypeLoc(templateSpecializationTypeLoc(hasTemplateArgumentLoc(0,10277 hasTypeLoc(loc(asString("double")))))))10278 matches `A<double, int> b`, but not `A<int, double> c`.10279</pre></td></tr>10280 10281 10282<tr><td>Matcher<TemplateSpecializationType></td><td class="name" onclick="toggle('forEachTemplateArgument3')"><a name="forEachTemplateArgument3Anchor">forEachTemplateArgument</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr>10283<tr><td colspan="4" class="doc" id="forEachTemplateArgument3"><pre>Matches templateSpecializationType, class template specialization,10284variable template specialization, and function template specialization10285nodes where the template argument matches the inner matcher. This matcher10286may produce multiple matches.10287 10288Given10289 template <typename T, unsigned N, unsigned M>10290 struct Matrix {};10291 10292 constexpr unsigned R = 2;10293 Matrix<int, R * 2, R * 4> M;10294 10295 template <typename T, typename U>10296 void f(T&& t, U&& u) {}10297 10298 bool B = false;10299 f(R, B);10300templateSpecializationType(forEachTemplateArgument(isExpr(expr())))10301 matches twice, with expr() matching 'R * 2' and 'R * 4'10302functionDecl(forEachTemplateArgument(refersToType(builtinType())))10303 matches the specialization f<unsigned, bool> twice, for 'unsigned'10304 and 'bool'10305</pre></td></tr>10306 10307 10308<tr><td>Matcher<TemplateSpecializationType></td><td class="name" onclick="toggle('hasAnyTemplateArgument3')"><a name="hasAnyTemplateArgument3Anchor">hasAnyTemplateArgument</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr>10309<tr><td colspan="4" class="doc" id="hasAnyTemplateArgument3"><pre>Matches templateSpecializationTypes, class template specializations,10310variable template specializations, and function template specializations10311that have at least one TemplateArgument matching the given InnerMatcher.10312 10313Given10314 template<typename T> class A {};10315 template<> class A<double> {};10316 A<int> a;10317 10318 template<typename T> f() {};10319 void func() { f<int>(); };10320 10321classTemplateSpecializationDecl(hasAnyTemplateArgument(10322 refersToType(asString("int"))))10323 matches the specialization A<int>10324 10325functionDecl(hasAnyTemplateArgument(refersToType(asString("int"))))10326 matches the specialization f<int>10327</pre></td></tr>10328 10329 10330<tr><td>Matcher<TemplateSpecializationType></td><td class="name" onclick="toggle('hasDeclaration4')"><a name="hasDeclaration4Anchor">hasDeclaration</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>10331<tr><td colspan="4" class="doc" id="hasDeclaration4"><pre>Matches a node if the declaration associated with that node10332matches the given matcher.10333 10334The associated declaration is:10335- for type nodes, the declaration of the underlying type10336- for CallExpr, the declaration of the callee10337- for MemberExpr, the declaration of the referenced member10338- for CXXConstructExpr, the declaration of the constructor10339- for CXXNewExpr, the declaration of the operator new10340- for ObjCIvarExpr, the declaration of the ivar10341 10342For type nodes, hasDeclaration will generally match the declaration of the10343sugared type. Given10344 class X {};10345 typedef X Y;10346 Y y;10347in varDecl(hasType(hasDeclaration(decl()))) the decl will match the10348typedefDecl. A common use case is to match the underlying, desugared type.10349This can be achieved by using the hasUnqualifiedDesugaredType matcher:10350 varDecl(hasType(hasUnqualifiedDesugaredType(10351 recordType(hasDeclaration(decl())))))10352In this matcher, the decl will match the CXXRecordDecl of class X.10353 10354Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>,10355 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>,10356 Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>,10357 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<RecordType>,10358 Matcher<TagType>, Matcher<TemplateSpecializationType>,10359 Matcher<TemplateTypeParmType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>,10360 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingType.html">UsingType</a>>10361</pre></td></tr>10362 10363 10364<tr><td>Matcher<TemplateSpecializationType></td><td class="name" onclick="toggle('hasTemplateArgument3')"><a name="hasTemplateArgument3Anchor">hasTemplateArgument</a></td><td>unsigned N, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr>10365<tr><td colspan="4" class="doc" id="hasTemplateArgument3"><pre>Matches templateSpecializationType, class template specializations,10366variable template specializations, and function template specializations10367where the n'th TemplateArgument matches the given InnerMatcher.10368 10369Given10370 template<typename T, typename U> class A {};10371 A<bool, int> b;10372 A<int, bool> c;10373 10374 template<typename T> void f() {}10375 void func() { f<int>(); };10376classTemplateSpecializationDecl(hasTemplateArgument(10377 1, refersToType(asString("int"))))10378 matches the specialization A<bool, int>10379 10380functionDecl(hasTemplateArgument(0, refersToType(asString("int"))))10381 matches the specialization f<int>10382</pre></td></tr>10383 10384 10385<tr><td>Matcher<TemplateTypeParmType></td><td class="name" onclick="toggle('hasDeclaration3')"><a name="hasDeclaration3Anchor">hasDeclaration</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>10386<tr><td colspan="4" class="doc" id="hasDeclaration3"><pre>Matches a node if the declaration associated with that node10387matches the given matcher.10388 10389The associated declaration is:10390- for type nodes, the declaration of the underlying type10391- for CallExpr, the declaration of the callee10392- for MemberExpr, the declaration of the referenced member10393- for CXXConstructExpr, the declaration of the constructor10394- for CXXNewExpr, the declaration of the operator new10395- for ObjCIvarExpr, the declaration of the ivar10396 10397For type nodes, hasDeclaration will generally match the declaration of the10398sugared type. Given10399 class X {};10400 typedef X Y;10401 Y y;10402in varDecl(hasType(hasDeclaration(decl()))) the decl will match the10403typedefDecl. A common use case is to match the underlying, desugared type.10404This can be achieved by using the hasUnqualifiedDesugaredType matcher:10405 varDecl(hasType(hasUnqualifiedDesugaredType(10406 recordType(hasDeclaration(decl())))))10407In this matcher, the decl will match the CXXRecordDecl of class X.10408 10409Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>,10410 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>,10411 Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>,10412 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<RecordType>,10413 Matcher<TagType>, Matcher<TemplateSpecializationType>,10414 Matcher<TemplateTypeParmType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>,10415 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingType.html">UsingType</a>>10416</pre></td></tr>10417 10418 10419<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td><td class="name" onclick="toggle('loc0')"><a name="loc0Anchor">loc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr>10420<tr><td colspan="4" class="doc" id="loc0"><pre>Matches TypeLocs for which the given inner10421QualType-matcher matches.10422</pre></td></tr>10423 10424 10425<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefNameDecl.html">TypedefNameDecl</a>></td><td class="name" onclick="toggle('hasTypeLoc12')"><a name="hasTypeLoc12Anchor">hasTypeLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> Inner</td></tr>10426<tr><td colspan="4" class="doc" id="hasTypeLoc12"><pre>Matches if the type location of a node matches the inner matcher.10427 10428Examples:10429 int x;10430declaratorDecl(hasTypeLoc(loc(asString("int"))))10431 matches int x10432 10433auto x = int(3);10434cxxTemporaryObjectExpr(hasTypeLoc(loc(asString("int"))))10435 matches int(3)10436 10437struct Foo { Foo(int, int); };10438auto x = Foo(1, 2);10439cxxFunctionalCastExpr(hasTypeLoc(loc(asString("struct Foo"))))10440 matches Foo(1, 2)10441 10442Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockDecl.html">BlockDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>>,10443 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFunctionalCastExpr.html">CXXFunctionalCastExpr</a>>,10444 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXTemporaryObjectExpr.html">CXXTemporaryObjectExpr</a>>,10445 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXUnresolvedConstructExpr.html">CXXUnresolvedConstructExpr</a>>,10446 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CompoundLiteralExpr.html">CompoundLiteralExpr</a>>,10447 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclaratorDecl.html">DeclaratorDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ExplicitCastExpr.html">ExplicitCastExpr</a>>,10448 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCPropertyDecl.html">ObjCPropertyDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgumentLoc.html">TemplateArgumentLoc</a>>,10449 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefNameDecl.html">TypedefNameDecl</a>>10450</pre></td></tr>10451 10452 10453<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefNameDecl.html">TypedefNameDecl</a>></td><td class="name" onclick="toggle('hasType2')"><a name="hasType2Anchor">hasType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr>10454<tr><td colspan="4" class="doc" id="hasType2"><pre>Matches if the expression's or declaration's type matches a type10455matcher.10456 10457Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X")))))10458 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X")))))10459 and U (matcher = typedefDecl(hasType(asString("int")))10460 and friend class X (matcher = friendDecl(hasType("X"))10461 and public virtual X (matcher = cxxBaseSpecifier(hasType(10462 asString("class X")))10463 class X {};10464 void y(X &x) { x; X z; }10465 typedef int U;10466 class Y { friend class X; };10467 class Z : public virtual X {};10468</pre></td></tr>10469 10470 10471<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>></td><td class="name" onclick="toggle('hasDeclaration2')"><a name="hasDeclaration2Anchor">hasDeclaration</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>10472<tr><td colspan="4" class="doc" id="hasDeclaration2"><pre>Matches a node if the declaration associated with that node10473matches the given matcher.10474 10475The associated declaration is:10476- for type nodes, the declaration of the underlying type10477- for CallExpr, the declaration of the callee10478- for MemberExpr, the declaration of the referenced member10479- for CXXConstructExpr, the declaration of the constructor10480- for CXXNewExpr, the declaration of the operator new10481- for ObjCIvarExpr, the declaration of the ivar10482 10483For type nodes, hasDeclaration will generally match the declaration of the10484sugared type. Given10485 class X {};10486 typedef X Y;10487 Y y;10488in varDecl(hasType(hasDeclaration(decl()))) the decl will match the10489typedefDecl. A common use case is to match the underlying, desugared type.10490This can be achieved by using the hasUnqualifiedDesugaredType matcher:10491 varDecl(hasType(hasUnqualifiedDesugaredType(10492 recordType(hasDeclaration(decl())))))10493In this matcher, the decl will match the CXXRecordDecl of class X.10494 10495Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>,10496 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>,10497 Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>,10498 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<RecordType>,10499 Matcher<TagType>, Matcher<TemplateSpecializationType>,10500 Matcher<TemplateTypeParmType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>,10501 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingType.html">UsingType</a>>10502</pre></td></tr>10503 10504 10505<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('hasQualifier0')"><a name="hasQualifier0Anchor">hasQualifier</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifier.html">NestedNameSpecifier</a>> InnerMatcher</td></tr>10506<tr><td colspan="4" class="doc" id="hasQualifier0"><pre>Matches Types whose qualifier, a NestedNameSpecifier,10507matches InnerMatcher if the qualifier exists.10508 10509Given10510 namespace N {10511 namespace M {10512 class D {};10513 }10514 }10515 N::M::D d;10516 10517elaboratedType(hasQualifier(hasPrefix(specifiesNamespace(hasName("N"))))10518matches the type of the variable declaration of d.10519</pre></td></tr>10520 10521 10522<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('hasUnderlyingType0')"><a name="hasUnderlyingType0Anchor">hasUnderlyingType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> Inner</td></tr>10523<tr><td colspan="4" class="doc" id="hasUnderlyingType0"><pre>Matches QualType nodes to find the underlying type.10524 10525Given10526 decltype(1) a = 1;10527 decltype(2.0) b = 2.0;10528decltypeType(hasUnderlyingType(isInteger()))10529 matches the type of "a"10530 10531Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>10532</pre></td></tr>10533 10534 10535<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('hasUnqualifiedDesugaredType0')"><a name="hasUnqualifiedDesugaredType0Anchor">hasUnqualifiedDesugaredType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>> InnerMatcher</td></tr>10536<tr><td colspan="4" class="doc" id="hasUnqualifiedDesugaredType0"><pre>Matches if the matched type matches the unqualified desugared10537type of the matched node.10538 10539For example, in:10540 class A {};10541 using B = A;10542The matcher type(hasUnqualifiedDesugaredType(recordType())) matches10543both B and A.10544</pre></td></tr>10545 10546 10547<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html">UnaryExprOrTypeTraitExpr</a>></td><td class="name" onclick="toggle('hasArgumentOfType0')"><a name="hasArgumentOfType0Anchor">hasArgumentOfType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr>10548<tr><td colspan="4" class="doc" id="hasArgumentOfType0"><pre>Matches unary expressions that have a specific type of argument.10549 10550Given10551 int a, c; float b; int s = sizeof(a) + sizeof(b) + alignof(c);10552unaryExprOrTypeTraitExpr(hasArgumentOfType(asString("int"))10553 matches sizeof(a) and alignof(c)10554</pre></td></tr>10555 10556 10557<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnaryOperator.html">UnaryOperator</a>></td><td class="name" onclick="toggle('hasUnaryOperand0')"><a name="hasUnaryOperand0Anchor">hasUnaryOperand</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>10558<tr><td colspan="4" class="doc" id="hasUnaryOperand0"><pre>Matches if the operand of a unary operator matches.10559 10560Example matches true (matcher = hasUnaryOperand(10561 cxxBoolLiteral(equals(true))))10562 !true10563</pre></td></tr>10564 10565 10566<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedMemberExpr.html">UnresolvedMemberExpr</a>></td><td class="name" onclick="toggle('hasObjectExpression1')"><a name="hasObjectExpression1Anchor">hasObjectExpression</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>10567<tr><td colspan="4" class="doc" id="hasObjectExpression1"><pre>Matches a member expression where the object expression is matched by a10568given matcher. Implicit object expressions are included; that is, it matches10569use of implicit `this`.10570 10571Given10572 struct X {10573 int m;10574 int f(X x) { x.m; return m; }10575 };10576memberExpr(hasObjectExpression(hasType(cxxRecordDecl(hasName("X")))))10577 matches `x.m`, but not `m`; however,10578memberExpr(hasObjectExpression(hasType(pointsTo(10579 cxxRecordDecl(hasName("X"))))))10580 matches `m` (aka. `this->m`), but not `x.m`.10581</pre></td></tr>10582 10583 10584<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>></td><td class="name" onclick="toggle('hasDeclaration1')"><a name="hasDeclaration1Anchor">hasDeclaration</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>10585<tr><td colspan="4" class="doc" id="hasDeclaration1"><pre>Matches a node if the declaration associated with that node10586matches the given matcher.10587 10588The associated declaration is:10589- for type nodes, the declaration of the underlying type10590- for CallExpr, the declaration of the callee10591- for MemberExpr, the declaration of the referenced member10592- for CXXConstructExpr, the declaration of the constructor10593- for CXXNewExpr, the declaration of the operator new10594- for ObjCIvarExpr, the declaration of the ivar10595 10596For type nodes, hasDeclaration will generally match the declaration of the10597sugared type. Given10598 class X {};10599 typedef X Y;10600 Y y;10601in varDecl(hasType(hasDeclaration(decl()))) the decl will match the10602typedefDecl. A common use case is to match the underlying, desugared type.10603This can be achieved by using the hasUnqualifiedDesugaredType matcher:10604 varDecl(hasType(hasUnqualifiedDesugaredType(10605 recordType(hasDeclaration(decl())))))10606In this matcher, the decl will match the CXXRecordDecl of class X.10607 10608Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>,10609 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>,10610 Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>,10611 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<RecordType>,10612 Matcher<TagType>, Matcher<TemplateSpecializationType>,10613 Matcher<TemplateTypeParmType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>,10614 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingType.html">UsingType</a>>10615</pre></td></tr>10616 10617 10618<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingShadowDecl.html">UsingShadowDecl</a>></td><td class="name" onclick="toggle('hasTargetDecl0')"><a name="hasTargetDecl0Anchor">hasTargetDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>> InnerMatcher</td></tr>10619<tr><td colspan="4" class="doc" id="hasTargetDecl0"><pre>Matches a using shadow declaration where the target declaration is10620matched by the given matcher.10621 10622Given10623 namespace X { int a; void b(); }10624 using X::a;10625 using X::b;10626usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(functionDecl())))10627 matches using X::b but not using X::a </pre></td></tr>10628 10629 10630<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingType.html">UsingType</a>></td><td class="name" onclick="toggle('hasDeclaration0')"><a name="hasDeclaration0Anchor">hasDeclaration</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>10631<tr><td colspan="4" class="doc" id="hasDeclaration0"><pre>Matches a node if the declaration associated with that node10632matches the given matcher.10633 10634The associated declaration is:10635- for type nodes, the declaration of the underlying type10636- for CallExpr, the declaration of the callee10637- for MemberExpr, the declaration of the referenced member10638- for CXXConstructExpr, the declaration of the constructor10639- for CXXNewExpr, the declaration of the operator new10640- for ObjCIvarExpr, the declaration of the ivar10641 10642For type nodes, hasDeclaration will generally match the declaration of the10643sugared type. Given10644 class X {};10645 typedef X Y;10646 Y y;10647in varDecl(hasType(hasDeclaration(decl()))) the decl will match the10648typedefDecl. A common use case is to match the underlying, desugared type.10649This can be achieved by using the hasUnqualifiedDesugaredType matcher:10650 varDecl(hasType(hasUnqualifiedDesugaredType(10651 recordType(hasDeclaration(decl())))))10652In this matcher, the decl will match the CXXRecordDecl of class X.10653 10654Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>,10655 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>,10656 Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>,10657 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<RecordType>,10658 Matcher<TagType>, Matcher<TemplateSpecializationType>,10659 Matcher<TemplateTypeParmType>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>,10660 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingType.html">UsingType</a>>10661</pre></td></tr>10662 10663 10664<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingType.html">UsingType</a>></td><td class="name" onclick="toggle('throughUsingDecl1')"><a name="throughUsingDecl1Anchor">throughUsingDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingShadowDecl.html">UsingShadowDecl</a>> Inner</td></tr>10665<tr><td colspan="4" class="doc" id="throughUsingDecl1"><pre>Matches if a node refers to a declaration through a specific10666using shadow declaration.10667 10668Examples:10669 namespace a { int f(); }10670 using a::f;10671 int x = f();10672declRefExpr(throughUsingDecl(anything()))10673 matches f10674 10675 namespace a { class X{}; }10676 using a::X;10677 X x;10678typeLoc(loc(usingType(throughUsingDecl(anything()))))10679 matches X10680 10681Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingType.html">UsingType</a>>10682</pre></td></tr>10683 10684 10685<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</a>></td><td class="name" onclick="toggle('hasType7')"><a name="hasType7Anchor">hasType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr>10686<tr><td colspan="4" class="doc" id="hasType7"><pre>Overloaded to match the declaration of the expression's or value10687declaration's type.10688 10689In case of a value declaration (for example a variable declaration),10690this resolves one layer of indirection. For example, in the value10691declaration "X x;", cxxRecordDecl(hasName("X")) matches the declaration of10692X, while varDecl(hasType(cxxRecordDecl(hasName("X")))) matches the10693declaration of x.10694 10695Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X")))))10696 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X")))))10697 and friend class X (matcher = friendDecl(hasType("X"))10698 and public virtual X (matcher = cxxBaseSpecifier(hasType(10699 cxxRecordDecl(hasName("X"))))10700 class X {};10701 void y(X &x) { x; X z; }10702 class Y { friend class X; };10703 class Z : public virtual X {};10704 10705Example matches class Derived10706(matcher = cxxRecordDecl(hasAnyBase(hasType(cxxRecordDecl(hasName("Base"))))))10707class Base {};10708class Derived : Base {};10709 10710Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FriendDecl.html">FriendDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</a>>,10711Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html">CXXBaseSpecifier</a>>10712</pre></td></tr>10713 10714 10715<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</a>></td><td class="name" onclick="toggle('hasType3')"><a name="hasType3Anchor">hasType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr>10716<tr><td colspan="4" class="doc" id="hasType3"><pre>Matches if the expression's or declaration's type matches a type10717matcher.10718 10719Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X")))))10720 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X")))))10721 and U (matcher = typedefDecl(hasType(asString("int")))10722 and friend class X (matcher = friendDecl(hasType("X"))10723 and public virtual X (matcher = cxxBaseSpecifier(hasType(10724 asString("class X")))10725 class X {};10726 void y(X &x) { x; X z; }10727 typedef int U;10728 class Y { friend class X; };10729 class Z : public virtual X {};10730</pre></td></tr>10731 10732 10733<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>></td><td class="name" onclick="toggle('hasInitializer0')"><a name="hasInitializer0Anchor">hasInitializer</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>10734<tr><td colspan="4" class="doc" id="hasInitializer0"><pre>Matches a variable declaration that has an initializer expression10735that matches the given matcher.10736 10737Example matches x (matcher = varDecl(hasInitializer(callExpr())))10738 bool y() { return true; }10739 bool x = y();10740</pre></td></tr>10741 10742 10743<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarTemplateSpecializationDecl.html">VarTemplateSpecializationDecl</a>></td><td class="name" onclick="toggle('forEachTemplateArgument1')"><a name="forEachTemplateArgument1Anchor">forEachTemplateArgument</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr>10744<tr><td colspan="4" class="doc" id="forEachTemplateArgument1"><pre>Matches templateSpecializationType, class template specialization,10745variable template specialization, and function template specialization10746nodes where the template argument matches the inner matcher. This matcher10747may produce multiple matches.10748 10749Given10750 template <typename T, unsigned N, unsigned M>10751 struct Matrix {};10752 10753 constexpr unsigned R = 2;10754 Matrix<int, R * 2, R * 4> M;10755 10756 template <typename T, typename U>10757 void f(T&& t, U&& u) {}10758 10759 bool B = false;10760 f(R, B);10761templateSpecializationType(forEachTemplateArgument(isExpr(expr())))10762 matches twice, with expr() matching 'R * 2' and 'R * 4'10763functionDecl(forEachTemplateArgument(refersToType(builtinType())))10764 matches the specialization f<unsigned, bool> twice, for 'unsigned'10765 and 'bool'10766</pre></td></tr>10767 10768 10769<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarTemplateSpecializationDecl.html">VarTemplateSpecializationDecl</a>></td><td class="name" onclick="toggle('hasAnyTemplateArgumentLoc1')"><a name="hasAnyTemplateArgumentLoc1Anchor">hasAnyTemplateArgumentLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgumentLoc.html">TemplateArgumentLoc</a>> InnerMatcher</td></tr>10770<tr><td colspan="4" class="doc" id="hasAnyTemplateArgumentLoc1"><pre>Matches template specialization `TypeLoc`s, class template specializations,10771variable template specializations, and function template specializations10772that have at least one `TemplateArgumentLoc` matching the given10773`InnerMatcher`.10774 10775Given10776 template<typename T> class A {};10777 A<int> a;10778varDecl(hasTypeLoc(templateSpecializationTypeLoc(hasAnyTemplateArgumentLoc(10779 hasTypeLoc(loc(asString("int")))))))10780 matches `A<int> a`.10781</pre></td></tr>10782 10783 10784<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarTemplateSpecializationDecl.html">VarTemplateSpecializationDecl</a>></td><td class="name" onclick="toggle('hasAnyTemplateArgument1')"><a name="hasAnyTemplateArgument1Anchor">hasAnyTemplateArgument</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr>10785<tr><td colspan="4" class="doc" id="hasAnyTemplateArgument1"><pre>Matches templateSpecializationTypes, class template specializations,10786variable template specializations, and function template specializations10787that have at least one TemplateArgument matching the given InnerMatcher.10788 10789Given10790 template<typename T> class A {};10791 template<> class A<double> {};10792 A<int> a;10793 10794 template<typename T> f() {};10795 void func() { f<int>(); };10796 10797classTemplateSpecializationDecl(hasAnyTemplateArgument(10798 refersToType(asString("int"))))10799 matches the specialization A<int>10800 10801functionDecl(hasAnyTemplateArgument(refersToType(asString("int"))))10802 matches the specialization f<int>10803</pre></td></tr>10804 10805 10806<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarTemplateSpecializationDecl.html">VarTemplateSpecializationDecl</a>></td><td class="name" onclick="toggle('hasTemplateArgumentLoc1')"><a name="hasTemplateArgumentLoc1Anchor">hasTemplateArgumentLoc</a></td><td>unsigned Index, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgumentLoc.html">TemplateArgumentLoc</a>> InnerMatcher</td></tr>10807<tr><td colspan="4" class="doc" id="hasTemplateArgumentLoc1"><pre>Matches template specialization `TypeLoc`s, class template specializations,10808variable template specializations, and function template specializations10809where the n'th `TemplateArgumentLoc` matches the given `InnerMatcher`.10810 10811Given10812 template<typename T, typename U> class A {};10813 A<double, int> b;10814 A<int, double> c;10815varDecl(hasTypeLoc(templateSpecializationTypeLoc(hasTemplateArgumentLoc(0,10816 hasTypeLoc(loc(asString("double")))))))10817 matches `A<double, int> b`, but not `A<int, double> c`.10818</pre></td></tr>10819 10820 10821<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarTemplateSpecializationDecl.html">VarTemplateSpecializationDecl</a>></td><td class="name" onclick="toggle('hasTemplateArgument1')"><a name="hasTemplateArgument1Anchor">hasTemplateArgument</a></td><td>unsigned N, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr>10822<tr><td colspan="4" class="doc" id="hasTemplateArgument1"><pre>Matches templateSpecializationType, class template specializations,10823variable template specializations, and function template specializations10824where the n'th TemplateArgument matches the given InnerMatcher.10825 10826Given10827 template<typename T, typename U> class A {};10828 A<bool, int> b;10829 A<int, bool> c;10830 10831 template<typename T> void f() {}10832 void func() { f<int>(); };10833classTemplateSpecializationDecl(hasTemplateArgument(10834 1, refersToType(asString("int"))))10835 matches the specialization A<bool, int>10836 10837functionDecl(hasTemplateArgument(0, refersToType(asString("int"))))10838 matches the specialization f<int>10839</pre></td></tr>10840 10841 10842<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VariableArrayType.html">VariableArrayType</a>></td><td class="name" onclick="toggle('hasSizeExpr0')"><a name="hasSizeExpr0Anchor">hasSizeExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>10843<tr><td colspan="4" class="doc" id="hasSizeExpr0"><pre>Matches VariableArrayType nodes that have a specific size10844expression.10845 10846Given10847 void f(int b) {10848 int a[b];10849 }10850variableArrayType(hasSizeExpr(ignoringImpCasts(declRefExpr(to(10851 varDecl(hasName("b")))))))10852 matches "int a[b]"10853</pre></td></tr>10854 10855 10856<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1WhileStmt.html">WhileStmt</a>></td><td class="name" onclick="toggle('hasBody2')"><a name="hasBody2Anchor">hasBody</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr>10857<tr><td colspan="4" class="doc" id="hasBody2"><pre>Matches a 'for', 'while', 'while' statement or a function or coroutine10858definition that has a given body. Note that in case of functions or10859coroutines this matcher only matches the definition itself and not the10860other declarations of the same function or coroutine.10861 10862Given10863 for (;;) {}10864forStmt(hasBody(compoundStmt()))10865 matches 'for (;;) {}'10866with compoundStmt()10867 matching '{}'10868 10869Given10870 void f();10871 void f() {}10872functionDecl(hasBody(compoundStmt()))10873 matches 'void f() {}'10874with compoundStmt()10875 matching '{}'10876 but does not match 'void f();'10877</pre></td></tr>10878 10879 10880<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1WhileStmt.html">WhileStmt</a>></td><td class="name" onclick="toggle('hasCondition2')"><a name="hasCondition2Anchor">hasCondition</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr>10881<tr><td colspan="4" class="doc" id="hasCondition2"><pre>Matches the condition expression of an if statement, for loop, while loop,10882do-while loop, switch statement or conditional operator.10883 10884Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true))))10885 if (true) {}10886</pre></td></tr>10887 10888 10889<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1WhileStmt.html">WhileStmt</a>></td><td class="name" onclick="toggle('hasConditionVariableStatement2')"><a name="hasConditionVariableStatement2Anchor">hasConditionVariableStatement</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html">DeclStmt</a>> InnerMatcher</td></tr>10890<tr><td colspan="4" class="doc" id="hasConditionVariableStatement2"><pre>Matches the condition variable statement in an if statement, for loop,10891while loop or switch statement.10892 10893Given10894 if (A* a = GetAPointer()) {}10895 for (; A* a = GetAPointer(); ) {}10896hasConditionVariableStatement(...)10897 matches both 'A* a = GetAPointer()'.10898</pre></td></tr>10899 10900<!--END_TRAVERSAL_MATCHERS -->10901</table>10902 10903</div>10904</body>10905</html>10906 10907 10908