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} 20</style> 21<script type="text/javascript"> 22function toggle(id) { 23 if (!id) return; 24 row = document.getElementById(id); 25 if (row.style.display != 'table-cell') 26 row.style.display = 'table-cell'; 27 else 28 row.style.display = 'none'; 29} 30</script> 31</head> 32<body onLoad="toggle(location.hash.substring(1, location.hash.length - 6))"> 33 34<!--#include virtual="../menu.html.incl"--> 35 36<div id="content"> 37 38<h1>AST Matcher Reference</h1> 39 40<p>This document shows all currently implemented matchers. The matchers are grouped 41by category and node type they match. You can click on matcher names to show the 42matcher's source documentation.</p> 43 44<p>There are three different basic categories of matchers: 45<ul> 46<li><a href="#decl-matchers">Node Matchers:</a> Matchers that match a specific type of AST node.</li> 47<li><a href="#narrowing-matchers">Narrowing Matchers:</a> Matchers that match attributes on AST nodes.</li> 48<li><a href="#traversal-matchers">Traversal Matchers:</a> Matchers that allow traversal between AST nodes.</li> 49</ul> 50</p> 51 52<p>Within each category the matchers are ordered by node type they match on. 53Note that if a matcher can match multiple node types, it will appear 54multiple times. This means that by searching for Matcher<Stmt> you can 55find all matchers that can be used to match on Stmt nodes.</p> 56 57<p>The exception to that rule are matchers that can match on any node. Those 58are marked with a * and are listed in the beginning of each category.</p> 59 60<p>Note that the categorization of matchers is a great help when you combine 61them into matcher expressions. You will usually want to form matcher expressions 62that read like english sentences by alternating between node matchers and 63narrowing or traversal matchers, like this: 64<pre> 65recordDecl(hasDescendant( 66 ifStmt(hasTrueExpression( 67 expr(hasDescendant( 68 ifStmt())))))) 69</pre> 70</p> 71 72<!-- ======================================================================= --> 73<h2 id="decl-matchers">Node Matchers</h2> 74<!-- ======================================================================= --> 75 76<p>Node matchers are at the core of matcher expressions - they specify the type 77of node that is expected. Every match expression starts with a node matcher, 78which can then be further refined with a narrowing or traversal matcher. All 79traversal matchers take node matchers as their arguments.</p> 80 81<p>For convenience, all node matchers take an arbitrary number of arguments 82and implicitly act as allOf matchers.</p> 83 84<p>Node matchers are the only matchers that support the bind("id") call to 85bind the matched node to the given string, to be later retrieved from the 86match callback.</p> 87 88<p>It is important to remember that the arguments to node matchers are 89predicates on the same node, just with additional information about the type. 90This is often useful to make matcher expression more readable by inlining bind 91calls into redundant node matchers inside another node matcher: 92<pre> 93// This binds the CXXRecordDecl to "id", as the decl() matcher will stay on 94// the same node. 95recordDecl(decl().bind("id"), hasName("::MyClass")) 96</pre> 97</p> 98 99<table> 100<tr style="text-align:left"><th>Return type</th><th>Name</th><th>Parameters</th></tr> 101<!-- START_DECL_MATCHERS --> 102 103<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> 104<tr><td colspan="4" class="doc" id="cxxCtorInitializer0"><pre>Matches constructor initializers. 105 106Examples matches i(42). 107 class C { 108 C() : i(42) {} 109 int i; 110 }; 111</pre></td></tr> 112 113 114<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> 115<tr><td colspan="4" class="doc" id="accessSpecDecl0"><pre>Matches C++ access specifier declarations. 116 117Given 118 class C { 119 public: 120 int a; 121 }; 122accessSpecDecl() 123 matches 'public:' 124</pre></td></tr> 125 126 127<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> 128<tr><td colspan="4" class="doc" id="blockDecl0"><pre>Matches block declarations. 129 130Example matches the declaration of the nameless block printing an input 131integer. 132 133 myFunc(^(int p) { 134 printf("%d", p); 135 }) 136</pre></td></tr> 137 138 139<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> 140<tr><td colspan="4" class="doc" id="classTemplateDecl0"><pre>Matches C++ class template declarations. 141 142Example matches Z 143 template<class T> class Z {}; 144</pre></td></tr> 145 146 147<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> 148<tr><td colspan="4" class="doc" id="classTemplatePartialSpecializationDecl0"><pre>Matches C++ class template partial specializations. 149 150Given 151 template<class T1, class T2, int I> 152 class A {}; 153 154 template<class T, int I> 155 class A<T, T*, I> {}; 156 157 template<> 158 class A<int, int, 1> {}; 159classTemplatePartialSpecializationDecl() 160 matches the specialization A<T,T*,I> but not A<int,int,1> 161</pre></td></tr> 162 163 164<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> 165<tr><td colspan="4" class="doc" id="classTemplateSpecializationDecl0"><pre>Matches C++ class template specializations. 166 167Given 168 template<typename T> class A {}; 169 template<> class A<double> {}; 170 A<int> a; 171classTemplateSpecializationDecl() 172 matches the specializations A<int> and A<double> 173</pre></td></tr> 174 175 176<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> 177<tr><td colspan="4" class="doc" id="cxxConstructorDecl0"><pre>Matches C++ constructor declarations. 178 179Example matches Foo::Foo() and Foo::Foo(int) 180 class Foo { 181 public: 182 Foo(); 183 Foo(int); 184 int DoSomething(); 185 }; 186</pre></td></tr> 187 188 189<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> 190<tr><td colspan="4" class="doc" id="cxxConversionDecl0"><pre>Matches conversion operator declarations. 191 192Example matches the operator. 193 class X { operator int() const; }; 194</pre></td></tr> 195 196 197<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> 198<tr><td colspan="4" class="doc" id="cxxDeductionGuideDecl0"><pre>Matches user-defined and implicitly generated deduction guide. 199 200Example matches the deduction guide. 201 template<typename T> 202 class X { X(int) }; 203 X(int) -> X<int>; 204</pre></td></tr> 205 206 207<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> 208<tr><td colspan="4" class="doc" id="cxxDestructorDecl0"><pre>Matches explicit C++ destructor declarations. 209 210Example matches Foo::~Foo() 211 class Foo { 212 public: 213 virtual ~Foo(); 214 }; 215</pre></td></tr> 216 217 218<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> 219<tr><td colspan="4" class="doc" id="cxxMethodDecl0"><pre>Matches method declarations. 220 221Example matches y 222 class X { void y(); }; 223</pre></td></tr> 224 225 226<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> 227<tr><td colspan="4" class="doc" id="cxxRecordDecl0"><pre>Matches C++ class declarations. 228 229Example matches X, Z 230 class X; 231 template<class T> class Z {}; 232</pre></td></tr> 233 234 235<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> 236<tr><td colspan="4" class="doc" id="decl0"><pre>Matches declarations. 237 238Examples matches X, C, and the friend declaration inside C; 239 void X(); 240 class C { 241 friend X; 242 }; 243</pre></td></tr> 244 245 246<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> 247<tr><td colspan="4" class="doc" id="declaratorDecl0"><pre>Matches declarator declarations (field, variable, function 248and non-type template parameter declarations). 249 250Given 251 class X { int y; }; 252declaratorDecl() 253 matches int y. 254</pre></td></tr> 255 256 257<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> 258<tr><td colspan="4" class="doc" id="enumConstantDecl0"><pre>Matches enum constants. 259 260Example matches A, B, C 261 enum X { 262 A, B, C 263 }; 264</pre></td></tr> 265 266 267<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> 268<tr><td colspan="4" class="doc" id="enumDecl0"><pre>Matches enum declarations. 269 270Example matches X 271 enum X { 272 A, B, C 273 }; 274</pre></td></tr> 275 276 277<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> 278<tr><td colspan="4" class="doc" id="fieldDecl0"><pre>Matches field declarations. 279 280Given 281 class X { int m; }; 282fieldDecl() 283 matches 'm'. 284</pre></td></tr> 285 286 287<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> 288<tr><td colspan="4" class="doc" id="friendDecl0"><pre>Matches friend declarations. 289 290Given 291 class X { friend void foo(); }; 292friendDecl() 293 matches 'friend void foo()'. 294</pre></td></tr> 295 296 297<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> 298<tr><td colspan="4" class="doc" id="functionDecl0"><pre>Matches function declarations. 299 300Example matches f 301 void f(); 302</pre></td></tr> 303 304 305<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> 306<tr><td colspan="4" class="doc" id="functionTemplateDecl0"><pre>Matches C++ function template declarations. 307 308Example matches f 309 template<class T> void f(T t) {} 310</pre></td></tr> 311 312 313<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> 314<tr><td colspan="4" class="doc" id="indirectFieldDecl0"><pre>Matches indirect field declarations. 315 316Given 317 struct X { struct { int a; }; }; 318indirectFieldDecl() 319 matches 'a'. 320</pre></td></tr> 321 322 323<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> 324<tr><td colspan="4" class="doc" id="labelDecl0"><pre>Matches a declaration of label. 325 326Given 327 goto FOO; 328 FOO: bar(); 329labelDecl() 330 matches 'FOO:' 331</pre></td></tr> 332 333 334<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> 335<tr><td colspan="4" class="doc" id="linkageSpecDecl0"><pre>Matches a declaration of a linkage specification. 336 337Given 338 extern "C" {} 339linkageSpecDecl() 340 matches "extern "C" {}" 341</pre></td></tr> 342 343 344<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> 345<tr><td colspan="4" class="doc" id="namedDecl0"><pre>Matches a declaration of anything that could have a name. 346 347Example matches X, S, the anonymous union type, i, and U; 348 typedef int X; 349 struct S { 350 union { 351 int i; 352 } U; 353 }; 354</pre></td></tr> 355 356 357<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> 358<tr><td colspan="4" class="doc" id="namespaceAliasDecl0"><pre>Matches a declaration of a namespace alias. 359 360Given 361 namespace test {} 362 namespace alias = ::test; 363namespaceAliasDecl() 364 matches "namespace alias" but not "namespace test" 365</pre></td></tr> 366 367 368<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> 369<tr><td colspan="4" class="doc" id="namespaceDecl0"><pre>Matches a declaration of a namespace. 370 371Given 372 namespace {} 373 namespace test {} 374namespaceDecl() 375 matches "namespace {}" and "namespace test {}" 376</pre></td></tr> 377 378 379<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> 380<tr><td colspan="4" class="doc" id="nonTypeTemplateParmDecl0"><pre>Matches non-type template parameter declarations. 381 382Given 383 template <typename T, int N> struct C {}; 384nonTypeTemplateParmDecl() 385 matches 'N', but not 'T'. 386</pre></td></tr> 387 388 389<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> 390<tr><td colspan="4" class="doc" id="objcCategoryDecl0"><pre>Matches Objective-C category declarations. 391 392Example matches Foo (Additions) 393 @interface Foo (Additions) 394 @end 395</pre></td></tr> 396 397 398<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> 399<tr><td colspan="4" class="doc" id="objcCategoryImplDecl0"><pre>Matches Objective-C category definitions. 400 401Example matches Foo (Additions) 402 @implementation Foo (Additions) 403 @end 404</pre></td></tr> 405 406 407<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> 408<tr><td colspan="4" class="doc" id="objcImplementationDecl0"><pre>Matches Objective-C implementation declarations. 409 410Example matches Foo 411 @implementation Foo 412 @end 413</pre></td></tr> 414 415 416<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> 417<tr><td colspan="4" class="doc" id="objcInterfaceDecl0"><pre>Matches Objective-C interface declarations. 418 419Example matches Foo 420 @interface Foo 421 @end 422</pre></td></tr> 423 424 425<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> 426<tr><td colspan="4" class="doc" id="objcIvarDecl0"><pre>Matches Objective-C instance variable declarations. 427 428Example matches _enabled 429 @implementation Foo { 430 BOOL _enabled; 431 } 432 @end 433</pre></td></tr> 434 435 436<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> 437<tr><td colspan="4" class="doc" id="objcMethodDecl0"><pre>Matches Objective-C method declarations. 438 439Example matches both declaration and definition of -[Foo method] 440 @interface Foo 441 - (void)method; 442 @end 443 444 @implementation Foo 445 - (void)method {} 446 @end 447</pre></td></tr> 448 449 450<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> 451<tr><td colspan="4" class="doc" id="objcPropertyDecl0"><pre>Matches Objective-C property declarations. 452 453Example matches enabled 454 @interface Foo 455 @property BOOL enabled; 456 @end 457</pre></td></tr> 458 459 460<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> 461<tr><td colspan="4" class="doc" id="objcProtocolDecl0"><pre>Matches Objective-C protocol declarations. 462 463Example matches FooDelegate 464 @protocol FooDelegate 465 @end 466</pre></td></tr> 467 468 469<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> 470<tr><td colspan="4" class="doc" id="parmVarDecl0"><pre>Matches parameter variable declarations. 471 472Given 473 void f(int x); 474parmVarDecl() 475 matches int x. 476</pre></td></tr> 477 478 479<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> 480<tr><td colspan="4" class="doc" id="recordDecl0"><pre>Matches class, struct, and union declarations. 481 482Example matches X, Z, U, and S 483 class X; 484 template<class T> class Z {}; 485 struct S {}; 486 union U {}; 487</pre></td></tr> 488 489 490<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> 491<tr><td colspan="4" class="doc" id="staticAssertDecl0"><pre>Matches a C++ static_assert declaration. 492 493Example: 494 staticAssertExpr() 495matches 496 static_assert(sizeof(S) == sizeof(int)) 497in 498 struct S { 499 int x; 500 }; 501 static_assert(sizeof(S) == sizeof(int)); 502</pre></td></tr> 503 504 505<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> 506<tr><td colspan="4" class="doc" id="tagDecl0"><pre>Matches tag declarations. 507 508Example matches X, Z, U, S, E 509 class X; 510 template<class T> class Z {}; 511 struct S {}; 512 union U {}; 513 enum E { 514 A, B, C 515 }; 516</pre></td></tr> 517 518 519<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> 520<tr><td colspan="4" class="doc" id="templateTypeParmDecl0"><pre>Matches template type parameter declarations. 521 522Given 523 template <typename T, int N> struct C {}; 524templateTypeParmDecl() 525 matches 'T', but not 'N'. 526</pre></td></tr> 527 528 529<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> 530<tr><td colspan="4" class="doc" id="translationUnitDecl0"><pre>Matches the top declaration context. 531 532Given 533 int X; 534 namespace NS { 535 int Y; 536 } // namespace NS 537decl(hasDeclContext(translationUnitDecl())) 538 matches "int X", but not "int Y". 539</pre></td></tr> 540 541 542<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> 543<tr><td colspan="4" class="doc" id="typeAliasDecl0"><pre>Matches type alias declarations. 544 545Given 546 typedef int X; 547 using Y = int; 548typeAliasDecl() 549 matches "using Y = int", but not "typedef int X" 550</pre></td></tr> 551 552 553<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> 554<tr><td colspan="4" class="doc" id="typeAliasTemplateDecl0"><pre>Matches type alias template declarations. 555 556typeAliasTemplateDecl() matches 557 template <typename T> 558 using Y = X<T>; 559</pre></td></tr> 560 561 562<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> 563<tr><td colspan="4" class="doc" id="typedefDecl0"><pre>Matches typedef declarations. 564 565Given 566 typedef int X; 567 using Y = int; 568typedefDecl() 569 matches "typedef int X", but not "using Y = int" 570</pre></td></tr> 571 572 573<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> 574<tr><td colspan="4" class="doc" id="typedefNameDecl0"><pre>Matches typedef name declarations. 575 576Given 577 typedef int X; 578 using Y = int; 579typedefNameDecl() 580 matches "typedef int X" and "using Y = int" 581</pre></td></tr> 582 583 584<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> 585<tr><td colspan="4" class="doc" id="unresolvedUsingTypenameDecl0"><pre>Matches unresolved using value declarations that involve the 586typename. 587 588Given 589 template <typename T> 590 struct Base { typedef T Foo; }; 591 592 template<typename T> 593 struct S : private Base<T> { 594 using typename Base<T>::Foo; 595 }; 596unresolvedUsingTypenameDecl() 597 matches using Base<T>::Foo </pre></td></tr> 598 599 600<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> 601<tr><td colspan="4" class="doc" id="unresolvedUsingValueDecl0"><pre>Matches unresolved using value declarations. 602 603Given 604 template<typename X> 605 class C : private X { 606 using X::x; 607 }; 608unresolvedUsingValueDecl() 609 matches using X::x </pre></td></tr> 610 611 612<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> 613<tr><td colspan="4" class="doc" id="usingDecl0"><pre>Matches using declarations. 614 615Given 616 namespace X { int x; } 617 using X::x; 618usingDecl() 619 matches using X::x </pre></td></tr> 620 621 622<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> 623<tr><td colspan="4" class="doc" id="usingDirectiveDecl0"><pre>Matches using namespace declarations. 624 625Given 626 namespace X { int x; } 627 using namespace X; 628usingDirectiveDecl() 629 matches using namespace X </pre></td></tr> 630 631 632<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> 633<tr><td colspan="4" class="doc" id="valueDecl0"><pre>Matches any value declaration. 634 635Example matches A, B, C and F 636 enum X { A, B, C }; 637 void F(); 638</pre></td></tr> 639 640 641<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> 642<tr><td colspan="4" class="doc" id="varDecl0"><pre>Matches variable declarations. 643 644Note: this does not match declarations of member variables, which are 645"field" declarations in Clang parlance. 646 647Example matches a 648 int a; 649</pre></td></tr> 650 651 652<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> 653<tr><td colspan="4" class="doc" id="nestedNameSpecifierLoc0"><pre>Same as nestedNameSpecifier but matches NestedNameSpecifierLoc. 654</pre></td></tr> 655 656 657<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> 658<tr><td colspan="4" class="doc" id="nestedNameSpecifier0"><pre>Matches nested name specifiers. 659 660Given 661 namespace ns { 662 struct A { static void f(); }; 663 void A::f() {} 664 void g() { A::f(); } 665 } 666 ns::A a; 667nestedNameSpecifier() 668 matches "ns::" and both "A::" 669</pre></td></tr> 670 671 672<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> 673<tr><td colspan="4" class="doc" id="ompDefaultClause0"><pre>Matches OpenMP ``default`` clause. 674 675Given 676 677 #pragma omp parallel default(none) 678 #pragma omp parallel default(shared) 679 #pragma omp parallel 680 681``ompDefaultClause()`` matches ``default(none)`` and ``default(shared)``. 682</pre></td></tr> 683 684 685<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> 686<tr><td colspan="4" class="doc" id="qualType0"><pre>Matches QualTypes in the clang AST. 687</pre></td></tr> 688 689 690<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> 691<tr><td colspan="4" class="doc" id="addrLabelExpr0"><pre>Matches address of label statements (GNU extension). 692 693Given 694 FOO: bar(); 695 void *ptr = &&FOO; 696 goto *bar; 697addrLabelExpr() 698 matches '&&FOO' 699</pre></td></tr> 700 701 702<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> 703<tr><td colspan="4" class="doc" id="arraySubscriptExpr0"><pre>Matches array subscript expressions. 704 705Given 706 int i = a[1]; 707arraySubscriptExpr() 708 matches "a[1]" 709</pre></td></tr> 710 711 712<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> 713<tr><td colspan="4" class="doc" id="asmStmt0"><pre>Matches asm statements. 714 715 int i = 100; 716 __asm("mov al, 2"); 717asmStmt() 718 matches '__asm("mov al, 2")' 719</pre></td></tr> 720 721 722<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> 723<tr><td colspan="4" class="doc" id="atomicExpr0"><pre>Matches atomic builtins. 724Example matches __atomic_load_n(ptr, 1) 725 void foo() { int *ptr; __atomic_load_n(ptr, 1); } 726</pre></td></tr> 727 728 729<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> 730<tr><td colspan="4" class="doc" id="autoreleasePoolStmt0"><pre>Matches an Objective-C autorelease pool statement. 731 732Given 733 @autoreleasepool { 734 int x = 0; 735 } 736autoreleasePoolStmt(stmt()) matches the declaration of "x" 737inside the autorelease pool. 738</pre></td></tr> 739 740 741<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> 742<tr><td colspan="4" class="doc" id="binaryConditionalOperator0"><pre>Matches binary conditional operator expressions (GNU extension). 743 744Example matches a ?: b 745 (a ?: b) + 42; 746</pre></td></tr> 747 748 749<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> 750<tr><td colspan="4" class="doc" id="binaryOperator0"><pre>Matches binary operator expressions. 751 752Example matches a || b 753 !(a || b) 754</pre></td></tr> 755 756 757<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> 758<tr><td colspan="4" class="doc" id="blockExpr0"><pre>Matches a reference to a block. 759 760Example: matches "^{}": 761 void f() { ^{}(); } 762</pre></td></tr> 763 764 765<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> 766<tr><td colspan="4" class="doc" id="breakStmt0"><pre>Matches break statements. 767 768Given 769 while (true) { break; } 770breakStmt() 771 matches 'break' 772</pre></td></tr> 773 774 775<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> 776<tr><td colspan="4" class="doc" id="cStyleCastExpr0"><pre>Matches a C-style cast expression. 777 778Example: Matches (int) 2.2f in 779 int i = (int) 2.2f; 780</pre></td></tr> 781 782 783<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> 784<tr><td colspan="4" class="doc" id="callExpr0"><pre>Matches call expressions. 785 786Example matches x.y() and y() 787 X x; 788 x.y(); 789 y(); 790</pre></td></tr> 791 792 793<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> 794<tr><td colspan="4" class="doc" id="caseStmt0"><pre>Matches case statements inside switch statements. 795 796Given 797 switch(a) { case 42: break; default: break; } 798caseStmt() 799 matches 'case 42:'. 800</pre></td></tr> 801 802 803<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> 804<tr><td colspan="4" class="doc" id="castExpr0"><pre>Matches any cast nodes of Clang's AST. 805 806Example: castExpr() matches each of the following: 807 (int) 3; 808 const_cast<Expr *>(SubExpr); 809 char c = 0; 810but does not match 811 int i = (0); 812 int k = 0; 813</pre></td></tr> 814 815 816<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> 817<tr><td colspan="4" class="doc" id="characterLiteral0"><pre>Matches character literals (also matches wchar_t). 818 819Not matching Hex-encoded chars (e.g. 0x1234, which is a IntegerLiteral), 820though. 821 822Example matches 'a', L'a' 823 char ch = 'a'; 824 wchar_t chw = L'a'; 825</pre></td></tr> 826 827 828<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> 829<tr><td colspan="4" class="doc" id="chooseExpr0"><pre>Matches GNU __builtin_choose_expr. 830</pre></td></tr> 831 832 833<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> 834<tr><td colspan="4" class="doc" id="compoundLiteralExpr0"><pre>Matches compound (i.e. non-scalar) literals 835 836Example match: {1}, (1, 2) 837 int array[4] = {1}; 838 vector int myvec = (vector int)(1, 2); 839</pre></td></tr> 840 841 842<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> 843<tr><td colspan="4" class="doc" id="compoundStmt0"><pre>Matches compound statements. 844 845Example matches '{}' and '{{}}' in 'for (;;) {{}}' 846 for (;;) {{}} 847</pre></td></tr> 848 849 850<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> 851<tr><td colspan="4" class="doc" id="conditionalOperator0"><pre>Matches conditional operator expressions. 852 853Example matches a ? b : c 854 (a ? b : c) + 42 855</pre></td></tr> 856 857 858<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> 859<tr><td colspan="4" class="doc" id="constantExpr0"><pre>Matches a constant expression wrapper. 860 861Example matches the constant in the case statement: 862 (matcher = constantExpr()) 863 switch (a) { 864 case 37: break; 865 } 866</pre></td></tr> 867 868 869<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> 870<tr><td colspan="4" class="doc" id="continueStmt0"><pre>Matches continue statements. 871 872Given 873 while (true) { continue; } 874continueStmt() 875 matches 'continue' 876</pre></td></tr> 877 878 879<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> 880<tr><td colspan="4" class="doc" id="cudaKernelCallExpr0"><pre>Matches CUDA kernel call expression. 881 882Example matches, 883 kernel<<<i,j>>>(); 884</pre></td></tr> 885 886 887<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> 888<tr><td colspan="4" class="doc" id="cxxBindTemporaryExpr0"><pre>Matches nodes where temporaries are created. 889 890Example matches FunctionTakesString(GetStringByValue()) 891 (matcher = cxxBindTemporaryExpr()) 892 FunctionTakesString(GetStringByValue()); 893 FunctionTakesStringByPointer(GetStringPointer()); 894</pre></td></tr> 895 896 897<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> 898<tr><td colspan="4" class="doc" id="cxxBoolLiteral0"><pre>Matches bool literals. 899 900Example matches true 901 true 902</pre></td></tr> 903 904 905<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> 906<tr><td colspan="4" class="doc" id="cxxCatchStmt0"><pre>Matches catch statements. 907 908 try {} catch(int i) {} 909cxxCatchStmt() 910 matches 'catch(int i)' 911</pre></td></tr> 912 913 914<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> 915<tr><td colspan="4" class="doc" id="cxxConstCastExpr0"><pre>Matches a const_cast expression. 916 917Example: Matches const_cast<int*>(&r) in 918 int n = 42; 919 const int &r(n); 920 int* p = const_cast<int*>(&r); 921</pre></td></tr> 922 923 924<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> 925<tr><td colspan="4" class="doc" id="cxxConstructExpr0"><pre>Matches constructor call expressions (including implicit ones). 926 927Example matches string(ptr, n) and ptr within arguments of f 928 (matcher = cxxConstructExpr()) 929 void f(const string &a, const string &b); 930 char *ptr; 931 int n; 932 f(string(ptr, n), ptr); 933</pre></td></tr> 934 935 936<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> 937<tr><td colspan="4" class="doc" id="cxxDefaultArgExpr0"><pre>Matches the value of a default argument at the call site. 938 939Example matches the CXXDefaultArgExpr placeholder inserted for the 940 default value of the second parameter in the call expression f(42) 941 (matcher = cxxDefaultArgExpr()) 942 void f(int x, int y = 0); 943 f(42); 944</pre></td></tr> 945 946 947<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> 948<tr><td colspan="4" class="doc" id="cxxDeleteExpr0"><pre>Matches delete expressions. 949 950Given 951 delete X; 952cxxDeleteExpr() 953 matches 'delete X'. 954</pre></td></tr> 955 956 957<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> 958<tr><td colspan="4" class="doc" id="cxxDependentScopeMemberExpr0"><pre>Matches member expressions where the actual member referenced could not be 959resolved because the base expression or the member name was dependent. 960 961Given 962 template <class T> void f() { T t; t.g(); } 963cxxDependentScopeMemberExpr() 964 matches t.g 965</pre></td></tr> 966 967 968<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> 969<tr><td colspan="4" class="doc" id="cxxDynamicCastExpr0"><pre>Matches a dynamic_cast expression. 970 971Example: 972 cxxDynamicCastExpr() 973matches 974 dynamic_cast<D*>(&b); 975in 976 struct B { virtual ~B() {} }; struct D : B {}; 977 B b; 978 D* p = dynamic_cast<D*>(&b); 979</pre></td></tr> 980 981 982<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> 983<tr><td colspan="4" class="doc" id="cxxForRangeStmt0"><pre>Matches range-based for statements. 984 985cxxForRangeStmt() matches 'for (auto a : i)' 986 int i[] = {1, 2, 3}; for (auto a : i); 987 for(int j = 0; j < 5; ++j); 988</pre></td></tr> 989 990 991<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> 992<tr><td colspan="4" class="doc" id="cxxFunctionalCastExpr0"><pre>Matches functional cast expressions 993 994Example: Matches Foo(bar); 995 Foo f = bar; 996 Foo g = (Foo) bar; 997 Foo h = Foo(bar); 998</pre></td></tr> 999 1000 1001<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> 1002<tr><td colspan="4" class="doc" id="cxxMemberCallExpr0"><pre>Matches member call expressions. 1003 1004Example matches x.y() 1005 X x; 1006 x.y(); 1007</pre></td></tr> 1008 1009 1010<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> 1011<tr><td colspan="4" class="doc" id="cxxNewExpr0"><pre>Matches new expressions. 1012 1013Given 1014 new X; 1015cxxNewExpr() 1016 matches 'new X'. 1017</pre></td></tr> 1018 1019 1020<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> 1021<tr><td colspan="4" class="doc" id="cxxNoexceptExpr0"><pre>Matches noexcept expressions. 1022 1023Given 1024 bool a() noexcept; 1025 bool b() noexcept(true); 1026 bool c() noexcept(false); 1027 bool d() noexcept(noexcept(a())); 1028 bool e = noexcept(b()) || noexcept(c()); 1029cxxNoexceptExpr() 1030 matches `noexcept(a())`, `noexcept(b())` and `noexcept(c())`. 1031 doesn't match the noexcept specifier in the declarations a, b, c or d. 1032</pre></td></tr> 1033 1034 1035<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> 1036<tr><td colspan="4" class="doc" id="cxxNullPtrLiteralExpr0"><pre>Matches nullptr literal. 1037</pre></td></tr> 1038 1039 1040<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> 1041<tr><td colspan="4" class="doc" id="cxxOperatorCallExpr0"><pre>Matches overloaded operator calls. 1042 1043Note that if an operator isn't overloaded, it won't match. Instead, use 1044binaryOperator matcher. 1045Currently it does not match operators such as new delete. 1046FIXME: figure out why these do not match? 1047 1048Example matches both operator<<((o << b), c) and operator<<(o, b) 1049 (matcher = cxxOperatorCallExpr()) 1050 ostream &operator<< (ostream &out, int i) { }; 1051 ostream &o; int b = 1, c = 1; 1052 o << b << c; 1053</pre></td></tr> 1054 1055 1056<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> 1057<tr><td colspan="4" class="doc" id="cxxReinterpretCastExpr0"><pre>Matches a reinterpret_cast expression. 1058 1059Either the source expression or the destination type can be matched 1060using has(), but hasDestinationType() is more specific and can be 1061more readable. 1062 1063Example matches reinterpret_cast<char*>(&p) in 1064 void* p = reinterpret_cast<char*>(&p); 1065</pre></td></tr> 1066 1067 1068<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> 1069<tr><td colspan="4" class="doc" id="cxxStaticCastExpr0"><pre>Matches a C++ static_cast expression. 1070 1071See also: hasDestinationType 1072See also: reinterpretCast 1073 1074Example: 1075 cxxStaticCastExpr() 1076matches 1077 static_cast<long>(8) 1078in 1079 long eight(static_cast<long>(8)); 1080</pre></td></tr> 1081 1082 1083<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> 1084<tr><td colspan="4" class="doc" id="cxxStdInitializerListExpr0"><pre>Matches C++ initializer list expressions. 1085 1086Given 1087 std::vector<int> a({ 1, 2, 3 }); 1088 std::vector<int> b = { 4, 5 }; 1089 int c[] = { 6, 7 }; 1090 std::pair<int, int> d = { 8, 9 }; 1091cxxStdInitializerListExpr() 1092 matches "{ 1, 2, 3 }" and "{ 4, 5 }" 1093</pre></td></tr> 1094 1095 1096<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> 1097<tr><td colspan="4" class="doc" id="cxxTemporaryObjectExpr0"><pre>Matches functional cast expressions having N != 1 arguments 1098 1099Example: Matches Foo(bar, bar) 1100 Foo h = Foo(bar, bar); 1101</pre></td></tr> 1102 1103 1104<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> 1105<tr><td colspan="4" class="doc" id="cxxThisExpr0"><pre>Matches implicit and explicit this expressions. 1106 1107Example matches the implicit this expression in "return i". 1108 (matcher = cxxThisExpr()) 1109struct foo { 1110 int i; 1111 int f() { return i; } 1112}; 1113</pre></td></tr> 1114 1115 1116<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> 1117<tr><td colspan="4" class="doc" id="cxxThrowExpr0"><pre>Matches throw expressions. 1118 1119 try { throw 5; } catch(int i) {} 1120cxxThrowExpr() 1121 matches 'throw 5' 1122</pre></td></tr> 1123 1124 1125<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> 1126<tr><td colspan="4" class="doc" id="cxxTryStmt0"><pre>Matches try statements. 1127 1128 try {} catch(int i) {} 1129cxxTryStmt() 1130 matches 'try {}' 1131</pre></td></tr> 1132 1133 1134<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> 1135<tr><td colspan="4" class="doc" id="cxxUnresolvedConstructExpr0"><pre>Matches unresolved constructor call expressions. 1136 1137Example matches T(t) in return statement of f 1138 (matcher = cxxUnresolvedConstructExpr()) 1139 template <typename T> 1140 void f(const T& t) { return T(t); } 1141</pre></td></tr> 1142 1143 1144<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> 1145<tr><td colspan="4" class="doc" id="declRefExpr0"><pre>Matches expressions that refer to declarations. 1146 1147Example matches x in if (x) 1148 bool x; 1149 if (x) {} 1150</pre></td></tr> 1151 1152 1153<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> 1154<tr><td colspan="4" class="doc" id="declStmt0"><pre>Matches declaration statements. 1155 1156Given 1157 int a; 1158declStmt() 1159 matches 'int a'. 1160</pre></td></tr> 1161 1162 1163<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> 1164<tr><td colspan="4" class="doc" id="defaultStmt0"><pre>Matches default statements inside switch statements. 1165 1166Given 1167 switch(a) { case 42: break; default: break; } 1168defaultStmt() 1169 matches 'default:'. 1170</pre></td></tr> 1171 1172 1173<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> 1174<tr><td colspan="4" class="doc" id="designatedInitExpr0"><pre>Matches C99 designated initializer expressions [C99 6.7.8]. 1175 1176Example: Matches { [2].y = 1.0, [0].x = 1.0 } 1177 point ptarray[10] = { [2].y = 1.0, [0].x = 1.0 }; 1178</pre></td></tr> 1179 1180 1181<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> 1182<tr><td colspan="4" class="doc" id="doStmt0"><pre>Matches do statements. 1183 1184Given 1185 do {} while (true); 1186doStmt() 1187 matches 'do {} while(true)' 1188</pre></td></tr> 1189 1190 1191<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> 1192<tr><td colspan="4" class="doc" id="explicitCastExpr0"><pre>Matches explicit cast expressions. 1193 1194Matches any cast expression written in user code, whether it be a 1195C-style cast, a functional-style cast, or a keyword cast. 1196 1197Does not match implicit conversions. 1198 1199Note: the name "explicitCast" is chosen to match Clang's terminology, as 1200Clang uses the term "cast" to apply to implicit conversions as well as to 1201actual cast expressions. 1202 1203See also: hasDestinationType. 1204 1205Example: matches all five of the casts in 1206 int((int)(reinterpret_cast<int>(static_cast<int>(const_cast<int>(42))))) 1207but does not match the implicit conversion in 1208 long ell = 42; 1209</pre></td></tr> 1210 1211 1212<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> 1213<tr><td colspan="4" class="doc" id="expr0"><pre>Matches expressions. 1214 1215Example matches x() 1216 void f() { x(); } 1217</pre></td></tr> 1218 1219 1220<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> 1221<tr><td colspan="4" class="doc" id="exprWithCleanups0"><pre>Matches expressions that introduce cleanups to be run at the end 1222of the sub-expression's evaluation. 1223 1224Example matches std::string() 1225 const std::string str = std::string(); 1226</pre></td></tr> 1227 1228 1229<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> 1230<tr><td colspan="4" class="doc" id="floatLiteral0"><pre>Matches float literals of all sizes / encodings, e.g. 12311.0, 1.0f, 1.0L and 1e10. 1232 1233Does not match implicit conversions such as 1234 float a = 10; 1235</pre></td></tr> 1236 1237 1238<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> 1239<tr><td colspan="4" class="doc" id="forStmt0"><pre>Matches for statements. 1240 1241Example matches 'for (;;) {}' 1242 for (;;) {} 1243 int i[] = {1, 2, 3}; for (auto a : i); 1244</pre></td></tr> 1245 1246 1247<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> 1248<tr><td colspan="4" class="doc" id="gnuNullExpr0"><pre>Matches GNU __null expression. 1249</pre></td></tr> 1250 1251 1252<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> 1253<tr><td colspan="4" class="doc" id="gotoStmt0"><pre>Matches goto statements. 1254 1255Given 1256 goto FOO; 1257 FOO: bar(); 1258gotoStmt() 1259 matches 'goto FOO' 1260</pre></td></tr> 1261 1262 1263<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> 1264<tr><td colspan="4" class="doc" id="ifStmt0"><pre>Matches if statements. 1265 1266Example matches 'if (x) {}' 1267 if (x) {} 1268</pre></td></tr> 1269 1270 1271<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> 1272<tr><td colspan="4" class="doc" id="imaginaryLiteral0"><pre>Matches imaginary literals, which are based on integer and floating 1273point literals e.g.: 1i, 1.0i 1274</pre></td></tr> 1275 1276 1277<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> 1278<tr><td colspan="4" class="doc" id="implicitCastExpr0"><pre>Matches the implicit cast nodes of Clang's AST. 1279 1280This matches many different places, including function call return value 1281eliding, as well as any type conversions. 1282</pre></td></tr> 1283 1284 1285<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> 1286<tr><td colspan="4" class="doc" id="implicitValueInitExpr0"><pre>Matches implicit initializers of init list expressions. 1287 1288Given 1289 point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 }; 1290implicitValueInitExpr() 1291 matches "[0].y" (implicitly) 1292</pre></td></tr> 1293 1294 1295<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> 1296<tr><td colspan="4" class="doc" id="initListExpr0"><pre>Matches init list expressions. 1297 1298Given 1299 int a[] = { 1, 2 }; 1300 struct B { int x, y; }; 1301 B b = { 5, 6 }; 1302initListExpr() 1303 matches "{ 1, 2 }" and "{ 5, 6 }" 1304</pre></td></tr> 1305 1306 1307<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> 1308<tr><td colspan="4" class="doc" id="integerLiteral0"><pre>Matches integer literals of all sizes / encodings, e.g. 13091, 1L, 0x1 and 1U. 1310 1311Does not match character-encoded integers such as L'a'. 1312</pre></td></tr> 1313 1314 1315<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> 1316<tr><td colspan="4" class="doc" id="labelStmt0"><pre>Matches label statements. 1317 1318Given 1319 goto FOO; 1320 FOO: bar(); 1321labelStmt() 1322 matches 'FOO:' 1323</pre></td></tr> 1324 1325 1326<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> 1327<tr><td colspan="4" class="doc" id="lambdaExpr0"><pre>Matches lambda expressions. 1328 1329Example matches [&](){return 5;} 1330 [&](){return 5;} 1331</pre></td></tr> 1332 1333 1334<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> 1335<tr><td colspan="4" class="doc" id="materializeTemporaryExpr0"><pre>Matches nodes where temporaries are materialized. 1336 1337Example: Given 1338 struct T {void func();}; 1339 T f(); 1340 void g(T); 1341materializeTemporaryExpr() matches 'f()' in these statements 1342 T u(f()); 1343 g(f()); 1344 f().func(); 1345but does not match 1346 f(); 1347</pre></td></tr> 1348 1349 1350<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> 1351<tr><td colspan="4" class="doc" id="memberExpr0"><pre>Matches member expressions. 1352 1353Given 1354 class Y { 1355 void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; } 1356 int a; static int b; 1357 }; 1358memberExpr() 1359 matches this->x, x, y.x, a, this->b 1360</pre></td></tr> 1361 1362 1363<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> 1364<tr><td colspan="4" class="doc" id="nullStmt0"><pre>Matches null statements. 1365 1366 foo();; 1367nullStmt() 1368 matches the second ';' 1369</pre></td></tr> 1370 1371 1372<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> 1373<tr><td colspan="4" class="doc" id="objcCatchStmt0"><pre>Matches Objective-C @catch statements. 1374 1375Example matches @catch 1376 @try {} 1377 @catch (...) {} 1378</pre></td></tr> 1379 1380 1381<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> 1382<tr><td colspan="4" class="doc" id="objcFinallyStmt0"><pre>Matches Objective-C @finally statements. 1383 1384Example matches @finally 1385 @try {} 1386 @finally {} 1387</pre></td></tr> 1388 1389 1390<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> 1391<tr><td colspan="4" class="doc" id="objcIvarRefExpr0"><pre>Matches a reference to an ObjCIvar. 1392 1393Example: matches "a" in "init" method: 1394@implementation A { 1395 NSString *a; 1396} 1397- (void) init { 1398 a = @"hello"; 1399} 1400</pre></td></tr> 1401 1402 1403<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> 1404<tr><td colspan="4" class="doc" id="objcMessageExpr0"><pre>Matches ObjectiveC Message invocation expressions. 1405 1406The innermost message send invokes the "alloc" class method on the 1407NSString class, while the outermost message send invokes the 1408"initWithString" instance method on the object returned from 1409NSString's "alloc". This matcher should match both message sends. 1410 [[NSString alloc] initWithString:@"Hello"] 1411</pre></td></tr> 1412 1413 1414<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> 1415<tr><td colspan="4" class="doc" id="objcThrowStmt0"><pre>Matches Objective-C statements. 1416 1417Example matches @throw obj; 1418</pre></td></tr> 1419 1420 1421<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> 1422<tr><td colspan="4" class="doc" id="objcTryStmt0"><pre>Matches Objective-C @try statements. 1423 1424Example matches @try 1425 @try {} 1426 @catch (...) {} 1427</pre></td></tr> 1428 1429 1430<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<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPExecutableDirective.html">OMPExecutableDirective</a>>...</td></tr> 1431<tr><td colspan="4" class="doc" id="ompExecutableDirective0"><pre>Matches any ``#pragma omp`` executable directive. 1432 1433Given 1434 1435 #pragma omp parallel 1436 #pragma omp parallel default(none) 1437 #pragma omp taskyield 1438 1439``ompExecutableDirective()`` matches ``omp parallel``, 1440``omp parallel default(none)`` and ``omp taskyield``. 1441</pre></td></tr> 1442 1443 1444<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> 1445<tr><td colspan="4" class="doc" id="opaqueValueExpr0"><pre>Matches opaque value expressions. They are used as helpers 1446to reference another expressions and can be met 1447in BinaryConditionalOperators, for example. 1448 1449Example matches 'a' 1450 (a ?: c) + 42; 1451</pre></td></tr> 1452 1453 1454<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> 1455<tr><td colspan="4" class="doc" id="parenExpr0"><pre>Matches parentheses used in expressions. 1456 1457Example matches (foo() + 1) 1458 int foo() { return 1; } 1459 int a = (foo() + 1); 1460</pre></td></tr> 1461 1462 1463<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> 1464<tr><td colspan="4" class="doc" id="parenListExpr0"><pre>Matches paren list expressions. 1465ParenListExprs don't have a predefined type and are used for late parsing. 1466In the final AST, they can be met in template declarations. 1467 1468Given 1469 template<typename T> class X { 1470 void f() { 1471 X x(*this); 1472 int a = 0, b = 1; int i = (a, b); 1473 } 1474 }; 1475parenListExpr() matches "*this" but NOT matches (a, b) because (a, b) 1476has a predefined type and is a ParenExpr, not a ParenListExpr. 1477</pre></td></tr> 1478 1479 1480<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> 1481<tr><td colspan="4" class="doc" id="predefinedExpr0"><pre>Matches predefined identifier expressions [C99 6.4.2.2]. 1482 1483Example: Matches __func__ 1484 printf("%s", __func__); 1485</pre></td></tr> 1486 1487 1488<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> 1489<tr><td colspan="4" class="doc" id="returnStmt0"><pre>Matches return statements. 1490 1491Given 1492 return 1; 1493returnStmt() 1494 matches 'return 1' 1495</pre></td></tr> 1496 1497 1498<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> 1499<tr><td colspan="4" class="doc" id="stmt0"><pre>Matches statements. 1500 1501Given 1502 { ++a; } 1503stmt() 1504 matches both the compound statement '{ ++a; }' and '++a'. 1505</pre></td></tr> 1506 1507 1508<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> 1509<tr><td colspan="4" class="doc" id="stmtExpr0"><pre>Matches statement expression (GNU extension). 1510 1511Example match: ({ int X = 4; X; }) 1512 int C = ({ int X = 4; X; }); 1513</pre></td></tr> 1514 1515 1516<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> 1517<tr><td colspan="4" class="doc" id="stringLiteral0"><pre>Matches string literals (also matches wide string literals). 1518 1519Example matches "abcd", L"abcd" 1520 char *s = "abcd"; 1521 wchar_t *ws = L"abcd"; 1522</pre></td></tr> 1523 1524 1525<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> 1526<tr><td colspan="4" class="doc" id="substNonTypeTemplateParmExpr0"><pre>Matches substitutions of non-type template parameters. 1527 1528Given 1529 template <int N> 1530 struct A { static const int n = N; }; 1531 struct B : public A<42> {}; 1532substNonTypeTemplateParmExpr() 1533 matches "N" in the right-hand side of "static const int n = N;" 1534</pre></td></tr> 1535 1536 1537<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> 1538<tr><td colspan="4" class="doc" id="switchCase0"><pre>Matches case and default statements inside switch statements. 1539 1540Given 1541 switch(a) { case 42: break; default: break; } 1542switchCase() 1543 matches 'case 42:' and 'default:'. 1544</pre></td></tr> 1545 1546 1547<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> 1548<tr><td colspan="4" class="doc" id="switchStmt0"><pre>Matches switch statements. 1549 1550Given 1551 switch(a) { case 42: break; default: break; } 1552switchStmt() 1553 matches 'switch(a)'. 1554</pre></td></tr> 1555 1556 1557<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> 1558<tr><td colspan="4" class="doc" id="unaryExprOrTypeTraitExpr0"><pre>Matches sizeof (C99), alignof (C++11) and vec_step (OpenCL) 1559 1560Given 1561 Foo x = bar; 1562 int y = sizeof(x) + alignof(x); 1563unaryExprOrTypeTraitExpr() 1564 matches sizeof(x) and alignof(x) 1565</pre></td></tr> 1566 1567 1568<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> 1569<tr><td colspan="4" class="doc" id="unaryOperator0"><pre>Matches unary operator expressions. 1570 1571Example matches !a 1572 !a || b 1573</pre></td></tr> 1574 1575 1576<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> 1577<tr><td colspan="4" class="doc" id="unresolvedLookupExpr0"><pre>Matches reference to a name that can be looked up during parsing 1578but could not be resolved to a specific declaration. 1579 1580Given 1581 template<typename T> 1582 T foo() { T a; return a; } 1583 template<typename T> 1584 void bar() { 1585 foo<T>(); 1586 } 1587unresolvedLookupExpr() 1588 matches foo<T>() </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('unresolvedMemberExpr0')"><a name="unresolvedMemberExpr0Anchor">unresolvedMemberExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedMemberExpr.html">UnresolvedMemberExpr</a>>...</td></tr> 1592<tr><td colspan="4" class="doc" id="unresolvedMemberExpr0"><pre>Matches unresolved member expressions. 1593 1594Given 1595 struct X { 1596 template <class T> void f(); 1597 void g(); 1598 }; 1599 template <class T> void h() { X x; x.f<T>(); x.g(); } 1600unresolvedMemberExpr() 1601 matches x.f<T> 1602</pre></td></tr> 1603 1604 1605<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> 1606<tr><td colspan="4" class="doc" id="userDefinedLiteral0"><pre>Matches user defined literal operator call. 1607 1608Example match: "foo"_suffix 1609</pre></td></tr> 1610 1611 1612<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> 1613<tr><td colspan="4" class="doc" id="whileStmt0"><pre>Matches while statements. 1614 1615Given 1616 while (true) {} 1617whileStmt() 1618 matches 'while (true) {}'. 1619</pre></td></tr> 1620 1621 1622<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> 1623<tr><td colspan="4" class="doc" id="templateArgument0"><pre>Matches template arguments. 1624 1625Given 1626 template <typename T> struct C {}; 1627 C<int> c; 1628templateArgument() 1629 matches 'int' in C<int>. 1630</pre></td></tr> 1631 1632 1633<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> 1634<tr><td colspan="4" class="doc" id="templateName0"><pre>Matches template name. 1635 1636Given 1637 template <typename T> class X { }; 1638 X<int> xi; 1639templateName() 1640 matches 'X' in X<int>. 1641</pre></td></tr> 1642 1643 1644<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> 1645<tr><td colspan="4" class="doc" id="typeLoc0"><pre>Matches TypeLocs in the clang AST. 1646</pre></td></tr> 1647 1648 1649<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> 1650<tr><td colspan="4" class="doc" id="arrayType0"><pre>Matches all kinds of arrays. 1651 1652Given 1653 int a[] = { 2, 3 }; 1654 int b[4]; 1655 void f() { int c[a[0]]; } 1656arrayType() 1657 matches "int a[]", "int b[4]" and "int c[a[0]]"; 1658</pre></td></tr> 1659 1660 1661<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> 1662<tr><td colspan="4" class="doc" id="atomicType0"><pre>Matches atomic types. 1663 1664Given 1665 _Atomic(int) i; 1666atomicType() 1667 matches "_Atomic(int) i" 1668</pre></td></tr> 1669 1670 1671<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<<a href="https://clang.llvm.org/doxygen/classclang_1_1AutoType.html">AutoType</a>>...</td></tr> 1672<tr><td colspan="4" class="doc" id="autoType0"><pre>Matches types nodes representing C++11 auto types. 1673 1674Given: 1675 auto n = 4; 1676 int v[] = { 2, 3 } 1677 for (auto i : v) { } 1678autoType() 1679 matches "auto n" and "auto i" 1680</pre></td></tr> 1681 1682 1683<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> 1684<tr><td colspan="4" class="doc" id="blockPointerType0"><pre>Matches block pointer types, i.e. types syntactically represented as 1685"void (^)(int)". 1686 1687The pointee is always required to be a FunctionType. 1688</pre></td></tr> 1689 1690 1691<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> 1692<tr><td colspan="4" class="doc" id="builtinType0"><pre>Matches builtin Types. 1693 1694Given 1695 struct A {}; 1696 A a; 1697 int b; 1698 float c; 1699 bool d; 1700builtinType() 1701 matches "int b", "float c" and "bool d" 1702</pre></td></tr> 1703 1704 1705<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> 1706<tr><td colspan="4" class="doc" id="complexType0"><pre>Matches C99 complex types. 1707 1708Given 1709 _Complex float f; 1710complexType() 1711 matches "_Complex float f" 1712</pre></td></tr> 1713 1714 1715<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> 1716<tr><td colspan="4" class="doc" id="constantArrayType0"><pre>Matches C arrays with a specified constant size. 1717 1718Given 1719 void() { 1720 int a[2]; 1721 int b[] = { 2, 3 }; 1722 int c[b[0]]; 1723 } 1724constantArrayType() 1725 matches "int a[2]" 1726</pre></td></tr> 1727 1728 1729<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> 1730<tr><td colspan="4" class="doc" id="decayedType0"><pre>Matches decayed type 1731Example matches i[] in declaration of f. 1732 (matcher = valueDecl(hasType(decayedType(hasDecayedType(pointerType()))))) 1733Example matches i[1]. 1734 (matcher = expr(hasType(decayedType(hasDecayedType(pointerType()))))) 1735 void f(int i[]) { 1736 i[1] = 0; 1737 } 1738</pre></td></tr> 1739 1740 1741<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<<a href="https://clang.llvm.org/doxygen/classclang_1_1DecltypeType.html">DecltypeType</a>>...</td></tr> 1742<tr><td colspan="4" class="doc" id="decltypeType0"><pre>Matches types nodes representing C++11 decltype(<expr>) types. 1743 1744Given: 1745 short i = 1; 1746 int j = 42; 1747 decltype(i + j) result = i + j; 1748decltypeType() 1749 matches "decltype(i + j)" 1750</pre></td></tr> 1751 1752 1753<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<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeducedTemplateSpecializationType.html">DeducedTemplateSpecializationType</a>>...</td></tr> 1754<tr><td colspan="4" class="doc" id="deducedTemplateSpecializationType0"><pre>Matches C++17 deduced template specialization types, e.g. deduced class 1755template types. 1756 1757Given 1758 template <typename T> 1759 class C { public: C(T); }; 1760 1761 C c(123); 1762deducedTemplateSpecializationType() matches the type in the declaration 1763of the variable c. 1764</pre></td></tr> 1765 1766 1767<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> 1768<tr><td colspan="4" class="doc" id="dependentSizedArrayType0"><pre>Matches C++ arrays whose size is a value-dependent expression. 1769 1770Given 1771 template<typename T, int Size> 1772 class array { 1773 T data[Size]; 1774 }; 1775dependentSizedArrayType 1776 matches "T data[Size]" 1777</pre></td></tr> 1778 1779 1780<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('elaboratedType0')"><a name="elaboratedType0Anchor">elaboratedType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ElaboratedType.html">ElaboratedType</a>>...</td></tr> 1781<tr><td colspan="4" class="doc" id="elaboratedType0"><pre>Matches types specified with an elaborated type keyword or with a 1782qualified name. 1783 1784Given 1785 namespace N { 1786 namespace M { 1787 class D {}; 1788 } 1789 } 1790 class C {}; 1791 1792 class C c; 1793 N::M::D d; 1794 1795elaboratedType() matches the type of the variable declarations of both 1796c and d. 1797</pre></td></tr> 1798 1799 1800<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<<a href="https://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>...</td></tr> 1801<tr><td colspan="4" class="doc" id="enumType0"><pre>Matches enum types. 1802 1803Given 1804 enum C { Green }; 1805 enum class S { Red }; 1806 1807 C c; 1808 S s; 1809 1810enumType() matches the type of the variable declarations of both c and 1811s. 1812</pre></td></tr> 1813 1814 1815<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> 1816<tr><td colspan="4" class="doc" id="functionProtoType0"><pre>Matches FunctionProtoType nodes. 1817 1818Given 1819 int (*f)(int); 1820 void g(); 1821functionProtoType() 1822 matches "int (*f)(int)" and the type of "g" in C++ mode. 1823 In C mode, "g" is not matched because it does not contain a prototype. 1824</pre></td></tr> 1825 1826 1827<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> 1828<tr><td colspan="4" class="doc" id="functionType0"><pre>Matches FunctionType nodes. 1829 1830Given 1831 int (*f)(int); 1832 void g(); 1833functionType() 1834 matches "int (*f)(int)" and the type of "g". 1835</pre></td></tr> 1836 1837 1838<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> 1839<tr><td colspan="4" class="doc" id="incompleteArrayType0"><pre>Matches C arrays with unspecified size. 1840 1841Given 1842 int a[] = { 2, 3 }; 1843 int b[42]; 1844 void f(int c[]) { int d[a[0]]; }; 1845incompleteArrayType() 1846 matches "int a[]" and "int c[]" 1847</pre></td></tr> 1848 1849 1850<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<<a href="https://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>...</td></tr> 1851<tr><td colspan="4" class="doc" id="injectedClassNameType0"><pre>Matches injected class name types. 1852 1853Example matches S s, but not S<T> s. 1854 (matcher = parmVarDecl(hasType(injectedClassNameType()))) 1855 template <typename T> struct S { 1856 void f(S s); 1857 void g(S<T> s); 1858 }; 1859</pre></td></tr> 1860 1861 1862<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> 1863<tr><td colspan="4" class="doc" id="lValueReferenceType0"><pre>Matches lvalue reference types. 1864 1865Given: 1866 int *a; 1867 int &b = *a; 1868 int &&c = 1; 1869 auto &d = b; 1870 auto &&e = c; 1871 auto &&f = 2; 1872 int g = 5; 1873 1874lValueReferenceType() matches the types of b, d, and e. e is 1875matched since the type is deduced as int& by reference collapsing rules. 1876</pre></td></tr> 1877 1878 1879<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> 1880<tr><td colspan="4" class="doc" id="memberPointerType0"><pre>Matches member pointer types. 1881Given 1882 struct A { int i; } 1883 A::* ptr = A::i; 1884memberPointerType() 1885 matches "A::* ptr" 1886</pre></td></tr> 1887 1888 1889<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> 1890<tr><td colspan="4" class="doc" id="objcObjectPointerType0"><pre>Matches an Objective-C object pointer type, which is different from 1891a pointer type, despite being syntactically similar. 1892 1893Given 1894 int *a; 1895 1896 @interface Foo 1897 @end 1898 Foo *f; 1899pointerType() 1900 matches "Foo *f", but does not match "int *a". 1901</pre></td></tr> 1902 1903 1904<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> 1905<tr><td colspan="4" class="doc" id="parenType0"><pre>Matches ParenType nodes. 1906 1907Given 1908 int (*ptr_to_array)[4]; 1909 int *array_of_ptrs[4]; 1910 1911varDecl(hasType(pointsTo(parenType()))) matches ptr_to_array but not 1912array_of_ptrs. 1913</pre></td></tr> 1914 1915 1916<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> 1917<tr><td colspan="4" class="doc" id="pointerType0"><pre>Matches pointer types, but does not match Objective-C object pointer 1918types. 1919 1920Given 1921 int *a; 1922 int &b = *a; 1923 int c = 5; 1924 1925 @interface Foo 1926 @end 1927 Foo *f; 1928pointerType() 1929 matches "int *a", but does not match "Foo *f". 1930</pre></td></tr> 1931 1932 1933<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> 1934<tr><td colspan="4" class="doc" id="rValueReferenceType0"><pre>Matches rvalue reference types. 1935 1936Given: 1937 int *a; 1938 int &b = *a; 1939 int &&c = 1; 1940 auto &d = b; 1941 auto &&e = c; 1942 auto &&f = 2; 1943 int g = 5; 1944 1945rValueReferenceType() matches the types of c and f. e is not 1946matched as it is deduced to int& by reference collapsing rules. 1947</pre></td></tr> 1948 1949 1950<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<<a href="https://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>...</td></tr> 1951<tr><td colspan="4" class="doc" id="recordType0"><pre>Matches record types (e.g. structs, classes). 1952 1953Given 1954 class C {}; 1955 struct S {}; 1956 1957 C c; 1958 S s; 1959 1960recordType() matches the type of the variable declarations of both c 1961and s. 1962</pre></td></tr> 1963 1964 1965<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> 1966<tr><td colspan="4" class="doc" id="referenceType0"><pre>Matches both lvalue and rvalue reference types. 1967 1968Given 1969 int *a; 1970 int &b = *a; 1971 int &&c = 1; 1972 auto &d = b; 1973 auto &&e = c; 1974 auto &&f = 2; 1975 int g = 5; 1976 1977referenceType() matches the types of b, c, d, e, and f. 1978</pre></td></tr> 1979 1980 1981<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<<a href="https://clang.llvm.org/doxygen/classclang_1_1SubstTemplateTypeParmType.html">SubstTemplateTypeParmType</a>>...</td></tr> 1982<tr><td colspan="4" class="doc" id="substTemplateTypeParmType0"><pre>Matches types that represent the result of substituting a type for a 1983template type parameter. 1984 1985Given 1986 template <typename T> 1987 void F(T t) { 1988 int i = 1 + t; 1989 } 1990 1991substTemplateTypeParmType() matches the type of 't' but not '1' 1992</pre></td></tr> 1993 1994 1995<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<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>...</td></tr> 1996<tr><td colspan="4" class="doc" id="tagType0"><pre>Matches tag types (record and enum types). 1997 1998Given 1999 enum E {}; 2000 class C {}; 2001 2002 E e; 2003 C c; 2004 2005tagType() matches the type of the variable declarations of both e 2006and c. 2007</pre></td></tr> 2008 2009 2010<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<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>...</td></tr> 2011<tr><td colspan="4" class="doc" id="templateSpecializationType0"><pre>Matches template specialization types. 2012 2013Given 2014 template <typename T> 2015 class C { }; 2016 2017 template class C<int>; // A 2018 C<char> var; // B 2019 2020templateSpecializationType() matches the type of the explicit 2021instantiation in A and the type of the variable declaration in B. 2022</pre></td></tr> 2023 2024 2025<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<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>...</td></tr> 2026<tr><td colspan="4" class="doc" id="templateTypeParmType0"><pre>Matches template type parameter types. 2027 2028Example matches T, but not int. 2029 (matcher = templateTypeParmType()) 2030 template <typename T> void f(int i); 2031</pre></td></tr> 2032 2033 2034<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> 2035<tr><td colspan="4" class="doc" id="type0"><pre>Matches Types in the clang AST. 2036</pre></td></tr> 2037 2038 2039<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> 2040<tr><td colspan="4" class="doc" id="typedefType0"><pre>Matches typedef types. 2041 2042Given 2043 typedef int X; 2044typedefType() 2045 matches "typedef int X" 2046</pre></td></tr> 2047 2048 2049<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<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnaryTransformType.html">UnaryTransformType</a>>...</td></tr> 2050<tr><td colspan="4" class="doc" id="unaryTransformType0"><pre>Matches types nodes representing unary type transformations. 2051 2052Given: 2053 typedef __underlying_type(T) type; 2054unaryTransformType() 2055 matches "__underlying_type(T)" 2056</pre></td></tr> 2057 2058 2059<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> 2060<tr><td colspan="4" class="doc" id="variableArrayType0"><pre>Matches C arrays with a specified size that is not an 2061integer-constant-expression. 2062 2063Given 2064 void f() { 2065 int a[] = { 2, 3 } 2066 int b[42]; 2067 int c[a[0]]; 2068 } 2069variableArrayType() 2070 matches "int c[a[0]]" 2071</pre></td></tr> 2072 2073<!--END_DECL_MATCHERS --> 2074</table> 2075 2076<!-- ======================================================================= --> 2077<h2 id="narrowing-matchers">Narrowing Matchers</h2> 2078<!-- ======================================================================= --> 2079 2080<p>Narrowing matchers match certain attributes on the current node, thus 2081narrowing down the set of nodes of the current type to match on.</p> 2082 2083<p>There are special logical narrowing matchers (allOf, anyOf, anything and unless) 2084which allow users to create more powerful match expressions.</p> 2085 2086<table> 2087<tr style="text-align:left"><th>Return type</th><th>Name</th><th>Parameters</th></tr> 2088<!-- START_NARROWING_MATCHERS --> 2089 2090<tr><td>Matcher<*></td><td class="name" onclick="toggle('allOf0')"><a name="allOf0Anchor">allOf</a></td><td>Matcher<*>, ..., Matcher<*></td></tr> 2091<tr><td colspan="4" class="doc" id="allOf0"><pre>Matches if all given matchers match. 2092 2093Usable as: Any Matcher 2094</pre></td></tr> 2095 2096 2097<tr><td>Matcher<*></td><td class="name" onclick="toggle('anyOf0')"><a name="anyOf0Anchor">anyOf</a></td><td>Matcher<*>, ..., Matcher<*></td></tr> 2098<tr><td colspan="4" class="doc" id="anyOf0"><pre>Matches if any of the given matchers matches. 2099 2100Usable as: Any Matcher 2101</pre></td></tr> 2102 2103 2104<tr><td>Matcher<*></td><td class="name" onclick="toggle('anything0')"><a name="anything0Anchor">anything</a></td><td></td></tr> 2105<tr><td colspan="4" class="doc" id="anything0"><pre>Matches any node. 2106 2107Useful when another matcher requires a child matcher, but there's no 2108additional constraint. This will often be used with an explicit conversion 2109to an internal::Matcher<> type such as TypeMatcher. 2110 2111Example: DeclarationMatcher(anything()) matches all declarations, e.g., 2112"int* p" and "void f()" in 2113 int* p; 2114 void f(); 2115 2116Usable as: Any Matcher 2117</pre></td></tr> 2118 2119 2120<tr><td>Matcher<*></td><td class="name" onclick="toggle('unless0')"><a name="unless0Anchor">unless</a></td><td>Matcher<*></td></tr> 2121<tr><td colspan="4" class="doc" id="unless0"><pre>Matches if the provided matcher does not match. 2122 2123Example matches Y (matcher = cxxRecordDecl(unless(hasName("X")))) 2124 class X {}; 2125 class Y {}; 2126 2127Usable as: Any Matcher 2128</pre></td></tr> 2129 2130 2131<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> 2132<tr><td colspan="4" class="doc" id="hasAnyOperatorName0"><pre>Matches operator expressions (binary or unary) that have any of the 2133specified names. 2134 2135 hasAnyOperatorName("+", "-") 2136 Is equivalent to 2137 anyOf(hasOperatorName("+"), hasOperatorName("-")) 2138</pre></td></tr> 2139 2140 2141<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> 2142<tr><td colspan="4" class="doc" id="hasOperatorName0"><pre>Matches the operator Name of operator expressions (binary or 2143unary). 2144 2145Example matches a || b (matcher = binaryOperator(hasOperatorName("||"))) 2146 !(a || b) 2147</pre></td></tr> 2148 2149 2150<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> 2151<tr><td colspan="4" class="doc" id="isAssignmentOperator0"><pre>Matches all kinds of assignment operators. 2152 2153Example 1: matches a += b (matcher = binaryOperator(isAssignmentOperator())) 2154 if (a == b) 2155 a += b; 2156 2157Example 2: matches s1 = s2 2158 (matcher = cxxOperatorCallExpr(isAssignmentOperator())) 2159 struct S { S& operator=(const S&); }; 2160 void x() { S s1, s2; s1 = s2; } 2161</pre></td></tr> 2162 2163 2164<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> 2165<tr><td colspan="4" class="doc" id="isComparisonOperator0"><pre>Matches comparison operators. 2166 2167Example 1: matches a == b (matcher = binaryOperator(isComparisonOperator())) 2168 if (a == b) 2169 a += b; 2170 2171Example 2: matches s1 < s2 2172 (matcher = cxxOperatorCallExpr(isComparisonOperator())) 2173 struct S { bool operator<(const S& other); }; 2174 void x(S s1, S s2) { bool b1 = s1 < s2; } 2175</pre></td></tr> 2176 2177 2178<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> 2179<tr><td colspan="4" class="doc" id="equals5"><pre></pre></td></tr> 2180 2181 2182<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> 2183<tr><td colspan="4" class="doc" id="equals2"><pre>Matches literals that are equal to the given value of type ValueT. 2184 2185Given 2186 f('false, 3.14, 42); 2187characterLiteral(equals(0)) 2188 matches 'cxxBoolLiteral(equals(false)) and cxxBoolLiteral(equals(0)) 2189 match false 2190floatLiteral(equals(3.14)) and floatLiteral(equals(314e-2)) 2191 match 3.14 2192integerLiteral(equals(42)) 2193 matches 42 2194 2195Note that you cannot directly match a negative numeric literal because the 2196minus sign is not part of the literal: It is a unary operator whose operand 2197is the positive numeric literal. Instead, you must use a unaryOperator() 2198matcher to match the minus sign: 2199 2200unaryOperator(hasOperatorName("-"), 2201 hasUnaryOperand(integerLiteral(equals(13)))) 2202 2203Usable 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>>, 2204 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>> 2205</pre></td></tr> 2206 2207 2208<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> 2209<tr><td colspan="4" class="doc" id="equals11"><pre></pre></td></tr> 2210 2211 2212<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> 2213<tr><td colspan="4" class="doc" id="equals8"><pre></pre></td></tr> 2214 2215 2216<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> 2217<tr><td colspan="4" class="doc" id="isCatchAll0"><pre>Matches a C++ catch statement that has a catch-all handler. 2218 2219Given 2220 try { 2221 // ... 2222 } catch (int) { 2223 // ... 2224 } catch (...) { 2225 // ... 2226 } 2227cxxCatchStmt(isCatchAll()) matches catch(...) but not catch(int). 2228</pre></td></tr> 2229 2230 2231<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> 2232<tr><td colspan="4" class="doc" id="argumentCountIs1"><pre>Checks that a call expression or a constructor call expression has 2233a specific number of arguments (including absent default arguments). 2234 2235Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2))) 2236 void f(int x, int y); 2237 f(0, 0); 2238</pre></td></tr> 2239 2240 2241<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> 2242<tr><td colspan="4" class="doc" id="isListInitialization0"><pre>Matches a constructor call expression which uses list initialization. 2243</pre></td></tr> 2244 2245 2246<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> 2247<tr><td colspan="4" class="doc" id="requiresZeroInitialization0"><pre>Matches a constructor call expression which requires 2248zero initialization. 2249 2250Given 2251void foo() { 2252 struct point { double x; double y; }; 2253 point pt[2] = { { 1.0, 2.0 } }; 2254} 2255initListExpr(has(cxxConstructExpr(requiresZeroInitialization())) 2256will match the implicit array filler for pt[1]. 2257</pre></td></tr> 2258 2259 2260<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> 2261<tr><td colspan="4" class="doc" id="isCopyConstructor0"><pre>Matches constructor declarations that are copy constructors. 2262 2263Given 2264 struct S { 2265 S(); // #1 2266 S(const S &); // #2 2267 S(S &&); // #3 2268 }; 2269cxxConstructorDecl(isCopyConstructor()) will match #2, but not #1 or #3. 2270</pre></td></tr> 2271 2272 2273<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> 2274<tr><td colspan="4" class="doc" id="isDefaultConstructor0"><pre>Matches constructor declarations that are default constructors. 2275 2276Given 2277 struct S { 2278 S(); // #1 2279 S(const S &); // #2 2280 S(S &&); // #3 2281 }; 2282cxxConstructorDecl(isDefaultConstructor()) will match #1, but not #2 or #3. 2283</pre></td></tr> 2284 2285 2286<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> 2287<tr><td colspan="4" class="doc" id="isDelegatingConstructor0"><pre>Matches constructors that delegate to another constructor. 2288 2289Given 2290 struct S { 2291 S(); // #1 2292 S(int) {} // #2 2293 S(S &&) : S() {} // #3 2294 }; 2295 S::S() : S(0) {} // #4 2296cxxConstructorDecl(isDelegatingConstructor()) will match #3 and #4, but not 2297#1 or #2. 2298</pre></td></tr> 2299 2300 2301<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> 2302<tr><td colspan="4" class="doc" id="isExplicit0"><pre>Matches constructor, conversion function, and deduction guide declarations 2303that have an explicit specifier if this explicit specifier is resolved to 2304true. 2305 2306Given 2307 template<bool b> 2308 struct S { 2309 S(int); // #1 2310 explicit S(double); // #2 2311 operator int(); // #3 2312 explicit operator bool(); // #4 2313 explicit(false) S(bool) // # 7 2314 explicit(true) S(char) // # 8 2315 explicit(b) S(S) // # 9 2316 }; 2317 S(int) -> S<true> // #5 2318 explicit S(double) -> S<false> // #6 2319cxxConstructorDecl(isExplicit()) will match #2 and #8, but not #1, #7 or #9. 2320cxxConversionDecl(isExplicit()) will match #4, but not #3. 2321cxxDeductionGuideDecl(isExplicit()) will match #6, but not #5. 2322</pre></td></tr> 2323 2324 2325<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> 2326<tr><td colspan="4" class="doc" id="isMoveConstructor0"><pre>Matches constructor declarations that are move constructors. 2327 2328Given 2329 struct S { 2330 S(); // #1 2331 S(const S &); // #2 2332 S(S &&); // #3 2333 }; 2334cxxConstructorDecl(isMoveConstructor()) will match #3, but not #1 or #2. 2335</pre></td></tr> 2336 2337 2338<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> 2339<tr><td colspan="4" class="doc" id="isExplicit1"><pre>Matches constructor, conversion function, and deduction guide declarations 2340that have an explicit specifier if this explicit specifier is resolved to 2341true. 2342 2343Given 2344 template<bool b> 2345 struct S { 2346 S(int); // #1 2347 explicit S(double); // #2 2348 operator int(); // #3 2349 explicit operator bool(); // #4 2350 explicit(false) S(bool) // # 7 2351 explicit(true) S(char) // # 8 2352 explicit(b) S(S) // # 9 2353 }; 2354 S(int) -> S<true> // #5 2355 explicit S(double) -> S<false> // #6 2356cxxConstructorDecl(isExplicit()) will match #2 and #8, but not #1, #7 or #9. 2357cxxConversionDecl(isExplicit()) will match #4, but not #3. 2358cxxDeductionGuideDecl(isExplicit()) will match #6, but not #5. 2359</pre></td></tr> 2360 2361 2362<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> 2363<tr><td colspan="4" class="doc" id="isBaseInitializer0"><pre>Matches a constructor initializer if it is initializing a base, as 2364opposed to a member. 2365 2366Given 2367 struct B {}; 2368 struct D : B { 2369 int I; 2370 D(int i) : I(i) {} 2371 }; 2372 struct E : B { 2373 E() : B() {} 2374 }; 2375cxxConstructorDecl(hasAnyConstructorInitializer(isBaseInitializer())) 2376 will match E(), but not match D(int). 2377</pre></td></tr> 2378 2379 2380<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> 2381<tr><td colspan="4" class="doc" id="isMemberInitializer0"><pre>Matches a constructor initializer if it is initializing a member, as 2382opposed to a base. 2383 2384Given 2385 struct B {}; 2386 struct D : B { 2387 int I; 2388 D(int i) : I(i) {} 2389 }; 2390 struct E : B { 2391 E() : B() {} 2392 }; 2393cxxConstructorDecl(hasAnyConstructorInitializer(isMemberInitializer())) 2394 will match D(int), but not match E(). 2395</pre></td></tr> 2396 2397 2398<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> 2399<tr><td colspan="4" class="doc" id="isWritten0"><pre>Matches a constructor initializer if it is explicitly written in 2400code (as opposed to implicitly added by the compiler). 2401 2402Given 2403 struct Foo { 2404 Foo() { } 2405 Foo(int) : foo_("A") { } 2406 string foo_; 2407 }; 2408cxxConstructorDecl(hasAnyConstructorInitializer(isWritten())) 2409 will match Foo(int), but not Foo() 2410</pre></td></tr> 2411 2412 2413<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> 2414<tr><td colspan="4" class="doc" id="isExplicit2"><pre>Matches constructor, conversion function, and deduction guide declarations 2415that have an explicit specifier if this explicit specifier is resolved to 2416true. 2417 2418Given 2419 template<bool b> 2420 struct S { 2421 S(int); // #1 2422 explicit S(double); // #2 2423 operator int(); // #3 2424 explicit operator bool(); // #4 2425 explicit(false) S(bool) // # 7 2426 explicit(true) S(char) // # 8 2427 explicit(b) S(S) // # 9 2428 }; 2429 S(int) -> S<true> // #5 2430 explicit S(double) -> S<false> // #6 2431cxxConstructorDecl(isExplicit()) will match #2 and #8, but not #1, #7 or #9. 2432cxxConversionDecl(isExplicit()) will match #4, but not #3. 2433cxxDeductionGuideDecl(isExplicit()) will match #6, but not #5. 2434</pre></td></tr> 2435 2436 2437<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> 2438<tr><td colspan="4" class="doc" id="isArrow2"><pre>Matches member expressions that are called with '->' as opposed 2439to '.'. 2440 2441Member calls on the implicit this pointer match as called with '->'. 2442 2443Given 2444 class Y { 2445 void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; } 2446 template <class T> void f() { this->f<T>(); f<T>(); } 2447 int a; 2448 static int b; 2449 }; 2450 template <class T> 2451 class Z { 2452 void x() { this->m; } 2453 }; 2454memberExpr(isArrow()) 2455 matches this->x, x, y.x, a, this->b 2456cxxDependentScopeMemberExpr(isArrow()) 2457 matches this->m 2458unresolvedMemberExpr(isArrow()) 2459 matches this->f<T>, f<T> 2460</pre></td></tr> 2461 2462 2463<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> 2464<tr><td colspan="4" class="doc" id="isConst0"><pre>Matches if the given method declaration is const. 2465 2466Given 2467struct A { 2468 void foo() const; 2469 void bar(); 2470}; 2471 2472cxxMethodDecl(isConst()) matches A::foo() but not A::bar() 2473</pre></td></tr> 2474 2475 2476<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> 2477<tr><td colspan="4" class="doc" id="isCopyAssignmentOperator0"><pre>Matches if the given method declaration declares a copy assignment 2478operator. 2479 2480Given 2481struct A { 2482 A &operator=(const A &); 2483 A &operator=(A &&); 2484}; 2485 2486cxxMethodDecl(isCopyAssignmentOperator()) matches the first method but not 2487the second one. 2488</pre></td></tr> 2489 2490 2491<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> 2492<tr><td colspan="4" class="doc" id="isFinal1"><pre>Matches if the given method or class declaration is final. 2493 2494Given: 2495 class A final {}; 2496 2497 struct B { 2498 virtual void f(); 2499 }; 2500 2501 struct C : B { 2502 void f() final; 2503 }; 2504matches A and C::f, but not B, C, or B::f 2505</pre></td></tr> 2506 2507 2508<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> 2509<tr><td colspan="4" class="doc" id="isMoveAssignmentOperator0"><pre>Matches if the given method declaration declares a move assignment 2510operator. 2511 2512Given 2513struct A { 2514 A &operator=(const A &); 2515 A &operator=(A &&); 2516}; 2517 2518cxxMethodDecl(isMoveAssignmentOperator()) matches the second method but not 2519the first one. 2520</pre></td></tr> 2521 2522 2523<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> 2524<tr><td colspan="4" class="doc" id="isOverride0"><pre>Matches if the given method declaration overrides another method. 2525 2526Given 2527 class A { 2528 public: 2529 virtual void x(); 2530 }; 2531 class B : public A { 2532 public: 2533 virtual void x(); 2534 }; 2535 matches B::x 2536</pre></td></tr> 2537 2538 2539<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> 2540<tr><td colspan="4" class="doc" id="isPure0"><pre>Matches if the given method declaration is pure. 2541 2542Given 2543 class A { 2544 public: 2545 virtual void x() = 0; 2546 }; 2547 matches A::x 2548</pre></td></tr> 2549 2550 2551<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> 2552<tr><td colspan="4" class="doc" id="isUserProvided0"><pre>Matches method declarations that are user-provided. 2553 2554Given 2555 struct S { 2556 S(); // #1 2557 S(const S &) = default; // #2 2558 S(S &&) = delete; // #3 2559 }; 2560cxxConstructorDecl(isUserProvided()) will match #1, but not #2 or #3. 2561</pre></td></tr> 2562 2563 2564<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> 2565<tr><td colspan="4" class="doc" id="isVirtual0"><pre>Matches if the given method declaration is virtual. 2566 2567Given 2568 class A { 2569 public: 2570 virtual void x(); 2571 }; 2572 matches A::x 2573</pre></td></tr> 2574 2575 2576<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> 2577<tr><td colspan="4" class="doc" id="isVirtualAsWritten0"><pre>Matches if the given method declaration has an explicit "virtual". 2578 2579Given 2580 class A { 2581 public: 2582 virtual void x(); 2583 }; 2584 class B : public A { 2585 public: 2586 void x(); 2587 }; 2588 matches A::x but not B::x 2589</pre></td></tr> 2590 2591 2592<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> 2593<tr><td colspan="4" class="doc" id="isArray0"><pre>Matches array new expressions. 2594 2595Given: 2596 MyClass *p1 = new MyClass[10]; 2597cxxNewExpr(isArray()) 2598 matches the expression 'new MyClass[10]'. 2599</pre></td></tr> 2600 2601 2602<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> 2603<tr><td colspan="4" class="doc" id="hasAnyOverloadedOperatorName0"><pre>Matches overloaded operator names. 2604 2605Matches overloaded operator names specified in strings without the 2606"operator" prefix: e.g. "<<". 2607 2608 hasAnyOverloadesOperatorName("+", "-") 2609Is equivalent to 2610 anyOf(hasOverloadedOperatorName("+"), hasOverloadedOperatorName("-")) 2611</pre></td></tr> 2612 2613 2614<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> 2615<tr><td colspan="4" class="doc" id="hasOverloadedOperatorName1"><pre>Matches overloaded operator names. 2616 2617Matches overloaded operator names specified in strings without the 2618"operator" prefix: e.g. "<<". 2619 2620Given: 2621 class A { int operator*(); }; 2622 const A &operator<<(const A &a, const A &b); 2623 A a; 2624 a << a; // <-- This matches 2625 2626cxxOperatorCallExpr(hasOverloadedOperatorName("<<"))) matches the 2627specified line and 2628cxxRecordDecl(hasMethod(hasOverloadedOperatorName("*"))) 2629matches the declaration of A. 2630 2631Usable 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>> 2632</pre></td></tr> 2633 2634 2635<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> 2636<tr><td colspan="4" class="doc" id="isAssignmentOperator1"><pre>Matches all kinds of assignment operators. 2637 2638Example 1: matches a += b (matcher = binaryOperator(isAssignmentOperator())) 2639 if (a == b) 2640 a += b; 2641 2642Example 2: matches s1 = s2 2643 (matcher = cxxOperatorCallExpr(isAssignmentOperator())) 2644 struct S { S& operator=(const S&); }; 2645 void x() { S s1, s2; s1 = s2; } 2646</pre></td></tr> 2647 2648 2649<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> 2650<tr><td colspan="4" class="doc" id="isComparisonOperator1"><pre>Matches comparison operators. 2651 2652Example 1: matches a == b (matcher = binaryOperator(isComparisonOperator())) 2653 if (a == b) 2654 a += b; 2655 2656Example 2: matches s1 < s2 2657 (matcher = cxxOperatorCallExpr(isComparisonOperator())) 2658 struct S { bool operator<(const S& other); }; 2659 void x(S s1, S s2) { bool b1 = s1 < s2; } 2660</pre></td></tr> 2661 2662 2663<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> 2664<tr><td colspan="4" class="doc" id="hasDefinition0"><pre>Matches a class declaration that is defined. 2665 2666Example matches x (matcher = cxxRecordDecl(hasDefinition())) 2667class x {}; 2668class y; 2669</pre></td></tr> 2670 2671 2672<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> 2673<tr><td colspan="4" class="doc" id="isDerivedFrom2"><pre>Overloaded method as shortcut for isDerivedFrom(hasName(...)). 2674</pre></td></tr> 2675 2676 2677<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> 2678<tr><td colspan="4" class="doc" id="isDirectlyDerivedFrom2"><pre>Overloaded method as shortcut for isDirectlyDerivedFrom(hasName(...)). 2679</pre></td></tr> 2680 2681 2682<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> 2683<tr><td colspan="4" class="doc" id="isExplicitTemplateSpecialization2"><pre>Matches explicit template specializations of function, class, or 2684static member variable template instantiations. 2685 2686Given 2687 template<typename T> void A(T t) { } 2688 template<> void A(int N) { } 2689functionDecl(isExplicitTemplateSpecialization()) 2690 matches the specialization A<int>(). 2691 2692Usable 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>> 2693</pre></td></tr> 2694 2695 2696<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> 2697<tr><td colspan="4" class="doc" id="isFinal0"><pre>Matches if the given method or class declaration is final. 2698 2699Given: 2700 class A final {}; 2701 2702 struct B { 2703 virtual void f(); 2704 }; 2705 2706 struct C : B { 2707 void f() final; 2708 }; 2709matches A and C::f, but not B, C, or B::f 2710</pre></td></tr> 2711 2712 2713<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> 2714<tr><td colspan="4" class="doc" id="isLambda0"><pre>Matches the generated class of lambda expressions. 2715 2716Given: 2717 auto x = []{}; 2718 2719cxxRecordDecl(isLambda()) matches the implicit class declaration of 2720decltype(x) 2721</pre></td></tr> 2722 2723 2724<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> 2725<tr><td colspan="4" class="doc" id="isSameOrDerivedFrom2"><pre>Overloaded method as shortcut for 2726isSameOrDerivedFrom(hasName(...)). 2727</pre></td></tr> 2728 2729 2730<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> 2731<tr><td colspan="4" class="doc" id="isTemplateInstantiation2"><pre>Matches template instantiations of function, class, or static 2732member variable template instantiations. 2733 2734Given 2735 template <typename T> class X {}; class A {}; X<A> x; 2736or 2737 template <typename T> class X {}; class A {}; template class X<A>; 2738or 2739 template <typename T> class X {}; class A {}; extern template class X<A>; 2740cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) 2741 matches the template instantiation of X<A>. 2742 2743But given 2744 template <typename T> class X {}; class A {}; 2745 template <> class X<A> {}; X<A> x; 2746cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) 2747 does not match, as X<A> is an explicit template specialization. 2748 2749Usable 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>> 2750</pre></td></tr> 2751 2752 2753<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> 2754<tr><td colspan="4" class="doc" id="argumentCountIs0"><pre>Checks that a call expression or a constructor call expression has 2755a specific number of arguments (including absent default arguments). 2756 2757Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2))) 2758 void f(int x, int y); 2759 f(0, 0); 2760</pre></td></tr> 2761 2762 2763<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> 2764<tr><td colspan="4" class="doc" id="usesADL0"><pre>Matches call expressions which were resolved using ADL. 2765 2766Example matches y(x) but not y(42) or NS::y(x). 2767 namespace NS { 2768 struct X {}; 2769 void y(X); 2770 } 2771 2772 void y(...); 2773 2774 void test() { 2775 NS::X x; 2776 y(x); // Matches 2777 NS::y(x); // Doesn't match 2778 y(42); // Doesn't match 2779 using NS::y; 2780 y(x); // Found by both unqualified lookup and ADL, doesn't match 2781 } 2782</pre></td></tr> 2783 2784 2785<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> 2786<tr><td colspan="4" class="doc" id="hasCastKind0"><pre>Matches casts that has a given cast kind. 2787 2788Example: matches the implicit cast around 0 2789(matcher = castExpr(hasCastKind(CK_NullToPointer))) 2790 int *p = 0; 2791 2792If the matcher is use from clang-query, CastKind parameter 2793should be passed as a quoted string. e.g., hasCastKind("CK_NullToPointer"). 2794</pre></td></tr> 2795 2796 2797<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> 2798<tr><td colspan="4" class="doc" id="equals4"><pre></pre></td></tr> 2799 2800 2801<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> 2802<tr><td colspan="4" class="doc" id="equals3"><pre>Matches literals that are equal to the given value of type ValueT. 2803 2804Given 2805 f('false, 3.14, 42); 2806characterLiteral(equals(0)) 2807 matches 'cxxBoolLiteral(equals(false)) and cxxBoolLiteral(equals(0)) 2808 match false 2809floatLiteral(equals(3.14)) and floatLiteral(equals(314e-2)) 2810 match 3.14 2811integerLiteral(equals(42)) 2812 matches 42 2813 2814Note that you cannot directly match a negative numeric literal because the 2815minus sign is not part of the literal: It is a unary operator whose operand 2816is the positive numeric literal. Instead, you must use a unaryOperator() 2817matcher to match the minus sign: 2818 2819unaryOperator(hasOperatorName("-"), 2820 hasUnaryOperand(integerLiteral(equals(13)))) 2821 2822Usable 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>>, 2823 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>> 2824</pre></td></tr> 2825 2826 2827<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> 2828<tr><td colspan="4" class="doc" id="equals10"><pre></pre></td></tr> 2829 2830 2831<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> 2832<tr><td colspan="4" class="doc" id="equals7"><pre></pre></td></tr> 2833 2834 2835<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> 2836<tr><td colspan="4" class="doc" id="templateArgumentCountIs0"><pre>Matches if the number of template arguments equals N. 2837 2838Given 2839 template<typename T> struct C {}; 2840 C<int> c; 2841classTemplateSpecializationDecl(templateArgumentCountIs(1)) 2842 matches C<int>. 2843</pre></td></tr> 2844 2845 2846<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> 2847<tr><td colspan="4" class="doc" id="statementCountIs0"><pre>Checks that a compound statement contains a specific number of 2848child statements. 2849 2850Example: Given 2851 { for (;;) {} } 2852compoundStmt(statementCountIs(0))) 2853 matches '{}' 2854 but does not match the outer compound statement. 2855</pre></td></tr> 2856 2857 2858<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> 2859<tr><td colspan="4" class="doc" id="hasSize0"><pre>Matches nodes that have the specified size. 2860 2861Given 2862 int a[42]; 2863 int b[2 * 21]; 2864 int c[41], d[43]; 2865 char *s = "abcd"; 2866 wchar_t *ws = L"abcd"; 2867 char *w = "a"; 2868constantArrayType(hasSize(42)) 2869 matches "int a[42]" and "int b[2 * 21]" 2870stringLiteral(hasSize(4)) 2871 matches "abcd", L"abcd" 2872</pre></td></tr> 2873 2874 2875<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> 2876<tr><td colspan="4" class="doc" id="declCountIs0"><pre>Matches declaration statements that contain a specific number of 2877declarations. 2878 2879Example: Given 2880 int a, b; 2881 int c; 2882 int d = 2, e; 2883declCountIs(2) 2884 matches 'int a, b;' and 'int d = 2, e;', but not 'int c;'. 2885</pre></td></tr> 2886 2887 2888<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> 2889<tr><td colspan="4" class="doc" id="equalsBoundNode1"><pre>Matches if a node equals a previously bound node. 2890 2891Matches a node if it equals the node previously bound to ID. 2892 2893Given 2894 class X { int a; int b; }; 2895cxxRecordDecl( 2896 has(fieldDecl(hasName("a"), hasType(type().bind("t")))), 2897 has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t")))))) 2898 matches the class X, as a and b have the same type. 2899 2900Note that when multiple matches are involved via forEach* matchers, 2901equalsBoundNodes acts as a filter. 2902For example: 2903compoundStmt( 2904 forEachDescendant(varDecl().bind("d")), 2905 forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d")))))) 2906will trigger a match for each combination of variable declaration 2907and reference to that variable declaration within a compound statement. 2908</pre></td></tr> 2909 2910 2911<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> 2912<tr><td colspan="4" class="doc" id="equalsNode0"><pre>Matches if a node equals another node. 2913 2914Decl has pointer identity in the AST. 2915</pre></td></tr> 2916 2917 2918<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> 2919<tr><td colspan="4" class="doc" id="hasAttr0"><pre>Matches declaration that has a given attribute. 2920 2921Given 2922 __attribute__((device)) void f() { ... } 2923decl(hasAttr(clang::attr::CUDADevice)) matches the function declaration of 2924f. If the matcher is used from clang-query, attr::Kind parameter should be 2925passed as a quoted string. e.g., hasAttr("attr::CUDADevice"). 2926</pre></td></tr> 2927 2928 2929<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>std::string RegExp</td></tr> 2930<tr><td colspan="4" class="doc" id="isExpansionInFileMatching0"><pre>Matches AST nodes that were expanded within files whose name is 2931partially matching a given regex. 2932 2933Example matches Y but not X 2934 (matcher = cxxRecordDecl(isExpansionInFileMatching("AST.*")) 2935 #include "ASTMatcher.h" 2936 class X {}; 2937ASTMatcher.h: 2938 class Y {}; 2939 2940Usable 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>> 2941</pre></td></tr> 2942 2943 2944<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> 2945<tr><td colspan="4" class="doc" id="isExpansionInMainFile0"><pre>Matches AST nodes that were expanded within the main-file. 2946 2947Example matches X but not Y 2948 (matcher = cxxRecordDecl(isExpansionInMainFile()) 2949 #include <Y.h> 2950 class X {}; 2951Y.h: 2952 class Y {}; 2953 2954Usable 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>> 2955</pre></td></tr> 2956 2957 2958<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> 2959<tr><td colspan="4" class="doc" id="isExpansionInSystemHeader0"><pre>Matches AST nodes that were expanded within system-header-files. 2960 2961Example matches Y but not X 2962 (matcher = cxxRecordDecl(isExpansionInSystemHeader()) 2963 #include <SystemHeader.h> 2964 class X {}; 2965SystemHeader.h: 2966 class Y {}; 2967 2968Usable 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>> 2969</pre></td></tr> 2970 2971 2972<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> 2973<tr><td colspan="4" class="doc" id="isImplicit0"><pre>Matches a declaration that has been implicitly added 2974by the compiler (eg. implicit default/copy constructors). 2975</pre></td></tr> 2976 2977 2978<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> 2979<tr><td colspan="4" class="doc" id="isInStdNamespace0"><pre>Matches declarations in the namespace `std`, but not in nested namespaces. 2980 2981Given 2982 class vector {}; 2983 namespace foo { 2984 class vector {}; 2985 namespace std { 2986 class vector {}; 2987 } 2988 } 2989 namespace std { 2990 inline namespace __1 { 2991 class vector {}; // #1 2992 namespace experimental { 2993 class vector {}; 2994 } 2995 } 2996 } 2997cxxRecordDecl(hasName("vector"), isInStdNamespace()) will match only #1. 2998</pre></td></tr> 2999 3000 3001<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> 3002<tr><td colspan="4" class="doc" id="isInstantiated0"><pre>Matches declarations that are template instantiations or are inside 3003template instantiations. 3004 3005Given 3006 template<typename T> void A(T t) { T i; } 3007 A(0); 3008 A(0U); 3009functionDecl(isInstantiated()) 3010 matches 'A(int) {...};' and 'A(unsigned) {...}'. 3011</pre></td></tr> 3012 3013 3014<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> 3015<tr><td colspan="4" class="doc" id="isPrivate0"><pre>Matches private C++ declarations. 3016 3017Given 3018 class C { 3019 public: int a; 3020 protected: int b; 3021 private: int c; 3022 }; 3023fieldDecl(isPrivate()) 3024 matches 'int c;' 3025</pre></td></tr> 3026 3027 3028<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> 3029<tr><td colspan="4" class="doc" id="isProtected0"><pre>Matches protected C++ declarations. 3030 3031Given 3032 class C { 3033 public: int a; 3034 protected: int b; 3035 private: int c; 3036 }; 3037fieldDecl(isProtected()) 3038 matches 'int b;' 3039</pre></td></tr> 3040 3041 3042<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> 3043<tr><td colspan="4" class="doc" id="isPublic0"><pre>Matches public C++ declarations. 3044 3045Given 3046 class C { 3047 public: int a; 3048 protected: int b; 3049 private: int c; 3050 }; 3051fieldDecl(isPublic()) 3052 matches 'int a;' 3053</pre></td></tr> 3054 3055 3056<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> 3057<tr><td colspan="4" class="doc" id="designatorCountIs0"><pre>Matches designated initializer expressions that contain 3058a specific number of designators. 3059 3060Example: Given 3061 point ptarray[10] = { [2].y = 1.0, [0].x = 1.0 }; 3062 point ptarray2[10] = { [2].y = 1.0, [2].x = 0.0, [0].x = 1.0 }; 3063designatorCountIs(2) 3064 matches '{ [2].y = 1.0, [0].x = 1.0 }', 3065 but not '{ [2].y = 1.0, [2].x = 0.0, [0].x = 1.0 }'. 3066</pre></td></tr> 3067 3068 3069<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> 3070<tr><td colspan="4" class="doc" id="isScoped0"><pre>Matches C++11 scoped enum declaration. 3071 3072Example matches Y (matcher = enumDecl(isScoped())) 3073enum X {}; 3074enum class Y {}; 3075</pre></td></tr> 3076 3077 3078<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> 3079<tr><td colspan="4" class="doc" id="isInstantiationDependent0"><pre>Matches expressions that are instantiation-dependent even if it is 3080neither type- nor value-dependent. 3081 3082In the following example, the expression sizeof(sizeof(T() + T())) 3083is instantiation-dependent (since it involves a template parameter T), 3084but is neither type- nor value-dependent, since the type of the inner 3085sizeof is known (std::size_t) and therefore the size of the outer 3086sizeof is known. 3087 template<typename T> 3088 void f(T x, T y) { sizeof(sizeof(T() + T()); } 3089expr(isInstantiationDependent()) matches sizeof(sizeof(T() + T()) 3090</pre></td></tr> 3091 3092 3093<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> 3094<tr><td colspan="4" class="doc" id="isTypeDependent0"><pre>Matches expressions that are type-dependent because the template type 3095is not yet instantiated. 3096 3097For example, the expressions "x" and "x + y" are type-dependent in 3098the following code, but "y" is not type-dependent: 3099 template<typename T> 3100 void add(T x, int y) { 3101 x + y; 3102 } 3103expr(isTypeDependent()) matches x + y 3104</pre></td></tr> 3105 3106 3107<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> 3108<tr><td colspan="4" class="doc" id="isValueDependent0"><pre>Matches expression that are value-dependent because they contain a 3109non-type template parameter. 3110 3111For example, the array bound of "Chars" in the following example is 3112value-dependent. 3113 template<int Size> int f() { return Size; } 3114expr(isValueDependent()) matches return Size 3115</pre></td></tr> 3116 3117 3118<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> 3119<tr><td colspan="4" class="doc" id="nullPointerConstant0"><pre>Matches expressions that resolve to a null pointer constant, such as 3120GNU's __null, C++11's nullptr, or C's NULL macro. 3121 3122Given: 3123 void *v1 = NULL; 3124 void *v2 = nullptr; 3125 void *v3 = __null; // GNU extension 3126 char *cp = (char *)0; 3127 int *ip = 0; 3128 int i = 0; 3129expr(nullPointerConstant()) 3130 matches the initializer for v1, v2, v3, cp, and ip. Does not match the 3131 initializer for i. 3132</pre></td></tr> 3133 3134 3135<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> 3136<tr><td colspan="4" class="doc" id="hasBitWidth0"><pre>Matches non-static data members that are bit-fields of the specified 3137bit width. 3138 3139Given 3140 class C { 3141 int a : 2; 3142 int b : 4; 3143 int c : 2; 3144 }; 3145fieldDecl(hasBitWidth(2)) 3146 matches 'int a;' and 'int c;' but not 'int b;'. 3147</pre></td></tr> 3148 3149 3150<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> 3151<tr><td colspan="4" class="doc" id="isBitField0"><pre>Matches non-static data members that are bit-fields. 3152 3153Given 3154 class C { 3155 int a : 2; 3156 int b; 3157 }; 3158fieldDecl(isBitField()) 3159 matches 'int a;' but not 'int b;'. 3160</pre></td></tr> 3161 3162 3163<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> 3164<tr><td colspan="4" class="doc" id="equals1"><pre>Matches literals that are equal to the given value of type ValueT. 3165 3166Given 3167 f('false, 3.14, 42); 3168characterLiteral(equals(0)) 3169 matches 'cxxBoolLiteral(equals(false)) and cxxBoolLiteral(equals(0)) 3170 match false 3171floatLiteral(equals(3.14)) and floatLiteral(equals(314e-2)) 3172 match 3.14 3173integerLiteral(equals(42)) 3174 matches 42 3175 3176Note that you cannot directly match a negative numeric literal because the 3177minus sign is not part of the literal: It is a unary operator whose operand 3178is the positive numeric literal. Instead, you must use a unaryOperator() 3179matcher to match the minus sign: 3180 3181unaryOperator(hasOperatorName("-"), 3182 hasUnaryOperand(integerLiteral(equals(13)))) 3183 3184Usable 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>>, 3185 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>> 3186</pre></td></tr> 3187 3188 3189<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> 3190<tr><td colspan="4" class="doc" id="equals12"><pre></pre></td></tr> 3191 3192 3193<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> 3194<tr><td colspan="4" class="doc" id="hasAnyOverloadedOperatorName1"><pre>Matches overloaded operator names. 3195 3196Matches overloaded operator names specified in strings without the 3197"operator" prefix: e.g. "<<". 3198 3199 hasAnyOverloadesOperatorName("+", "-") 3200Is equivalent to 3201 anyOf(hasOverloadedOperatorName("+"), hasOverloadedOperatorName("-")) 3202</pre></td></tr> 3203 3204 3205<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> 3206<tr><td colspan="4" class="doc" id="hasDynamicExceptionSpec0"><pre>Matches functions that have a dynamic exception specification. 3207 3208Given: 3209 void f(); 3210 void g() noexcept; 3211 void h() noexcept(true); 3212 void i() noexcept(false); 3213 void j() throw(); 3214 void k() throw(int); 3215 void l() throw(...); 3216functionDecl(hasDynamicExceptionSpec()) and 3217 functionProtoType(hasDynamicExceptionSpec()) 3218 match the declarations of j, k, and l, but not f, g, h, or i. 3219</pre></td></tr> 3220 3221 3222<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> 3223<tr><td colspan="4" class="doc" id="hasOverloadedOperatorName0"><pre>Matches overloaded operator names. 3224 3225Matches overloaded operator names specified in strings without the 3226"operator" prefix: e.g. "<<". 3227 3228Given: 3229 class A { int operator*(); }; 3230 const A &operator<<(const A &a, const A &b); 3231 A a; 3232 a << a; // <-- This matches 3233 3234cxxOperatorCallExpr(hasOverloadedOperatorName("<<"))) matches the 3235specified line and 3236cxxRecordDecl(hasMethod(hasOverloadedOperatorName("*"))) 3237matches the declaration of A. 3238 3239Usable 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>> 3240</pre></td></tr> 3241 3242 3243<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> 3244<tr><td colspan="4" class="doc" id="hasTrailingReturn0"><pre>Matches a function declared with a trailing return type. 3245 3246Example matches Y (matcher = functionDecl(hasTrailingReturn())) 3247int X() {} 3248auto Y() -> int {} 3249</pre></td></tr> 3250 3251 3252<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> 3253<tr><td colspan="4" class="doc" id="isConstexpr1"><pre>Matches constexpr variable and function declarations, 3254 and if constexpr. 3255 3256Given: 3257 constexpr int foo = 42; 3258 constexpr int bar(); 3259 void baz() { if constexpr(1 > 0) {} } 3260varDecl(isConstexpr()) 3261 matches the declaration of foo. 3262functionDecl(isConstexpr()) 3263 matches the declaration of bar. 3264ifStmt(isConstexpr()) 3265 matches the if statement in baz. 3266</pre></td></tr> 3267 3268 3269<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> 3270<tr><td colspan="4" class="doc" id="isDefaulted0"><pre>Matches defaulted function declarations. 3271 3272Given: 3273 class A { ~A(); }; 3274 class B { ~B() = default; }; 3275functionDecl(isDefaulted()) 3276 matches the declaration of ~B, but not ~A. 3277</pre></td></tr> 3278 3279 3280<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> 3281<tr><td colspan="4" class="doc" id="isDefinition3"><pre>Matches if a declaration has a body attached. 3282 3283Example matches A, va, fa 3284 class A {}; 3285 class B; // Doesn't match, as it has no body. 3286 int va; 3287 extern int vb; // Doesn't match, as it doesn't define the variable. 3288 void fa() {} 3289 void fb(); // Doesn't match, as it has no body. 3290 @interface X 3291 - (void)ma; // Doesn't match, interface is declaration. 3292 @end 3293 @implementation X 3294 - (void)ma {} 3295 @end 3296 3297Usable 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>>, 3298 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html">ObjCMethodDecl</a>> 3299</pre></td></tr> 3300 3301 3302<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> 3303<tr><td colspan="4" class="doc" id="isDeleted0"><pre>Matches deleted function declarations. 3304 3305Given: 3306 void Func(); 3307 void DeletedFunc() = delete; 3308functionDecl(isDeleted()) 3309 matches the declaration of DeletedFunc, but not Func. 3310</pre></td></tr> 3311 3312 3313<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> 3314<tr><td colspan="4" class="doc" id="isExplicitTemplateSpecialization0"><pre>Matches explicit template specializations of function, class, or 3315static member variable template instantiations. 3316 3317Given 3318 template<typename T> void A(T t) { } 3319 template<> void A(int N) { } 3320functionDecl(isExplicitTemplateSpecialization()) 3321 matches the specialization A<int>(). 3322 3323Usable 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>> 3324</pre></td></tr> 3325 3326 3327<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> 3328<tr><td colspan="4" class="doc" id="isExternC0"><pre>Matches extern "C" function or variable declarations. 3329 3330Given: 3331 extern "C" void f() {} 3332 extern "C" { void g() {} } 3333 void h() {} 3334 extern "C" int x = 1; 3335 extern "C" int y = 2; 3336 int z = 3; 3337functionDecl(isExternC()) 3338 matches the declaration of f and g, but not the declaration of h. 3339varDecl(isExternC()) 3340 matches the declaration of x and y, but not the declaration of z. 3341</pre></td></tr> 3342 3343 3344<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> 3345<tr><td colspan="4" class="doc" id="isInline1"><pre>Matches function and namespace declarations that are marked with 3346the inline keyword. 3347 3348Given 3349 inline void f(); 3350 void g(); 3351 namespace n { 3352 inline namespace m {} 3353 } 3354functionDecl(isInline()) will match ::f(). 3355namespaceDecl(isInline()) will match n::m. 3356</pre></td></tr> 3357 3358 3359<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> 3360<tr><td colspan="4" class="doc" id="isMain0"><pre>Determines whether the function is "main", which is the entry point 3361into an executable program. 3362</pre></td></tr> 3363 3364 3365<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> 3366<tr><td colspan="4" class="doc" id="isNoReturn0"><pre>Matches FunctionDecls that have a noreturn attribute. 3367 3368Given 3369 void nope(); 3370 [[noreturn]] void a(); 3371 __attribute__((noreturn)) void b(); 3372 struct c { [[noreturn]] c(); }; 3373functionDecl(isNoReturn()) 3374 matches all of those except 3375 void nope(); 3376</pre></td></tr> 3377 3378 3379<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> 3380<tr><td colspan="4" class="doc" id="isNoThrow0"><pre>Matches functions that have a non-throwing exception specification. 3381 3382Given: 3383 void f(); 3384 void g() noexcept; 3385 void h() throw(); 3386 void i() throw(int); 3387 void j() noexcept(false); 3388functionDecl(isNoThrow()) and functionProtoType(isNoThrow()) 3389 match the declarations of g, and h, but not f, i or j. 3390</pre></td></tr> 3391 3392 3393<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> 3394<tr><td colspan="4" class="doc" id="isStaticStorageClass0"><pre>Matches variable/function declarations that have "static" storage 3395class specifier ("static" keyword) written in the source. 3396 3397Given: 3398 static void f() {} 3399 static int i = 0; 3400 extern int j; 3401 int k; 3402functionDecl(isStaticStorageClass()) 3403 matches the function declaration f. 3404varDecl(isStaticStorageClass()) 3405 matches the variable declaration i. 3406</pre></td></tr> 3407 3408 3409<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> 3410<tr><td colspan="4" class="doc" id="isTemplateInstantiation0"><pre>Matches template instantiations of function, class, or static 3411member variable template instantiations. 3412 3413Given 3414 template <typename T> class X {}; class A {}; X<A> x; 3415or 3416 template <typename T> class X {}; class A {}; template class X<A>; 3417or 3418 template <typename T> class X {}; class A {}; extern template class X<A>; 3419cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) 3420 matches the template instantiation of X<A>. 3421 3422But given 3423 template <typename T> class X {}; class A {}; 3424 template <> class X<A> {}; X<A> x; 3425cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) 3426 does not match, as X<A> is an explicit template specialization. 3427 3428Usable 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>> 3429</pre></td></tr> 3430 3431 3432<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> 3433<tr><td colspan="4" class="doc" id="isVariadic0"><pre>Matches if a function declaration is variadic. 3434 3435Example matches f, but not g or h. The function i will not match, even when 3436compiled in C mode. 3437 void f(...); 3438 void g(int); 3439 template <typename... Ts> void h(Ts...); 3440 void i(); 3441</pre></td></tr> 3442 3443 3444<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> 3445<tr><td colspan="4" class="doc" id="parameterCountIs0"><pre>Matches FunctionDecls and FunctionProtoTypes that have a 3446specific parameter count. 3447 3448Given 3449 void f(int i) {} 3450 void g(int i, int j) {} 3451 void h(int i, int j); 3452 void j(int i); 3453 void k(int x, int y, int z, ...); 3454functionDecl(parameterCountIs(2)) 3455 matches g and h 3456functionProtoType(parameterCountIs(2)) 3457 matches g and h 3458functionProtoType(parameterCountIs(3)) 3459 matches k 3460</pre></td></tr> 3461 3462 3463<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> 3464<tr><td colspan="4" class="doc" id="hasDynamicExceptionSpec1"><pre>Matches functions that have a dynamic exception specification. 3465 3466Given: 3467 void f(); 3468 void g() noexcept; 3469 void h() noexcept(true); 3470 void i() noexcept(false); 3471 void j() throw(); 3472 void k() throw(int); 3473 void l() throw(...); 3474functionDecl(hasDynamicExceptionSpec()) and 3475 functionProtoType(hasDynamicExceptionSpec()) 3476 match the declarations of j, k, and l, but not f, g, h, or i. 3477</pre></td></tr> 3478 3479 3480<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> 3481<tr><td colspan="4" class="doc" id="isNoThrow1"><pre>Matches functions that have a non-throwing exception specification. 3482 3483Given: 3484 void f(); 3485 void g() noexcept; 3486 void h() throw(); 3487 void i() throw(int); 3488 void j() noexcept(false); 3489functionDecl(isNoThrow()) and functionProtoType(isNoThrow()) 3490 match the declarations of g, and h, but not f, i or j. 3491</pre></td></tr> 3492 3493 3494<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> 3495<tr><td colspan="4" class="doc" id="parameterCountIs1"><pre>Matches FunctionDecls and FunctionProtoTypes that have a 3496specific parameter count. 3497 3498Given 3499 void f(int i) {} 3500 void g(int i, int j) {} 3501 void h(int i, int j); 3502 void j(int i); 3503 void k(int x, int y, int z, ...); 3504functionDecl(parameterCountIs(2)) 3505 matches g and h 3506functionProtoType(parameterCountIs(2)) 3507 matches g and h 3508functionProtoType(parameterCountIs(3)) 3509 matches k 3510</pre></td></tr> 3511 3512 3513<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> 3514<tr><td colspan="4" class="doc" id="isConstexpr2"><pre>Matches constexpr variable and function declarations, 3515 and if constexpr. 3516 3517Given: 3518 constexpr int foo = 42; 3519 constexpr int bar(); 3520 void baz() { if constexpr(1 > 0) {} } 3521varDecl(isConstexpr()) 3522 matches the declaration of foo. 3523functionDecl(isConstexpr()) 3524 matches the declaration of bar. 3525ifStmt(isConstexpr()) 3526 matches the if statement in baz. 3527</pre></td></tr> 3528 3529 3530<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> 3531<tr><td colspan="4" class="doc" id="equals6"><pre></pre></td></tr> 3532 3533 3534<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> 3535<tr><td colspan="4" class="doc" id="equals0"><pre>Matches literals that are equal to the given value of type ValueT. 3536 3537Given 3538 f('false, 3.14, 42); 3539characterLiteral(equals(0)) 3540 matches 'cxxBoolLiteral(equals(false)) and cxxBoolLiteral(equals(0)) 3541 match false 3542floatLiteral(equals(3.14)) and floatLiteral(equals(314e-2)) 3543 match 3.14 3544integerLiteral(equals(42)) 3545 matches 42 3546 3547Note that you cannot directly match a negative numeric literal because the 3548minus sign is not part of the literal: It is a unary operator whose operand 3549is the positive numeric literal. Instead, you must use a unaryOperator() 3550matcher to match the minus sign: 3551 3552unaryOperator(hasOperatorName("-"), 3553 hasUnaryOperand(integerLiteral(equals(13)))) 3554 3555Usable 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>>, 3556 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>> 3557</pre></td></tr> 3558 3559 3560<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> 3561<tr><td colspan="4" class="doc" id="equals13"><pre></pre></td></tr> 3562 3563 3564<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> 3565<tr><td colspan="4" class="doc" id="equals9"><pre></pre></td></tr> 3566 3567 3568<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> 3569<tr><td colspan="4" class="doc" id="isArrow0"><pre>Matches member expressions that are called with '->' as opposed 3570to '.'. 3571 3572Member calls on the implicit this pointer match as called with '->'. 3573 3574Given 3575 class Y { 3576 void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; } 3577 template <class T> void f() { this->f<T>(); f<T>(); } 3578 int a; 3579 static int b; 3580 }; 3581 template <class T> 3582 class Z { 3583 void x() { this->m; } 3584 }; 3585memberExpr(isArrow()) 3586 matches this->x, x, y.x, a, this->b 3587cxxDependentScopeMemberExpr(isArrow()) 3588 matches this->m 3589unresolvedMemberExpr(isArrow()) 3590 matches this->f<T>, f<T> 3591</pre></td></tr> 3592 3593 3594<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> 3595<tr><td colspan="4" class="doc" id="hasAnyName0"><pre>Matches NamedDecl nodes that have any of the specified names. 3596 3597This matcher is only provided as a performance optimization of hasName. 3598 hasAnyName(a, b, c) 3599 is equivalent to, but faster than 3600 anyOf(hasName(a), hasName(b), hasName(c)) 3601</pre></td></tr> 3602 3603 3604<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> 3605<tr><td colspan="4" class="doc" id="hasExternalFormalLinkage0"><pre>Matches a declaration that has external formal linkage. 3606 3607Example matches only z (matcher = varDecl(hasExternalFormalLinkage())) 3608void f() { 3609 int x; 3610 static int y; 3611} 3612int z; 3613 3614Example matches f() because it has external formal linkage despite being 3615unique to the translation unit as though it has internal likage 3616(matcher = functionDecl(hasExternalFormalLinkage())) 3617 3618namespace { 3619void f() {} 3620} 3621</pre></td></tr> 3622 3623 3624<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> 3625<tr><td colspan="4" class="doc" id="hasName0"><pre>Matches NamedDecl nodes that have the specified name. 3626 3627Supports specifying enclosing namespaces or classes by prefixing the name 3628with '<enclosing>::'. 3629Does not match typedefs of an underlying type with the given name. 3630 3631Example matches X (Name == "X") 3632 class X; 3633 3634Example matches X (Name is one of "::a::b::X", "a::b::X", "b::X", "X") 3635 namespace a { namespace b { class X; } } 3636</pre></td></tr> 3637 3638 3639<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>std::string RegExp</td></tr> 3640<tr><td colspan="4" class="doc" id="matchesName0"><pre>Matches NamedDecl nodes whose fully qualified names contain 3641a substring matched by the given RegExp. 3642 3643Supports specifying enclosing namespaces or classes by 3644prefixing the name with '<enclosing>::'. Does not match typedefs 3645of an underlying type with the given name. 3646 3647Example matches X (regexp == "::X") 3648 class X; 3649 3650Example matches X (regexp is one of "::X", "^foo::.*X", among others) 3651 namespace foo { namespace bar { class X; } } 3652</pre></td></tr> 3653 3654 3655<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> 3656<tr><td colspan="4" class="doc" id="isAnonymous0"><pre>Matches anonymous namespace declarations. 3657 3658Given 3659 namespace n { 3660 namespace {} // #1 3661 } 3662namespaceDecl(isAnonymous()) will match #1 but not ::n. 3663</pre></td></tr> 3664 3665 3666<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> 3667<tr><td colspan="4" class="doc" id="isInline0"><pre>Matches function and namespace declarations that are marked with 3668the inline keyword. 3669 3670Given 3671 inline void f(); 3672 void g(); 3673 namespace n { 3674 inline namespace m {} 3675 } 3676functionDecl(isInline()) will match ::f(). 3677namespaceDecl(isInline()) will match n::m. 3678</pre></td></tr> 3679 3680 3681<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> 3682<tr><td colspan="4" class="doc" id="isNoneKind0"><pre>Matches if the OpenMP ``default`` clause has ``none`` kind specified. 3683 3684Given 3685 3686 #pragma omp parallel 3687 #pragma omp parallel default(none) 3688 #pragma omp parallel default(shared) 3689 3690``ompDefaultClause(isNoneKind())`` matches only ``default(none)``. 3691</pre></td></tr> 3692 3693 3694<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> 3695<tr><td colspan="4" class="doc" id="isSharedKind0"><pre>Matches if the OpenMP ``default`` clause has ``shared`` kind specified. 3696 3697Given 3698 3699 #pragma omp parallel 3700 #pragma omp parallel default(none) 3701 #pragma omp parallel default(shared) 3702 3703``ompDefaultClause(isSharedKind())`` matches only ``default(shared)``. 3704</pre></td></tr> 3705 3706 3707<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPExecutableDirective.html">OMPExecutableDirective</a>></td><td class="name" onclick="toggle('isAllowedToContainClauseKind0')"><a name="isAllowedToContainClauseKind0Anchor">isAllowedToContainClauseKind</a></td><td>OpenMPClauseKind CKind</td></tr> 3708<tr><td colspan="4" class="doc" id="isAllowedToContainClauseKind0"><pre>Matches if the OpenMP directive is allowed to contain the specified OpenMP 3709clause kind. 3710 3711Given 3712 3713 #pragma omp parallel 3714 #pragma omp parallel for 3715 #pragma omp for 3716 3717`ompExecutableDirective(isAllowedToContainClause(OMPC_default))`` matches 3718``omp parallel`` and ``omp parallel for``. 3719 3720If the matcher is use from clang-query, ``OpenMPClauseKind`` parameter 3721should be passed as a quoted string. e.g., 3722``isAllowedToContainClauseKind("OMPC_default").`` 3723</pre></td></tr> 3724 3725 3726<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPExecutableDirective.html">OMPExecutableDirective</a>></td><td class="name" onclick="toggle('isStandaloneDirective0')"><a name="isStandaloneDirective0Anchor">isStandaloneDirective</a></td><td></td></tr> 3727<tr><td colspan="4" class="doc" id="isStandaloneDirective0"><pre>Matches standalone OpenMP directives, 3728i.e., directives that can't have a structured block. 3729 3730Given 3731 3732 #pragma omp parallel 3733 {} 3734 #pragma omp taskyield 3735 3736``ompExecutableDirective(isStandaloneDirective()))`` matches 3737``omp taskyield``. 3738</pre></td></tr> 3739 3740 3741<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> 3742<tr><td colspan="4" class="doc" id="isDerivedFrom3"><pre>Overloaded method as shortcut for isDerivedFrom(hasName(...)). 3743</pre></td></tr> 3744 3745 3746<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> 3747<tr><td colspan="4" class="doc" id="isDirectlyDerivedFrom3"><pre>Overloaded method as shortcut for isDirectlyDerivedFrom(hasName(...)). 3748</pre></td></tr> 3749 3750 3751<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> 3752<tr><td colspan="4" class="doc" id="isSameOrDerivedFrom3"><pre>Overloaded method as shortcut for 3753isSameOrDerivedFrom(hasName(...)). 3754</pre></td></tr> 3755 3756 3757<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>></td><td class="name" onclick="toggle('argumentCountIs2')"><a name="argumentCountIs2Anchor">argumentCountIs</a></td><td>unsigned N</td></tr> 3758<tr><td colspan="4" class="doc" id="argumentCountIs2"><pre>Checks that a call expression or a constructor call expression has 3759a specific number of arguments (including absent default arguments). 3760 3761Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2))) 3762 void f(int x, int y); 3763 f(0, 0); 3764</pre></td></tr> 3765 3766 3767<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> 3768<tr><td colspan="4" class="doc" id="hasAnySelector0"><pre>Matches when at least one of the supplied string equals to the 3769Selector.getAsString() 3770 3771 matcher = objCMessageExpr(hasSelector("methodA:", "methodB:")); 3772 matches both of the expressions below: 3773 [myObj methodA:argA]; 3774 [myObj methodB:argB]; 3775</pre></td></tr> 3776 3777 3778<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> 3779<tr><td colspan="4" class="doc" id="hasKeywordSelector0"><pre>Matches when the selector is a keyword selector 3780 3781objCMessageExpr(hasKeywordSelector()) matches the generated setFrame 3782message expression in 3783 3784 UIWebView *webView = ...; 3785 CGRect bodyFrame = webView.frame; 3786 bodyFrame.size.height = self.bodyContentHeight; 3787 webView.frame = bodyFrame; 3788 // ^---- matches here 3789</pre></td></tr> 3790 3791 3792<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> 3793<tr><td colspan="4" class="doc" id="hasNullSelector0"><pre>Matches when the selector is the empty selector 3794 3795Matches only when the selector of the objCMessageExpr is NULL. This may 3796represent an error condition in the tree! 3797</pre></td></tr> 3798 3799 3800<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> 3801<tr><td colspan="4" class="doc" id="hasSelector0"><pre>Matches when BaseName == Selector.getAsString() 3802 3803 matcher = objCMessageExpr(hasSelector("loadHTMLString:baseURL:")); 3804 matches the outer message expr in the code below, but NOT the message 3805 invocation for self.bodyView. 3806 [self.bodyView loadHTMLString:html baseURL:NULL]; 3807</pre></td></tr> 3808 3809 3810<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> 3811<tr><td colspan="4" class="doc" id="hasUnarySelector0"><pre>Matches when the selector is a Unary Selector 3812 3813 matcher = objCMessageExpr(matchesSelector(hasUnarySelector()); 3814 matches self.bodyView in the code below, but NOT the outer message 3815 invocation of "loadHTMLString:baseURL:". 3816 [self.bodyView loadHTMLString:html baseURL:NULL]; 3817</pre></td></tr> 3818 3819 3820<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> 3821<tr><td colspan="4" class="doc" id="isClassMessage0"><pre>Returns true when the Objective-C message is sent to a class. 3822 3823Example 3824matcher = objcMessageExpr(isClassMessage()) 3825matches 3826 [NSString stringWithFormat:@"format"]; 3827but not 3828 NSString *x = @"hello"; 3829 [x containsString:@"h"]; 3830</pre></td></tr> 3831 3832 3833<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> 3834<tr><td colspan="4" class="doc" id="isInstanceMessage0"><pre>Returns true when the Objective-C message is sent to an instance. 3835 3836Example 3837matcher = objcMessageExpr(isInstanceMessage()) 3838matches 3839 NSString *x = @"hello"; 3840 [x containsString:@"h"]; 3841but not 3842 [NSString stringWithFormat:@"format"]; 3843</pre></td></tr> 3844 3845 3846<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>std::string RegExp</td></tr> 3847<tr><td colspan="4" class="doc" id="matchesSelector0"><pre>Matches ObjC selectors whose name contains 3848a substring matched by the given RegExp. 3849 matcher = objCMessageExpr(matchesSelector("loadHTMLStringmatches the outer message expr in the code below, but NOT the message 3850 invocation for self.bodyView. 3851 [self.bodyView loadHTMLString:html baseURL:NULL]; 3852</pre></td></tr> 3853 3854 3855<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> 3856<tr><td colspan="4" class="doc" id="numSelectorArgs0"><pre>Matches when the selector has the specified number of arguments 3857 3858 matcher = objCMessageExpr(numSelectorArgs(0)); 3859 matches self.bodyView in the code below 3860 3861 matcher = objCMessageExpr(numSelectorArgs(2)); 3862 matches the invocation of "loadHTMLString:baseURL:" but not that 3863 of self.bodyView 3864 [self.bodyView loadHTMLString:html baseURL:NULL]; 3865</pre></td></tr> 3866 3867 3868<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> 3869<tr><td colspan="4" class="doc" id="isClassMethod0"><pre>Returns true when the Objective-C method declaration is a class method. 3870 3871Example 3872matcher = objcMethodDecl(isClassMethod()) 3873matches 3874@interface I + (void)foo; @end 3875but not 3876@interface I - (void)bar; @end 3877</pre></td></tr> 3878 3879 3880<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> 3881<tr><td colspan="4" class="doc" id="isDefinition2"><pre>Matches if a declaration has a body attached. 3882 3883Example matches A, va, fa 3884 class A {}; 3885 class B; // Doesn't match, as it has no body. 3886 int va; 3887 extern int vb; // Doesn't match, as it doesn't define the variable. 3888 void fa() {} 3889 void fb(); // Doesn't match, as it has no body. 3890 @interface X 3891 - (void)ma; // Doesn't match, interface is declaration. 3892 @end 3893 @implementation X 3894 - (void)ma {} 3895 @end 3896 3897Usable 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>>, 3898 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html">ObjCMethodDecl</a>> 3899</pre></td></tr> 3900 3901 3902<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> 3903<tr><td colspan="4" class="doc" id="isInstanceMethod0"><pre>Returns true when the Objective-C method declaration is an instance method. 3904 3905Example 3906matcher = objcMethodDecl(isInstanceMethod()) 3907matches 3908@interface I - (void)bar; @end 3909but not 3910@interface I + (void)foo; @end 3911</pre></td></tr> 3912 3913 3914<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> 3915<tr><td colspan="4" class="doc" id="hasDefaultArgument0"><pre>Matches a declaration that has default arguments. 3916 3917Example matches y (matcher = parmVarDecl(hasDefaultArgument())) 3918void x(int val) {} 3919void y(int val = 0) {} 3920 3921Deprecated. Use hasInitializer() instead to be able to 3922match on the contents of the default argument. For example: 3923 3924void x(int val = 7) {} 3925void y(int val = 42) {} 3926parmVarDecl(hasInitializer(integerLiteral(equals(42)))) 3927 matches the parameter of y 3928 3929A matcher such as 3930 parmVarDecl(hasInitializer(anything())) 3931is equivalent to parmVarDecl(hasDefaultArgument()). 3932</pre></td></tr> 3933 3934 3935<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> 3936<tr><td colspan="4" class="doc" id="asString0"><pre>Matches if the matched type is represented by the given string. 3937 3938Given 3939 class Y { public: void x(); }; 3940 void z() { Y* y; y->x(); } 3941cxxMemberCallExpr(on(hasType(asString("class Y *")))) 3942 matches y->x() 3943</pre></td></tr> 3944 3945 3946<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> 3947<tr><td colspan="4" class="doc" id="equalsBoundNode3"><pre>Matches if a node equals a previously bound node. 3948 3949Matches a node if it equals the node previously bound to ID. 3950 3951Given 3952 class X { int a; int b; }; 3953cxxRecordDecl( 3954 has(fieldDecl(hasName("a"), hasType(type().bind("t")))), 3955 has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t")))))) 3956 matches the class X, as a and b have the same type. 3957 3958Note that when multiple matches are involved via forEach* matchers, 3959equalsBoundNodes acts as a filter. 3960For example: 3961compoundStmt( 3962 forEachDescendant(varDecl().bind("d")), 3963 forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d")))))) 3964will trigger a match for each combination of variable declaration 3965and reference to that variable declaration within a compound statement. 3966</pre></td></tr> 3967 3968 3969<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> 3970<tr><td colspan="4" class="doc" id="hasLocalQualifiers0"><pre>Matches QualType nodes that have local CV-qualifiers attached to 3971the node, not hidden within a typedef. 3972 3973Given 3974 typedef const int const_int; 3975 const_int i; 3976 int *const j; 3977 int *volatile k; 3978 int m; 3979varDecl(hasType(hasLocalQualifiers())) matches only j and k. 3980i is const-qualified but the qualifier is not local. 3981</pre></td></tr> 3982 3983 3984<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> 3985<tr><td colspan="4" class="doc" id="isAnyCharacter0"><pre>Matches QualType nodes that are of character type. 3986 3987Given 3988 void a(char); 3989 void b(wchar_t); 3990 void c(double); 3991functionDecl(hasAnyParameter(hasType(isAnyCharacter()))) 3992matches "a(char)", "b(wchar_t)", but not "c(double)". 3993</pre></td></tr> 3994 3995 3996<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> 3997<tr><td colspan="4" class="doc" id="isAnyPointer0"><pre>Matches QualType nodes that are of any pointer type; this includes 3998the Objective-C object pointer type, which is different despite being 3999syntactically similar. 4000 4001Given 4002 int *i = nullptr; 4003 4004 @interface Foo 4005 @end 4006 Foo *f; 4007 4008 int j; 4009varDecl(hasType(isAnyPointer())) 4010 matches "int *i" and "Foo *f", but not "int j". 4011</pre></td></tr> 4012 4013 4014<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> 4015<tr><td colspan="4" class="doc" id="isConstQualified0"><pre>Matches QualType nodes that are const-qualified, i.e., that 4016include "top-level" const. 4017 4018Given 4019 void a(int); 4020 void b(int const); 4021 void c(const int); 4022 void d(const int*); 4023 void e(int const) {}; 4024functionDecl(hasAnyParameter(hasType(isConstQualified()))) 4025 matches "void b(int const)", "void c(const int)" and 4026 "void e(int const) {}". It does not match d as there 4027 is no top-level const on the parameter type "const int *". 4028</pre></td></tr> 4029 4030 4031<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> 4032<tr><td colspan="4" class="doc" id="isInteger0"><pre>Matches QualType nodes that are of integer type. 4033 4034Given 4035 void a(int); 4036 void b(long); 4037 void c(double); 4038functionDecl(hasAnyParameter(hasType(isInteger()))) 4039matches "a(int)", "b(long)", but not "c(double)". 4040</pre></td></tr> 4041 4042 4043<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> 4044<tr><td colspan="4" class="doc" id="isSignedInteger0"><pre>Matches QualType nodes that are of signed integer type. 4045 4046Given 4047 void a(int); 4048 void b(unsigned long); 4049 void c(double); 4050functionDecl(hasAnyParameter(hasType(isSignedInteger()))) 4051matches "a(int)", but not "b(unsigned long)" and "c(double)". 4052</pre></td></tr> 4053 4054 4055<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> 4056<tr><td colspan="4" class="doc" id="isUnsignedInteger0"><pre>Matches QualType nodes that are of unsigned integer type. 4057 4058Given 4059 void a(int); 4060 void b(unsigned long); 4061 void c(double); 4062functionDecl(hasAnyParameter(hasType(isUnsignedInteger()))) 4063matches "b(unsigned long)", but not "a(int)" and "c(double)". 4064</pre></td></tr> 4065 4066 4067<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> 4068<tr><td colspan="4" class="doc" id="isVolatileQualified0"><pre>Matches QualType nodes that are volatile-qualified, i.e., that 4069include "top-level" volatile. 4070 4071Given 4072 void a(int); 4073 void b(int volatile); 4074 void c(volatile int); 4075 void d(volatile int*); 4076 void e(int volatile) {}; 4077functionDecl(hasAnyParameter(hasType(isVolatileQualified()))) 4078 matches "void b(int volatile)", "void c(volatile int)" and 4079 "void e(int volatile) {}". It does not match d as there 4080 is no top-level volatile on the parameter type "volatile int *". 4081</pre></td></tr> 4082 4083 4084<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> 4085<tr><td colspan="4" class="doc" id="equalsBoundNode0"><pre>Matches if a node equals a previously bound node. 4086 4087Matches a node if it equals the node previously bound to ID. 4088 4089Given 4090 class X { int a; int b; }; 4091cxxRecordDecl( 4092 has(fieldDecl(hasName("a"), hasType(type().bind("t")))), 4093 has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t")))))) 4094 matches the class X, as a and b have the same type. 4095 4096Note that when multiple matches are involved via forEach* matchers, 4097equalsBoundNodes acts as a filter. 4098For example: 4099compoundStmt( 4100 forEachDescendant(varDecl().bind("d")), 4101 forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d")))))) 4102will trigger a match for each combination of variable declaration 4103and reference to that variable declaration within a compound statement. 4104</pre></td></tr> 4105 4106 4107<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> 4108<tr><td colspan="4" class="doc" id="equalsNode1"><pre>Matches if a node equals another node. 4109 4110Stmt has pointer identity in the AST. 4111</pre></td></tr> 4112 4113 4114<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('isExpandedFromMacro0')"><a name="isExpandedFromMacro0Anchor">isExpandedFromMacro</a></td><td>llvm::StringRef MacroName</td></tr> 4115<tr><td colspan="4" class="doc" id="isExpandedFromMacro0"><pre>Matches statements that are (transitively) expanded from the named macro. 4116Does not match if only part of the statement is expanded from that macro or 4117if different parts of the the statement are expanded from different 4118appearances of the macro. 4119 4120FIXME: Change to be a polymorphic matcher that works on any syntactic 4121node. There's nothing `Stmt`-specific about it. 4122</pre></td></tr> 4123 4124 4125<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>std::string RegExp</td></tr> 4126<tr><td colspan="4" class="doc" id="isExpansionInFileMatching1"><pre>Matches AST nodes that were expanded within files whose name is 4127partially matching a given regex. 4128 4129Example matches Y but not X 4130 (matcher = cxxRecordDecl(isExpansionInFileMatching("AST.*")) 4131 #include "ASTMatcher.h" 4132 class X {}; 4133ASTMatcher.h: 4134 class Y {}; 4135 4136Usable 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>> 4137</pre></td></tr> 4138 4139 4140<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> 4141<tr><td colspan="4" class="doc" id="isExpansionInMainFile1"><pre>Matches AST nodes that were expanded within the main-file. 4142 4143Example matches X but not Y 4144 (matcher = cxxRecordDecl(isExpansionInMainFile()) 4145 #include <Y.h> 4146 class X {}; 4147Y.h: 4148 class Y {}; 4149 4150Usable 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>> 4151</pre></td></tr> 4152 4153 4154<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> 4155<tr><td colspan="4" class="doc" id="isExpansionInSystemHeader1"><pre>Matches AST nodes that were expanded within system-header-files. 4156 4157Example matches Y but not X 4158 (matcher = cxxRecordDecl(isExpansionInSystemHeader()) 4159 #include <SystemHeader.h> 4160 class X {}; 4161SystemHeader.h: 4162 class Y {}; 4163 4164Usable 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>> 4165</pre></td></tr> 4166 4167 4168<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> 4169<tr><td colspan="4" class="doc" id="isInTemplateInstantiation0"><pre>Matches statements inside of a template instantiation. 4170 4171Given 4172 int j; 4173 template<typename T> void A(T t) { T i; j += 42;} 4174 A(0); 4175 A(0U); 4176declStmt(isInTemplateInstantiation()) 4177 matches 'int i;' and 'unsigned i'. 4178unless(stmt(isInTemplateInstantiation())) 4179 will NOT match j += 42; as it's shared between the template definition and 4180 instantiation. 4181</pre></td></tr> 4182 4183 4184<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> 4185<tr><td colspan="4" class="doc" id="hasSize1"><pre>Matches nodes that have the specified size. 4186 4187Given 4188 int a[42]; 4189 int b[2 * 21]; 4190 int c[41], d[43]; 4191 char *s = "abcd"; 4192 wchar_t *ws = L"abcd"; 4193 char *w = "a"; 4194constantArrayType(hasSize(42)) 4195 matches "int a[42]" and "int b[2 * 21]" 4196stringLiteral(hasSize(4)) 4197 matches "abcd", L"abcd" 4198</pre></td></tr> 4199 4200 4201<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> 4202<tr><td colspan="4" class="doc" id="isClass0"><pre>Matches TagDecl object that are spelled with "class." 4203 4204Example matches C, but not S, U or E. 4205 struct S {}; 4206 class C {}; 4207 union U {}; 4208 enum E {}; 4209</pre></td></tr> 4210 4211 4212<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> 4213<tr><td colspan="4" class="doc" id="isDefinition0"><pre>Matches if a declaration has a body attached. 4214 4215Example matches A, va, fa 4216 class A {}; 4217 class B; // Doesn't match, as it has no body. 4218 int va; 4219 extern int vb; // Doesn't match, as it doesn't define the variable. 4220 void fa() {} 4221 void fb(); // Doesn't match, as it has no body. 4222 @interface X 4223 - (void)ma; // Doesn't match, interface is declaration. 4224 @end 4225 @implementation X 4226 - (void)ma {} 4227 @end 4228 4229Usable 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>>, 4230 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html">ObjCMethodDecl</a>> 4231</pre></td></tr> 4232 4233 4234<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> 4235<tr><td colspan="4" class="doc" id="isEnum0"><pre>Matches TagDecl object that are spelled with "enum." 4236 4237Example matches E, but not C, S or U. 4238 struct S {}; 4239 class C {}; 4240 union U {}; 4241 enum E {}; 4242</pre></td></tr> 4243 4244 4245<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> 4246<tr><td colspan="4" class="doc" id="isStruct0"><pre>Matches TagDecl object that are spelled with "struct." 4247 4248Example matches S, but not C, U or E. 4249 struct S {}; 4250 class C {}; 4251 union U {}; 4252 enum E {}; 4253</pre></td></tr> 4254 4255 4256<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> 4257<tr><td colspan="4" class="doc" id="isUnion0"><pre>Matches TagDecl object that are spelled with "union." 4258 4259Example matches U, but not C, S or E. 4260 struct S {}; 4261 class C {}; 4262 union U {}; 4263 enum E {}; 4264</pre></td></tr> 4265 4266 4267<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> 4268<tr><td colspan="4" class="doc" id="equalsIntegralValue0"><pre>Matches a TemplateArgument of integral type with a given value. 4269 4270Note that 'Value' is a string as the template argument's value is 4271an arbitrary precision integer. 'Value' must be euqal to the canonical 4272representation of that integral value in base 10. 4273 4274Given 4275 template<int T> struct C {}; 4276 C<42> c; 4277classTemplateSpecializationDecl( 4278 hasAnyTemplateArgument(equalsIntegralValue("42"))) 4279 matches the implicit instantiation of C in C<42>. 4280</pre></td></tr> 4281 4282 4283<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> 4284<tr><td colspan="4" class="doc" id="isIntegral0"><pre>Matches a TemplateArgument that is an integral value. 4285 4286Given 4287 template<int T> struct C {}; 4288 C<42> c; 4289classTemplateSpecializationDecl( 4290 hasAnyTemplateArgument(isIntegral())) 4291 matches the implicit instantiation of C in C<42> 4292 with isIntegral() matching 42. 4293</pre></td></tr> 4294 4295 4296<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>></td><td class="name" onclick="toggle('templateArgumentCountIs1')"><a name="templateArgumentCountIs1Anchor">templateArgumentCountIs</a></td><td>unsigned N</td></tr> 4297<tr><td colspan="4" class="doc" id="templateArgumentCountIs1"><pre>Matches if the number of template arguments equals N. 4298 4299Given 4300 template<typename T> struct C {}; 4301 C<int> c; 4302classTemplateSpecializationDecl(templateArgumentCountIs(1)) 4303 matches C<int>. 4304</pre></td></tr> 4305 4306 4307<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>std::string RegExp</td></tr> 4308<tr><td colspan="4" class="doc" id="isExpansionInFileMatching2"><pre>Matches AST nodes that were expanded within files whose name is 4309partially matching a given regex. 4310 4311Example matches Y but not X 4312 (matcher = cxxRecordDecl(isExpansionInFileMatching("AST.*")) 4313 #include "ASTMatcher.h" 4314 class X {}; 4315ASTMatcher.h: 4316 class Y {}; 4317 4318Usable 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>> 4319</pre></td></tr> 4320 4321 4322<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> 4323<tr><td colspan="4" class="doc" id="isExpansionInMainFile2"><pre>Matches AST nodes that were expanded within the main-file. 4324 4325Example matches X but not Y 4326 (matcher = cxxRecordDecl(isExpansionInMainFile()) 4327 #include <Y.h> 4328 class X {}; 4329Y.h: 4330 class Y {}; 4331 4332Usable 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>> 4333</pre></td></tr> 4334 4335 4336<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> 4337<tr><td colspan="4" class="doc" id="isExpansionInSystemHeader2"><pre>Matches AST nodes that were expanded within system-header-files. 4338 4339Example matches Y but not X 4340 (matcher = cxxRecordDecl(isExpansionInSystemHeader()) 4341 #include <SystemHeader.h> 4342 class X {}; 4343SystemHeader.h: 4344 class Y {}; 4345 4346Usable 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>> 4347</pre></td></tr> 4348 4349 4350<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> 4351<tr><td colspan="4" class="doc" id="booleanType0"><pre>Matches type bool. 4352 4353Given 4354 struct S { bool func(); }; 4355functionDecl(returns(booleanType())) 4356 matches "bool func();" 4357</pre></td></tr> 4358 4359 4360<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> 4361<tr><td colspan="4" class="doc" id="equalsBoundNode2"><pre>Matches if a node equals a previously bound node. 4362 4363Matches a node if it equals the node previously bound to ID. 4364 4365Given 4366 class X { int a; int b; }; 4367cxxRecordDecl( 4368 has(fieldDecl(hasName("a"), hasType(type().bind("t")))), 4369 has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t")))))) 4370 matches the class X, as a and b have the same type. 4371 4372Note that when multiple matches are involved via forEach* matchers, 4373equalsBoundNodes acts as a filter. 4374For example: 4375compoundStmt( 4376 forEachDescendant(varDecl().bind("d")), 4377 forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d")))))) 4378will trigger a match for each combination of variable declaration 4379and reference to that variable declaration within a compound statement. 4380</pre></td></tr> 4381 4382 4383<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> 4384<tr><td colspan="4" class="doc" id="equalsNode2"><pre>Matches if a node equals another node. 4385 4386Type has pointer identity in the AST. 4387</pre></td></tr> 4388 4389 4390<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> 4391<tr><td colspan="4" class="doc" id="realFloatingPointType0"><pre>Matches any real floating-point type (float, double, long double). 4392 4393Given 4394 int i; 4395 float f; 4396realFloatingPointType() 4397 matches "float f" but not "int i" 4398</pre></td></tr> 4399 4400 4401<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> 4402<tr><td colspan="4" class="doc" id="voidType0"><pre>Matches type void. 4403 4404Given 4405 struct S { void func(); }; 4406functionDecl(returns(voidType())) 4407 matches "void func();" 4408</pre></td></tr> 4409 4410 4411<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> 4412<tr><td colspan="4" class="doc" id="ofKind0"><pre>Matches unary expressions of a certain kind. 4413 4414Given 4415 int x; 4416 int s = sizeof(x) + alignof(x) 4417unaryExprOrTypeTraitExpr(ofKind(UETT_SizeOf)) 4418 matches sizeof(x) 4419 4420If the matcher is use from clang-query, UnaryExprOrTypeTrait parameter 4421should be passed as a quoted string. e.g., ofKind("UETT_SizeOf"). 4422</pre></td></tr> 4423 4424 4425<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnaryOperator.html">UnaryOperator</a>></td><td class="name" onclick="toggle('hasAnyOperatorName1')"><a name="hasAnyOperatorName1Anchor">hasAnyOperatorName</a></td><td>StringRef, ..., StringRef</td></tr> 4426<tr><td colspan="4" class="doc" id="hasAnyOperatorName1"><pre>Matches operator expressions (binary or unary) that have any of the 4427specified names. 4428 4429 hasAnyOperatorName("+", "-") 4430 Is equivalent to 4431 anyOf(hasOperatorName("+"), hasOperatorName("-")) 4432</pre></td></tr> 4433 4434 4435<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnaryOperator.html">UnaryOperator</a>></td><td class="name" onclick="toggle('hasOperatorName1')"><a name="hasOperatorName1Anchor">hasOperatorName</a></td><td>std::string Name</td></tr> 4436<tr><td colspan="4" class="doc" id="hasOperatorName1"><pre>Matches the operator Name of operator expressions (binary or 4437unary). 4438 4439Example matches a || b (matcher = binaryOperator(hasOperatorName("||"))) 4440 !(a || b) 4441</pre></td></tr> 4442 4443 4444<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> 4445<tr><td colspan="4" class="doc" id="isArrow1"><pre>Matches member expressions that are called with '->' as opposed 4446to '.'. 4447 4448Member calls on the implicit this pointer match as called with '->'. 4449 4450Given 4451 class Y { 4452 void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; } 4453 template <class T> void f() { this->f<T>(); f<T>(); } 4454 int a; 4455 static int b; 4456 }; 4457 template <class T> 4458 class Z { 4459 void x() { this->m; } 4460 }; 4461memberExpr(isArrow()) 4462 matches this->x, x, y.x, a, this->b 4463cxxDependentScopeMemberExpr(isArrow()) 4464 matches this->m 4465unresolvedMemberExpr(isArrow()) 4466 matches this->f<T>, f<T> 4467</pre></td></tr> 4468 4469 4470<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> 4471<tr><td colspan="4" class="doc" id="hasAutomaticStorageDuration0"><pre>Matches a variable declaration that has automatic storage duration. 4472 4473Example matches x, but not y, z, or a. 4474(matcher = varDecl(hasAutomaticStorageDuration()) 4475void f() { 4476 int x; 4477 static int y; 4478 thread_local int z; 4479} 4480int a; 4481</pre></td></tr> 4482 4483 4484<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> 4485<tr><td colspan="4" class="doc" id="hasGlobalStorage0"><pre>Matches a variable declaration that does not have local storage. 4486 4487Example matches y and z (matcher = varDecl(hasGlobalStorage()) 4488void f() { 4489 int x; 4490 static int y; 4491} 4492int z; 4493</pre></td></tr> 4494 4495 4496<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> 4497<tr><td colspan="4" class="doc" id="hasLocalStorage0"><pre>Matches a variable declaration that has function scope and is a 4498non-static local variable. 4499 4500Example matches x (matcher = varDecl(hasLocalStorage()) 4501void f() { 4502 int x; 4503 static int y; 4504} 4505int z; 4506</pre></td></tr> 4507 4508 4509<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> 4510<tr><td colspan="4" class="doc" id="hasStaticStorageDuration0"><pre>Matches a variable declaration that has static storage duration. 4511It includes the variable declared at namespace scope and those declared 4512with "static" and "extern" storage class specifiers. 4513 4514void f() { 4515 int x; 4516 static int y; 4517 thread_local int z; 4518} 4519int a; 4520static int b; 4521extern int c; 4522varDecl(hasStaticStorageDuration()) 4523 matches the function declaration y, a, b and c. 4524</pre></td></tr> 4525 4526 4527<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> 4528<tr><td colspan="4" class="doc" id="hasThreadStorageDuration0"><pre>Matches a variable declaration that has thread storage duration. 4529 4530Example matches z, but not x, z, or a. 4531(matcher = varDecl(hasThreadStorageDuration()) 4532void f() { 4533 int x; 4534 static int y; 4535 thread_local int z; 4536} 4537int a; 4538</pre></td></tr> 4539 4540 4541<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> 4542<tr><td colspan="4" class="doc" id="isConstexpr0"><pre>Matches constexpr variable and function declarations, 4543 and if constexpr. 4544 4545Given: 4546 constexpr int foo = 42; 4547 constexpr int bar(); 4548 void baz() { if constexpr(1 > 0) {} } 4549varDecl(isConstexpr()) 4550 matches the declaration of foo. 4551functionDecl(isConstexpr()) 4552 matches the declaration of bar. 4553ifStmt(isConstexpr()) 4554 matches the if statement in baz. 4555</pre></td></tr> 4556 4557 4558<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> 4559<tr><td colspan="4" class="doc" id="isDefinition1"><pre>Matches if a declaration has a body attached. 4560 4561Example matches A, va, fa 4562 class A {}; 4563 class B; // Doesn't match, as it has no body. 4564 int va; 4565 extern int vb; // Doesn't match, as it doesn't define the variable. 4566 void fa() {} 4567 void fb(); // Doesn't match, as it has no body. 4568 @interface X 4569 - (void)ma; // Doesn't match, interface is declaration. 4570 @end 4571 @implementation X 4572 - (void)ma {} 4573 @end 4574 4575Usable 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>>, 4576 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html">ObjCMethodDecl</a>> 4577</pre></td></tr> 4578 4579 4580<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> 4581<tr><td colspan="4" class="doc" id="isExceptionVariable0"><pre>Matches a variable declaration that is an exception variable from 4582a C++ catch block, or an Objective-C statement. 4583 4584Example matches x (matcher = varDecl(isExceptionVariable()) 4585void f(int y) { 4586 try { 4587 } catch (int x) { 4588 } 4589} 4590</pre></td></tr> 4591 4592 4593<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> 4594<tr><td colspan="4" class="doc" id="isExplicitTemplateSpecialization1"><pre>Matches explicit template specializations of function, class, or 4595static member variable template instantiations. 4596 4597Given 4598 template<typename T> void A(T t) { } 4599 template<> void A(int N) { } 4600functionDecl(isExplicitTemplateSpecialization()) 4601 matches the specialization A<int>(). 4602 4603Usable 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>> 4604</pre></td></tr> 4605 4606 4607<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> 4608<tr><td colspan="4" class="doc" id="isExternC1"><pre>Matches extern "C" function or variable declarations. 4609 4610Given: 4611 extern "C" void f() {} 4612 extern "C" { void g() {} } 4613 void h() {} 4614 extern "C" int x = 1; 4615 extern "C" int y = 2; 4616 int z = 3; 4617functionDecl(isExternC()) 4618 matches the declaration of f and g, but not the declaration of h. 4619varDecl(isExternC()) 4620 matches the declaration of x and y, but not the declaration of z. 4621</pre></td></tr> 4622 4623 4624<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> 4625<tr><td colspan="4" class="doc" id="isStaticLocal0"><pre>Matches a static variable with local scope. 4626 4627Example matches y (matcher = varDecl(isStaticLocal())) 4628void f() { 4629 int x; 4630 static int y; 4631} 4632static int z; 4633</pre></td></tr> 4634 4635 4636<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> 4637<tr><td colspan="4" class="doc" id="isStaticStorageClass1"><pre>Matches variable/function declarations that have "static" storage 4638class specifier ("static" keyword) written in the source. 4639 4640Given: 4641 static void f() {} 4642 static int i = 0; 4643 extern int j; 4644 int k; 4645functionDecl(isStaticStorageClass()) 4646 matches the function declaration f. 4647varDecl(isStaticStorageClass()) 4648 matches the variable declaration i. 4649</pre></td></tr> 4650 4651 4652<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> 4653<tr><td colspan="4" class="doc" id="isTemplateInstantiation1"><pre>Matches template instantiations of function, class, or static 4654member variable template instantiations. 4655 4656Given 4657 template <typename T> class X {}; class A {}; X<A> x; 4658or 4659 template <typename T> class X {}; class A {}; template class X<A>; 4660or 4661 template <typename T> class X {}; class A {}; extern template class X<A>; 4662cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) 4663 matches the template instantiation of X<A>. 4664 4665But given 4666 template <typename T> class X {}; class A {}; 4667 template <> class X<A> {}; X<A> x; 4668cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) 4669 does not match, as X<A> is an explicit template specialization. 4670 4671Usable 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>> 4672</pre></td></tr> 4673 4674<!--END_NARROWING_MATCHERS --> 4675</table> 4676 4677<!-- ======================================================================= --> 4678<h2 id="traversal-matchers">AST Traversal Matchers</h2> 4679<!-- ======================================================================= --> 4680 4681<p>Traversal matchers specify the relationship to other nodes that are 4682reachable from the current node.</p> 4683 4684<p>Note that there are special traversal matchers (has, hasDescendant, forEach and 4685forEachDescendant) which work on all nodes and allow users to write more generic 4686match expressions.</p> 4687 4688<table> 4689<tr style="text-align:left"><th>Return type</th><th>Name</th><th>Parameters</th></tr> 4690<!-- START_TRAVERSAL_MATCHERS --> 4691 4692<tr><td>Matcher<*></td><td class="name" onclick="toggle('eachOf0')"><a name="eachOf0Anchor">eachOf</a></td><td>Matcher<*>, ..., Matcher<*></td></tr> 4693<tr><td colspan="4" class="doc" id="eachOf0"><pre>Matches if any of the given matchers matches. 4694 4695Unlike anyOf, eachOf will generate a match result for each 4696matching submatcher. 4697 4698For example, in: 4699 class A { int a; int b; }; 4700The matcher: 4701 cxxRecordDecl(eachOf(has(fieldDecl(hasName("a")).bind("v")), 4702 has(fieldDecl(hasName("b")).bind("v")))) 4703will generate two results binding "v", the first of which binds 4704the field declaration of a, the second the field declaration of 4705b. 4706 4707Usable as: Any Matcher 4708</pre></td></tr> 4709 4710 4711<tr><td>Matcher<*></td><td class="name" onclick="toggle('findAll0')"><a name="findAll0Anchor">findAll</a></td><td>Matcher<*> Matcher</td></tr> 4712<tr><td colspan="4" class="doc" id="findAll0"><pre>Matches if the node or any descendant matches. 4713 4714Generates results for each match. 4715 4716For example, in: 4717 class A { class B {}; class C {}; }; 4718The matcher: 4719 cxxRecordDecl(hasName("::A"), 4720 findAll(cxxRecordDecl(isDefinition()).bind("m"))) 4721will generate results for A, B and C. 4722 4723Usable as: Any Matcher 4724</pre></td></tr> 4725 4726 4727<tr><td>Matcher<*></td><td class="name" onclick="toggle('forEachDescendant0')"><a name="forEachDescendant0Anchor">forEachDescendant</a></td><td>Matcher<*></td></tr> 4728<tr><td colspan="4" class="doc" id="forEachDescendant0"><pre>Matches AST nodes that have descendant AST nodes that match the 4729provided matcher. 4730 4731Example matches X, A, A::X, B, B::C, B::C::X 4732 (matcher = cxxRecordDecl(forEachDescendant(cxxRecordDecl(hasName("X"))))) 4733 class X {}; 4734 class A { class X {}; }; // Matches A, because A::X is a class of name 4735 // X inside A. 4736 class B { class C { class X {}; }; }; 4737 4738DescendantT must be an AST base type. 4739 4740As opposed to 'hasDescendant', 'forEachDescendant' will cause a match for 4741each result that matches instead of only on the first one. 4742 4743Note: Recursively combined ForEachDescendant can cause many matches: 4744 cxxRecordDecl(forEachDescendant(cxxRecordDecl( 4745 forEachDescendant(cxxRecordDecl()) 4746 ))) 4747will match 10 times (plus injected class name matches) on: 4748 class A { class B { class C { class D { class E {}; }; }; }; }; 4749 4750Usable as: Any Matcher 4751</pre></td></tr> 4752 4753 4754<tr><td>Matcher<*></td><td class="name" onclick="toggle('forEach0')"><a name="forEach0Anchor">forEach</a></td><td>Matcher<*></td></tr> 4755<tr><td colspan="4" class="doc" id="forEach0"><pre>Matches AST nodes that have child AST nodes that match the 4756provided matcher. 4757 4758Example matches X, Y, Y::X, Z::Y, Z::Y::X 4759 (matcher = cxxRecordDecl(forEach(cxxRecordDecl(hasName("X"))) 4760 class X {}; 4761 class Y { class X {}; }; // Matches Y, because Y::X is a class of name X 4762 // inside Y. 4763 class Z { class Y { class X {}; }; }; // Does not match Z. 4764 4765ChildT must be an AST base type. 4766 4767As opposed to 'has', 'forEach' will cause a match for each result that 4768matches instead of only on the first one. 4769 4770Usable as: Any Matcher 4771</pre></td></tr> 4772 4773 4774<tr><td>Matcher<*></td><td class="name" onclick="toggle('hasAncestor0')"><a name="hasAncestor0Anchor">hasAncestor</a></td><td>Matcher<*></td></tr> 4775<tr><td colspan="4" class="doc" id="hasAncestor0"><pre>Matches AST nodes that have an ancestor that matches the provided 4776matcher. 4777 4778Given 4779void f() { if (true) { int x = 42; } } 4780void g() { for (;;) { int x = 43; } } 4781expr(integerLiteral(hasAncestor(ifStmt()))) matches 42, but not 43. 4782 4783Usable as: Any Matcher 4784</pre></td></tr> 4785 4786 4787<tr><td>Matcher<*></td><td class="name" onclick="toggle('hasDescendant0')"><a name="hasDescendant0Anchor">hasDescendant</a></td><td>Matcher<*></td></tr> 4788<tr><td colspan="4" class="doc" id="hasDescendant0"><pre>Matches AST nodes that have descendant AST nodes that match the 4789provided matcher. 4790 4791Example matches X, Y, Z 4792 (matcher = cxxRecordDecl(hasDescendant(cxxRecordDecl(hasName("X"))))) 4793 class X {}; // Matches X, because X::X is a class of name X inside X. 4794 class Y { class X {}; }; 4795 class Z { class Y { class X {}; }; }; 4796 4797DescendantT must be an AST base type. 4798 4799Usable as: Any Matcher 4800</pre></td></tr> 4801 4802 4803<tr><td>Matcher<*></td><td class="name" onclick="toggle('has0')"><a name="has0Anchor">has</a></td><td>Matcher<*></td></tr> 4804<tr><td colspan="4" class="doc" id="has0"><pre>Matches AST nodes that have child AST nodes that match the 4805provided matcher. 4806 4807Example matches X, Y 4808 (matcher = cxxRecordDecl(has(cxxRecordDecl(hasName("X"))) 4809 class X {}; // Matches X, because X::X is a class of name X inside X. 4810 class Y { class X {}; }; 4811 class Z { class Y { class X {}; }; }; // Does not match Z. 4812 4813ChildT must be an AST base type. 4814 4815Usable as: Any Matcher 4816Note that has is direct matcher, so it also matches things like implicit 4817casts and paren casts. If you are matching with expr then you should 4818probably consider using ignoringParenImpCasts like: 4819has(ignoringParenImpCasts(expr())). 4820</pre></td></tr> 4821 4822 4823<tr><td>Matcher<*></td><td class="name" onclick="toggle('hasParent0')"><a name="hasParent0Anchor">hasParent</a></td><td>Matcher<*></td></tr> 4824<tr><td colspan="4" class="doc" id="hasParent0"><pre>Matches AST nodes that have a parent that matches the provided 4825matcher. 4826 4827Given 4828void f() { for (;;) { int x = 42; if (true) { int x = 43; } } } 4829compoundStmt(hasParent(ifStmt())) matches "{ int x = 43; }". 4830 4831Usable as: Any Matcher 4832</pre></td></tr> 4833 4834 4835<tr><td>Matcher<*></td><td class="name" onclick="toggle('optionally0')"><a name="optionally0Anchor">optionally</a></td><td>Matcher<*></td></tr> 4836<tr><td colspan="4" class="doc" id="optionally0"><pre>Matches any node regardless of the submatcher. 4837 4838However, optionally will retain any bindings generated by the submatcher. 4839Useful when additional information which may or may not present about a main 4840matching node is desired. 4841 4842For example, in: 4843 class Foo { 4844 int bar; 4845 } 4846The matcher: 4847 cxxRecordDecl( 4848 optionally(has( 4849 fieldDecl(hasName("bar")).bind("var") 4850 ))).bind("record") 4851will produce a result binding for both "record" and "var". 4852The matcher will produce a "record" binding for even if there is no data 4853member named "bar" in that class. 4854 4855Usable as: Any Matcher 4856</pre></td></tr> 4857 4858 4859<tr><td>Matcher<*></td><td class="name" onclick="toggle('traverse0')"><a name="traverse0Anchor">traverse</a></td><td>TraversalKind TK, Matcher<*> InnerMatcher</td></tr> 4860<tr><td colspan="4" class="doc" id="traverse0"><pre>Causes all nested matchers to be matched with the specified traversal kind. 4861 4862Given 4863 void foo() 4864 { 4865 int i = 3.0; 4866 } 4867The matcher 4868 traverse(TK_IgnoreImplicitCastsAndParentheses, 4869 varDecl(hasInitializer(floatLiteral().bind("init"))) 4870 ) 4871matches the variable declaration with "init" bound to the "3.0". 4872</pre></td></tr> 4873 4874 4875<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> 4876<tr><td colspan="4" class="doc" id="hasCondition5"><pre>Matches the condition expression of an if statement, for loop, 4877switch statement or conditional operator. 4878 4879Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true)))) 4880 if (true) {} 4881</pre></td></tr> 4882 4883 4884<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> 4885<tr><td colspan="4" class="doc" id="hasFalseExpression0"><pre>Matches the false branch expression of a conditional operator 4886(binary or ternary). 4887 4888Example matches b 4889 condition ? a : b 4890 condition ?: b 4891</pre></td></tr> 4892 4893 4894<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> 4895<tr><td colspan="4" class="doc" id="hasTrueExpression0"><pre>Matches the true branch expression of a conditional operator. 4896 4897Example 1 (conditional ternary operator): matches a 4898 condition ? a : b 4899 4900Example 2 (conditional binary operator): matches opaqueValueExpr(condition) 4901 condition ?: b 4902</pre></td></tr> 4903 4904 4905<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</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> 4906<tr><td colspan="4" class="doc" id="hasDeclaration15"><pre>Matches a node if the declaration associated with that node 4907matches the given matcher. 4908 4909The associated declaration is: 4910- for type nodes, the declaration of the underlying type 4911- for CallExpr, the declaration of the callee 4912- for MemberExpr, the declaration of the referenced member 4913- for CXXConstructExpr, the declaration of the constructor 4914- for CXXNewExpr, the declaration of the operator new 4915- for ObjCIvarExpr, the declaration of the ivar 4916 4917For type nodes, hasDeclaration will generally match the declaration of the 4918sugared type. Given 4919 class X {}; 4920 typedef X Y; 4921 Y y; 4922in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 4923typedefDecl. A common use case is to match the underlying, desugared type. 4924This can be achieved by using the hasUnqualifiedDesugaredType matcher: 4925 varDecl(hasType(hasUnqualifiedDesugaredType( 4926 recordType(hasDeclaration(decl()))))) 4927In this matcher, the decl will match the CXXRecordDecl of class X. 4928 4929Usable 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>>, 4930 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>>, 4931 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, 4932 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<<a href="https://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, 4933 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, 4934 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, 4935 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 4936</pre></td></tr> 4937 4938 4939<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> 4940<tr><td colspan="4" class="doc" id="hasBase0"><pre>Matches the base expression of an array subscript expression. 4941 4942Given 4943 int i[5]; 4944 void f() { i[1] = 42; } 4945arraySubscriptExpression(hasBase(implicitCastExpr( 4946 hasSourceExpression(declRefExpr())))) 4947 matches i[1] with the declRefExpr() matching i 4948</pre></td></tr> 4949 4950 4951<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> 4952<tr><td colspan="4" class="doc" id="hasIndex0"><pre>Matches the index expression of an array subscript expression. 4953 4954Given 4955 int i[5]; 4956 void f() { i[1] = 42; } 4957arraySubscriptExpression(hasIndex(integerLiteral())) 4958 matches i[1] with the integerLiteral() matching 1 4959</pre></td></tr> 4960 4961 4962<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ArraySubscriptExpr.html">ArraySubscriptExpr</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> 4963<tr><td colspan="4" class="doc" id="hasLHS1"><pre>Matches the left hand side of binary operator expressions. 4964 4965Example matches a (matcher = binaryOperator(hasLHS())) 4966 a || b 4967</pre></td></tr> 4968 4969 4970<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ArraySubscriptExpr.html">ArraySubscriptExpr</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> 4971<tr><td colspan="4" class="doc" id="hasRHS1"><pre>Matches the right hand side of binary operator expressions. 4972 4973Example matches b (matcher = binaryOperator(hasRHS())) 4974 a || b 4975</pre></td></tr> 4976 4977 4978<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> 4979<tr><td colspan="4" class="doc" id="hasElementType0"><pre>Matches arrays and C99 complex types that have a specific element 4980type. 4981 4982Given 4983 struct A {}; 4984 A a[7]; 4985 int b[7]; 4986arrayType(hasElementType(builtinType())) 4987 matches "int b[7]" 4988 4989Usable 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>> 4990</pre></td></tr> 4991 4992 4993<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> 4994<tr><td colspan="4" class="doc" id="hasValueType0"><pre>Matches atomic types with a specific value type. 4995 4996Given 4997 _Atomic(int) i; 4998 _Atomic(float) f; 4999atomicType(hasValueType(isInteger())) 5000 matches "_Atomic(int) i" 5001 5002Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AtomicType.html">AtomicType</a>> 5003</pre></td></tr> 5004 5005 5006<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AutoType.html">AutoType</a>></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> 5007<tr><td colspan="4" class="doc" id="hasDeducedType0"><pre>Matches AutoType nodes where the deduced type is a specific type. 5008 5009Note: There is no TypeLoc for the deduced type and thus no 5010getDeducedLoc() matcher. 5011 5012Given 5013 auto a = 1; 5014 auto b = 2.0; 5015autoType(hasDeducedType(isInteger())) 5016 matches "auto a" 5017 5018Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AutoType.html">AutoType</a>> 5019</pre></td></tr> 5020 5021 5022<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> 5023<tr><td colspan="4" class="doc" id="hasEitherOperand0"><pre>Matches if either the left hand side or the right hand side of a 5024binary operator matches. 5025</pre></td></tr> 5026 5027 5028<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> 5029<tr><td colspan="4" class="doc" id="hasLHS0"><pre>Matches the left hand side of binary operator expressions. 5030 5031Example matches a (matcher = binaryOperator(hasLHS())) 5032 a || b 5033</pre></td></tr> 5034 5035 5036<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> 5037<tr><td colspan="4" class="doc" id="hasOperands0"><pre>Matches if both matchers match with opposite sides of the binary operator. 5038 5039Example matcher = binaryOperator(hasOperands(integerLiteral(equals(1), 5040 integerLiteral(equals(2))) 5041 1 + 2 // Match 5042 2 + 1 // Match 5043 1 + 1 // No match 5044 2 + 2 // No match 5045</pre></td></tr> 5046 5047 5048<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> 5049<tr><td colspan="4" class="doc" id="hasRHS0"><pre>Matches the right hand side of binary operator expressions. 5050 5051Example matches b (matcher = binaryOperator(hasRHS())) 5052 a || b 5053</pre></td></tr> 5054 5055 5056<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> 5057<tr><td colspan="4" class="doc" id="hasAnyParameter2"><pre>Matches any parameter of a function or an ObjC method declaration or a 5058block. 5059 5060Does not match the 'this' parameter of a method. 5061 5062Given 5063 class X { void f(int x, int y, int z) {} }; 5064cxxMethodDecl(hasAnyParameter(hasName("y"))) 5065 matches f(int x, int y, int z) {} 5066with hasAnyParameter(...) 5067 matching int y 5068 5069For ObjectiveC, given 5070 @interface I - (void) f:(int) y; @end 5071 5072the matcher objcMethodDecl(hasAnyParameter(hasName("y"))) 5073matches the declaration of method f with hasParameter 5074matching y. 5075 5076For blocks, given 5077 b = ^(int y) { printf("%d", y) }; 5078 5079the matcher blockDecl(hasAnyParameter(hasName("y"))) 5080matches the declaration of the block b with hasParameter 5081matching y. 5082</pre></td></tr> 5083 5084 5085<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> 5086<tr><td colspan="4" class="doc" id="hasParameter2"><pre>Matches the n'th parameter of a function or an ObjC method 5087declaration or a block. 5088 5089Given 5090 class X { void f(int x) {} }; 5091cxxMethodDecl(hasParameter(0, hasType(varDecl()))) 5092 matches f(int x) {} 5093with hasParameter(...) 5094 matching int x 5095 5096For ObjectiveC, given 5097 @interface I - (void) f:(int) y; @end 5098 5099the matcher objcMethodDecl(hasParameter(0, hasName("y"))) 5100matches the declaration of method f with hasParameter 5101matching y. 5102</pre></td></tr> 5103 5104 5105<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> 5106<tr><td colspan="4" class="doc" id="pointee0"><pre>Narrows PointerType (and similar) matchers to those where the 5107pointee matches a given matcher. 5108 5109Given 5110 int *a; 5111 int const *b; 5112 float const *f; 5113pointerType(pointee(isConstQualified(), isInteger())) 5114 matches "int const *b" 5115 5116Usable 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>>, 5117 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>> 5118</pre></td></tr> 5119 5120 5121<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> 5122<tr><td colspan="4" class="doc" id="forEachArgumentWithParam1"><pre>Matches all arguments and their respective ParmVarDecl. 5123 5124Given 5125 void f(int i); 5126 int y; 5127 f(y); 5128callExpr( 5129 forEachArgumentWithParam( 5130 declRefExpr(to(varDecl(hasName("y")))), 5131 parmVarDecl(hasType(isInteger())) 5132)) 5133 matches f(y); 5134with declRefExpr(...) 5135 matching int y 5136and parmVarDecl(...) 5137 matching int i 5138</pre></td></tr> 5139 5140 5141<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> 5142<tr><td colspan="4" class="doc" id="hasAnyArgument1"><pre>Matches any argument of a call expression or a constructor call 5143expression, or an ObjC-message-send expression. 5144 5145Given 5146 void x(int, int, int) { int y; x(1, y, 42); } 5147callExpr(hasAnyArgument(declRefExpr())) 5148 matches x(1, y, 42) 5149with hasAnyArgument(...) 5150 matching y 5151 5152For ObjectiveC, given 5153 @interface I - (void) f:(int) y; @end 5154 void foo(I *i) { [i f:12]; } 5155objcMessageExpr(hasAnyArgument(integerLiteral(equals(12)))) 5156 matches [i f:12] 5157</pre></td></tr> 5158 5159 5160<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> 5161<tr><td colspan="4" class="doc" id="hasArgument1"><pre>Matches the n'th argument of a call expression or a constructor 5162call expression. 5163 5164Example matches y in x(y) 5165 (matcher = callExpr(hasArgument(0, declRefExpr()))) 5166 void x(int) { int y; x(y); } 5167</pre></td></tr> 5168 5169 5170<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</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> 5171<tr><td colspan="4" class="doc" id="hasDeclaration13"><pre>Matches a node if the declaration associated with that node 5172matches the given matcher. 5173 5174The associated declaration is: 5175- for type nodes, the declaration of the underlying type 5176- for CallExpr, the declaration of the callee 5177- for MemberExpr, the declaration of the referenced member 5178- for CXXConstructExpr, the declaration of the constructor 5179- for CXXNewExpr, the declaration of the operator new 5180- for ObjCIvarExpr, the declaration of the ivar 5181 5182For type nodes, hasDeclaration will generally match the declaration of the 5183sugared type. Given 5184 class X {}; 5185 typedef X Y; 5186 Y y; 5187in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 5188typedefDecl. A common use case is to match the underlying, desugared type. 5189This can be achieved by using the hasUnqualifiedDesugaredType matcher: 5190 varDecl(hasType(hasUnqualifiedDesugaredType( 5191 recordType(hasDeclaration(decl()))))) 5192In this matcher, the decl will match the CXXRecordDecl of class X. 5193 5194Usable 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>>, 5195 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>>, 5196 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, 5197 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<<a href="https://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, 5198 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, 5199 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, 5200 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 5201</pre></td></tr> 5202 5203 5204<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> 5205<tr><td colspan="4" class="doc" id="forEachConstructorInitializer0"><pre>Matches each constructor initializer in a constructor definition. 5206 5207Given 5208 class A { A() : i(42), j(42) {} int i; int j; }; 5209cxxConstructorDecl(forEachConstructorInitializer( 5210 forField(decl().bind("x")) 5211)) 5212 will trigger two matches, binding for 'i' and 'j' respectively. 5213</pre></td></tr> 5214 5215 5216<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> 5217<tr><td colspan="4" class="doc" id="hasAnyConstructorInitializer0"><pre>Matches a constructor initializer. 5218 5219Given 5220 struct Foo { 5221 Foo() : foo_(1) { } 5222 int foo_; 5223 }; 5224cxxRecordDecl(has(cxxConstructorDecl( 5225 hasAnyConstructorInitializer(anything()) 5226))) 5227 record matches Foo, hasAnyConstructorInitializer matches foo_(1) 5228</pre></td></tr> 5229 5230 5231<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> 5232<tr><td colspan="4" class="doc" id="forField0"><pre>Matches the field declaration of a constructor initializer. 5233 5234Given 5235 struct Foo { 5236 Foo() : foo_(1) { } 5237 int foo_; 5238 }; 5239cxxRecordDecl(has(cxxConstructorDecl(hasAnyConstructorInitializer( 5240 forField(hasName("foo_")))))) 5241 matches Foo 5242with forField matching foo_ 5243</pre></td></tr> 5244 5245 5246<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> 5247<tr><td colspan="4" class="doc" id="withInitializer0"><pre>Matches the initializer expression of a constructor initializer. 5248 5249Given 5250 struct Foo { 5251 Foo() : foo_(1) { } 5252 int foo_; 5253 }; 5254cxxRecordDecl(has(cxxConstructorDecl(hasAnyConstructorInitializer( 5255 withInitializer(integerLiteral(equals(1))))))) 5256 matches Foo 5257with withInitializer matching (1) 5258</pre></td></tr> 5259 5260 5261<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> 5262<tr><td colspan="4" class="doc" id="hasObjectExpression2"><pre>Matches a member expression where the object expression is matched by a 5263given matcher. Implicit object expressions are included; that is, it matches 5264use of implicit `this`. 5265 5266Given 5267 struct X { 5268 int m; 5269 int f(X x) { x.m; return m; } 5270 }; 5271memberExpr(hasObjectExpression(hasType(cxxRecordDecl(hasName("X"))))) 5272 matches `x.m`, but not `m`; however, 5273memberExpr(hasObjectExpression(hasType(pointsTo( 5274 cxxRecordDecl(hasName("X")))))) 5275 matches `m` (aka. `this->m`), but not `x.m`. 5276</pre></td></tr> 5277 5278 5279<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> 5280<tr><td colspan="4" class="doc" id="hasBody3"><pre>Matches a 'for', 'while', 'do while' statement or a function 5281definition that has a given body. 5282 5283Given 5284 for (;;) {} 5285hasBody(compoundStmt()) 5286 matches 'for (;;) {}' 5287with compoundStmt() 5288 matching '{}' 5289</pre></td></tr> 5290 5291 5292<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> 5293<tr><td colspan="4" class="doc" id="hasInitStatement2"><pre>Matches selection statements with initializer. 5294 5295Given: 5296 void foo() { 5297 if (int i = foobar(); i > 0) {} 5298 switch (int i = foobar(); i) {} 5299 for (auto& a = get_range(); auto& x : a) {} 5300 } 5301 void bar() { 5302 if (foobar() > 0) {} 5303 switch (foobar()) {} 5304 for (auto& x : get_range()) {} 5305 } 5306ifStmt(hasInitStatement(anything())) 5307 matches the if statement in foo but not in bar. 5308switchStmt(hasInitStatement(anything())) 5309 matches the switch statement in foo but not in bar. 5310cxxForRangeStmt(hasInitStatement(anything())) 5311 matches the range for statement in foo but not in bar. 5312</pre></td></tr> 5313 5314 5315<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> 5316<tr><td colspan="4" class="doc" id="hasLoopVariable0"><pre>Matches the initialization statement of a for loop. 5317 5318Example: 5319 forStmt(hasLoopVariable(anything())) 5320matches 'int x' in 5321 for (int x : a) { } 5322</pre></td></tr> 5323 5324 5325<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> 5326<tr><td colspan="4" class="doc" id="hasRangeInit0"><pre>Matches the range initialization statement of a for loop. 5327 5328Example: 5329 forStmt(hasRangeInit(anything())) 5330matches 'a' in 5331 for (int x : a) { } 5332</pre></td></tr> 5333 5334 5335<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> 5336<tr><td colspan="4" class="doc" id="onImplicitObjectArgument0"><pre>Matches on the implicit object argument of a member call expression. Unlike 5337`on`, matches the argument directly without stripping away anything. 5338 5339Given 5340 class Y { public: void m(); }; 5341 Y g(); 5342 class X : public Y { void g(); }; 5343 void z(Y y, X x) { y.m(); x.m(); x.g(); (g()).m(); } 5344cxxMemberCallExpr(onImplicitObjectArgument(hasType( 5345 cxxRecordDecl(hasName("Y"))))) 5346 matches `y.m()`, `x.m()` and (g()).m(), but not `x.g()`. 5347cxxMemberCallExpr(on(callExpr())) 5348 does not match `(g()).m()`, because the parens are not ignored. 5349 5350FIXME: Overload to allow directly matching types? 5351</pre></td></tr> 5352 5353 5354<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> 5355<tr><td colspan="4" class="doc" id="on0"><pre>Matches on the implicit object argument of a member call expression, after 5356stripping off any parentheses or implicit casts. 5357 5358Given 5359 class Y { public: void m(); }; 5360 Y g(); 5361 class X : public Y {}; 5362 void z(Y y, X x) { y.m(); (g()).m(); x.m(); } 5363cxxMemberCallExpr(on(hasType(cxxRecordDecl(hasName("Y"))))) 5364 matches `y.m()` and `(g()).m()`. 5365cxxMemberCallExpr(on(hasType(cxxRecordDecl(hasName("X"))))) 5366 matches `x.m()`. 5367cxxMemberCallExpr(on(callExpr())) 5368 matches `(g()).m()`. 5369 5370FIXME: Overload to allow directly matching types? 5371</pre></td></tr> 5372 5373 5374<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> 5375<tr><td colspan="4" class="doc" id="thisPointerType1"><pre>Overloaded to match the type's declaration. 5376</pre></td></tr> 5377 5378 5379<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> 5380<tr><td colspan="4" class="doc" id="thisPointerType0"><pre>Matches if the type of the expression's implicit object argument either 5381matches the InnerMatcher, or is a pointer to a type that matches the 5382InnerMatcher. 5383 5384Given 5385 class Y { public: void m(); }; 5386 class X : public Y { void g(); }; 5387 void z() { Y y; y.m(); Y *p; p->m(); X x; x.m(); x.g(); } 5388cxxMemberCallExpr(thisPointerType(hasDeclaration( 5389 cxxRecordDecl(hasName("Y"))))) 5390 matches `y.m()`, `p->m()` and `x.m()`. 5391cxxMemberCallExpr(thisPointerType(hasDeclaration( 5392 cxxRecordDecl(hasName("X"))))) 5393 matches `x.g()`. 5394</pre></td></tr> 5395 5396 5397<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> 5398<tr><td colspan="4" class="doc" id="forEachOverridden0"><pre>Matches each method overridden by the given method. This matcher may 5399produce multiple matches. 5400 5401Given 5402 class A { virtual void f(); }; 5403 class B : public A { void f(); }; 5404 class C : public B { void f(); }; 5405cxxMethodDecl(ofClass(hasName("C")), 5406 forEachOverridden(cxxMethodDecl().bind("b"))).bind("d") 5407 matches once, with "b" binding "A::f" and "d" binding "C::f" (Note 5408 that B::f is not overridden by C::f). 5409 5410The check can produce multiple matches in case of multiple inheritance, e.g. 5411 class A1 { virtual void f(); }; 5412 class A2 { virtual void f(); }; 5413 class C : public A1, public A2 { void f(); }; 5414cxxMethodDecl(ofClass(hasName("C")), 5415 forEachOverridden(cxxMethodDecl().bind("b"))).bind("d") 5416 matches twice, once with "b" binding "A1::f" and "d" binding "C::f", and 5417 once with "b" binding "A2::f" and "d" binding "C::f". 5418</pre></td></tr> 5419 5420 5421<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> 5422<tr><td colspan="4" class="doc" id="ofClass0"><pre>Matches the class declaration that the given method declaration 5423belongs to. 5424 5425FIXME: Generalize this for other kinds of declarations. 5426FIXME: What other kind of declarations would we need to generalize 5427this to? 5428 5429Example matches A() in the last line 5430 (matcher = cxxConstructExpr(hasDeclaration(cxxMethodDecl( 5431 ofClass(hasName("A")))))) 5432 class A { 5433 public: 5434 A(); 5435 }; 5436 A a = A(); 5437</pre></td></tr> 5438 5439 5440<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> 5441<tr><td colspan="4" class="doc" id="hasAnyPlacementArg0"><pre>Matches any placement new expression arguments. 5442 5443Given: 5444 MyClass *p1 = new (Storage) MyClass(); 5445cxxNewExpr(hasAnyPlacementArg(anything())) 5446 matches the expression 'new (Storage, 16) MyClass()'. 5447</pre></td></tr> 5448 5449 5450<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> 5451<tr><td colspan="4" class="doc" id="hasArraySize0"><pre>Matches array new expressions with a given array size. 5452 5453Given: 5454 MyClass *p1 = new MyClass[10]; 5455cxxNewExpr(hasArraySize(integerLiteral(equals(10)))) 5456 matches the expression 'new MyClass[10]'. 5457</pre></td></tr> 5458 5459 5460<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</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> 5461<tr><td colspan="4" class="doc" id="hasDeclaration12"><pre>Matches a node if the declaration associated with that node 5462matches the given matcher. 5463 5464The associated declaration is: 5465- for type nodes, the declaration of the underlying type 5466- for CallExpr, the declaration of the callee 5467- for MemberExpr, the declaration of the referenced member 5468- for CXXConstructExpr, the declaration of the constructor 5469- for CXXNewExpr, the declaration of the operator new 5470- for ObjCIvarExpr, the declaration of the ivar 5471 5472For type nodes, hasDeclaration will generally match the declaration of the 5473sugared type. Given 5474 class X {}; 5475 typedef X Y; 5476 Y y; 5477in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 5478typedefDecl. A common use case is to match the underlying, desugared type. 5479This can be achieved by using the hasUnqualifiedDesugaredType matcher: 5480 varDecl(hasType(hasUnqualifiedDesugaredType( 5481 recordType(hasDeclaration(decl()))))) 5482In this matcher, the decl will match the CXXRecordDecl of class X. 5483 5484Usable 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>>, 5485 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>>, 5486 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, 5487 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<<a href="https://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, 5488 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, 5489 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, 5490 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 5491</pre></td></tr> 5492 5493 5494<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> 5495<tr><td colspan="4" class="doc" id="hasPlacementArg0"><pre>Matches placement new expression arguments. 5496 5497Given: 5498 MyClass *p1 = new (Storage, 16) MyClass(); 5499cxxNewExpr(hasPlacementArg(1, integerLiteral(equals(16)))) 5500 matches the expression 'new (Storage, 16) MyClass()'. 5501</pre></td></tr> 5502 5503 5504<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> 5505<tr><td colspan="4" class="doc" id="hasMethod0"><pre>Matches the first method of a class or struct that satisfies InnerMatcher. 5506 5507Given: 5508 class A { void func(); }; 5509 class B { void member(); }; 5510 5511cxxRecordDecl(hasMethod(hasName("func"))) matches the declaration of 5512A but not B. 5513</pre></td></tr> 5514 5515 5516<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> 5517<tr><td colspan="4" class="doc" id="isDerivedFrom0"><pre>Matches C++ classes that are directly or indirectly derived from a class 5518matching Base, or Objective-C classes that directly or indirectly 5519subclass a class matching Base. 5520 5521Note that a class is not considered to be derived from itself. 5522 5523Example matches Y, Z, C (Base == hasName("X")) 5524 class X; 5525 class Y : public X {}; // directly derived 5526 class Z : public Y {}; // indirectly derived 5527 typedef X A; 5528 typedef A B; 5529 class C : public B {}; // derived from a typedef of X 5530 5531In the following example, Bar matches isDerivedFrom(hasName("X")): 5532 class Foo; 5533 typedef Foo X; 5534 class Bar : public Foo {}; // derived from a type that X is a typedef of 5535 5536In the following example, Bar matches isDerivedFrom(hasName("NSObject")) 5537 @interface NSObject @end 5538 @interface Bar : NSObject @end 5539 5540Usable 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>> 5541</pre></td></tr> 5542 5543 5544<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> 5545<tr><td colspan="4" class="doc" id="isDirectlyDerivedFrom0"><pre>Matches C++ or Objective-C classes that are directly derived from a class 5546matching Base. 5547 5548Note that a class is not considered to be derived from itself. 5549 5550Example matches Y, C (Base == hasName("X")) 5551 class X; 5552 class Y : public X {}; // directly derived 5553 class Z : public Y {}; // indirectly derived 5554 typedef X A; 5555 typedef A B; 5556 class C : public B {}; // derived from a typedef of X 5557 5558In the following example, Bar matches isDerivedFrom(hasName("X")): 5559 class Foo; 5560 typedef Foo X; 5561 class Bar : public Foo {}; // derived from a type that X is a typedef of 5562</pre></td></tr> 5563 5564 5565<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> 5566<tr><td colspan="4" class="doc" id="isSameOrDerivedFrom0"><pre>Similar to isDerivedFrom(), but also matches classes that directly 5567match Base. 5568</pre></td></tr> 5569 5570 5571<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> 5572<tr><td colspan="4" class="doc" id="hasAnyArgument2"><pre>Matches any argument of a call expression or a constructor call 5573expression, or an ObjC-message-send expression. 5574 5575Given 5576 void x(int, int, int) { int y; x(1, y, 42); } 5577callExpr(hasAnyArgument(declRefExpr())) 5578 matches x(1, y, 42) 5579with hasAnyArgument(...) 5580 matching y 5581 5582For ObjectiveC, given 5583 @interface I - (void) f:(int) y; @end 5584 void foo(I *i) { [i f:12]; } 5585objcMessageExpr(hasAnyArgument(integerLiteral(equals(12)))) 5586 matches [i f:12] 5587</pre></td></tr> 5588 5589 5590<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</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_1Decl.html">Decl</a>> InnerMatcher</td></tr> 5591<tr><td colspan="4" class="doc" id="callee1"><pre>Matches if the call expression's callee's declaration matches the 5592given matcher. 5593 5594Example matches y.x() (matcher = callExpr(callee( 5595 cxxMethodDecl(hasName("x"))))) 5596 class Y { public: void x(); }; 5597 void z() { Y y; y.x(); } 5598</pre></td></tr> 5599 5600 5601<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> 5602<tr><td colspan="4" class="doc" id="callee0"><pre>Matches if the call expression's callee expression matches. 5603 5604Given 5605 class Y { void x() { this->x(); x(); Y y; y.x(); } }; 5606 void f() { f(); } 5607callExpr(callee(expr())) 5608 matches this->x(), x(), y.x(), f() 5609with callee(...) 5610 matching this->x, x, y.x, f respectively 5611 5612Note: Callee cannot take the more general internal::Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> 5613because this introduces ambiguous overloads with calls to Callee taking a 5614internal::Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, as the matcher hierarchy is purely 5615implemented in terms of implicit casts. 5616</pre></td></tr> 5617 5618 5619<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> 5620<tr><td colspan="4" class="doc" id="forEachArgumentWithParam0"><pre>Matches all arguments and their respective ParmVarDecl. 5621 5622Given 5623 void f(int i); 5624 int y; 5625 f(y); 5626callExpr( 5627 forEachArgumentWithParam( 5628 declRefExpr(to(varDecl(hasName("y")))), 5629 parmVarDecl(hasType(isInteger())) 5630)) 5631 matches f(y); 5632with declRefExpr(...) 5633 matching int y 5634and parmVarDecl(...) 5635 matching int i 5636</pre></td></tr> 5637 5638 5639<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> 5640<tr><td colspan="4" class="doc" id="hasAnyArgument0"><pre>Matches any argument of a call expression or a constructor call 5641expression, or an ObjC-message-send expression. 5642 5643Given 5644 void x(int, int, int) { int y; x(1, y, 42); } 5645callExpr(hasAnyArgument(declRefExpr())) 5646 matches x(1, y, 42) 5647with hasAnyArgument(...) 5648 matching y 5649 5650For ObjectiveC, given 5651 @interface I - (void) f:(int) y; @end 5652 void foo(I *i) { [i f:12]; } 5653objcMessageExpr(hasAnyArgument(integerLiteral(equals(12)))) 5654 matches [i f:12] 5655</pre></td></tr> 5656 5657 5658<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> 5659<tr><td colspan="4" class="doc" id="hasArgument0"><pre>Matches the n'th argument of a call expression or a constructor 5660call expression. 5661 5662Example matches y in x(y) 5663 (matcher = callExpr(hasArgument(0, declRefExpr()))) 5664 void x(int) { int y; x(y); } 5665</pre></td></tr> 5666 5667 5668<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</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> 5669<tr><td colspan="4" class="doc" id="hasDeclaration14"><pre>Matches a node if the declaration associated with that node 5670matches the given matcher. 5671 5672The associated declaration is: 5673- for type nodes, the declaration of the underlying type 5674- for CallExpr, the declaration of the callee 5675- for MemberExpr, the declaration of the referenced member 5676- for CXXConstructExpr, the declaration of the constructor 5677- for CXXNewExpr, the declaration of the operator new 5678- for ObjCIvarExpr, the declaration of the ivar 5679 5680For type nodes, hasDeclaration will generally match the declaration of the 5681sugared type. Given 5682 class X {}; 5683 typedef X Y; 5684 Y y; 5685in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 5686typedefDecl. A common use case is to match the underlying, desugared type. 5687This can be achieved by using the hasUnqualifiedDesugaredType matcher: 5688 varDecl(hasType(hasUnqualifiedDesugaredType( 5689 recordType(hasDeclaration(decl()))))) 5690In this matcher, the decl will match the CXXRecordDecl of class X. 5691 5692Usable 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>>, 5693 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>>, 5694 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, 5695 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<<a href="https://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, 5696 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, 5697 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, 5698 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 5699</pre></td></tr> 5700 5701 5702<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> 5703<tr><td colspan="4" class="doc" id="hasCaseConstant0"><pre>If the given case statement does not use the GNU case range 5704extension, matches the constant given in the statement. 5705 5706Given 5707 switch (1) { case 1: case 1+1: case 3 ... 4: ; } 5708caseStmt(hasCaseConstant(integerLiteral())) 5709 matches "case 1:" 5710</pre></td></tr> 5711 5712 5713<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> 5714<tr><td colspan="4" class="doc" id="hasSourceExpression0"><pre>Matches if the cast's source expression 5715or opaque value's source expression matches the given matcher. 5716 5717Example 1: matches "a string" 5718(matcher = castExpr(hasSourceExpression(cxxConstructExpr()))) 5719class URL { URL(string); }; 5720URL url = "a string"; 5721 5722Example 2: matches 'b' (matcher = 5723opaqueValueExpr(hasSourceExpression(implicitCastExpr(declRefExpr()))) 5724int a = b ?: 1; 5725</pre></td></tr> 5726 5727 5728<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> 5729<tr><td colspan="4" class="doc" id="hasAnyTemplateArgument0"><pre>Matches classTemplateSpecializations, templateSpecializationType and 5730functionDecl that have at least one TemplateArgument matching the given 5731InnerMatcher. 5732 5733Given 5734 template<typename T> class A {}; 5735 template<> class A<double> {}; 5736 A<int> a; 5737 5738 template<typename T> f() {}; 5739 void func() { f<int>(); }; 5740 5741classTemplateSpecializationDecl(hasAnyTemplateArgument( 5742 refersToType(asString("int")))) 5743 matches the specialization A<int> 5744 5745functionDecl(hasAnyTemplateArgument(refersToType(asString("int")))) 5746 matches the specialization f<int> 5747</pre></td></tr> 5748 5749 5750<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> 5751<tr><td colspan="4" class="doc" id="hasSpecializedTemplate0"><pre>Matches the specialized template of a specialization declaration. 5752 5753Given 5754 template<typename T> class A {}; #1 5755 template<> class A<int> {}; #2 5756classTemplateSpecializationDecl(hasSpecializedTemplate(classTemplateDecl())) 5757 matches '#2' with classTemplateDecl() matching the class template 5758 declaration of 'A' at #1. 5759</pre></td></tr> 5760 5761 5762<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> 5763<tr><td colspan="4" class="doc" id="hasTemplateArgument0"><pre>Matches classTemplateSpecializations, templateSpecializationType and 5764functionDecl where the n'th TemplateArgument matches the given InnerMatcher. 5765 5766Given 5767 template<typename T, typename U> class A {}; 5768 A<bool, int> b; 5769 A<int, bool> c; 5770 5771 template<typename T> void f() {} 5772 void func() { f<int>(); }; 5773classTemplateSpecializationDecl(hasTemplateArgument( 5774 1, refersToType(asString("int")))) 5775 matches the specialization A<bool, int> 5776 5777functionDecl(hasTemplateArgument(0, refersToType(asString("int")))) 5778 matches the specialization f<int> 5779</pre></td></tr> 5780 5781 5782<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> 5783<tr><td colspan="4" class="doc" id="hasElementType1"><pre>Matches arrays and C99 complex types that have a specific element 5784type. 5785 5786Given 5787 struct A {}; 5788 A a[7]; 5789 int b[7]; 5790arrayType(hasElementType(builtinType())) 5791 matches "int b[7]" 5792 5793Usable 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>> 5794</pre></td></tr> 5795 5796 5797<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> 5798<tr><td colspan="4" class="doc" id="hasAnySubstatement0"><pre>Matches compound statements where at least one substatement matches 5799a given matcher. Also matches StmtExprs that have CompoundStmt as children. 5800 5801Given 5802 { {}; 1+2; } 5803hasAnySubstatement(compoundStmt()) 5804 matches '{ {}; 1+2; }' 5805with compoundStmt() 5806 matching '{}' 5807</pre></td></tr> 5808 5809 5810<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> 5811<tr><td colspan="4" class="doc" id="hasDecayedType0"><pre>Matches the decayed type, whos decayed type matches InnerMatcher 5812</pre></td></tr> 5813 5814 5815<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>></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> 5816<tr><td colspan="4" class="doc" id="hasDeclaration11"><pre>Matches a node if the declaration associated with that node 5817matches the given matcher. 5818 5819The associated declaration is: 5820- for type nodes, the declaration of the underlying type 5821- for CallExpr, the declaration of the callee 5822- for MemberExpr, the declaration of the referenced member 5823- for CXXConstructExpr, the declaration of the constructor 5824- for CXXNewExpr, the declaration of the operator new 5825- for ObjCIvarExpr, the declaration of the ivar 5826 5827For type nodes, hasDeclaration will generally match the declaration of the 5828sugared type. Given 5829 class X {}; 5830 typedef X Y; 5831 Y y; 5832in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 5833typedefDecl. A common use case is to match the underlying, desugared type. 5834This can be achieved by using the hasUnqualifiedDesugaredType matcher: 5835 varDecl(hasType(hasUnqualifiedDesugaredType( 5836 recordType(hasDeclaration(decl()))))) 5837In this matcher, the decl will match the CXXRecordDecl of class X. 5838 5839Usable 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>>, 5840 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>>, 5841 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, 5842 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<<a href="https://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, 5843 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, 5844 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, 5845 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 5846</pre></td></tr> 5847 5848 5849<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>> InnerMatcher</td></tr> 5850<tr><td colspan="4" class="doc" id="throughUsingDecl0"><pre>Matches a DeclRefExpr that refers to a declaration through a 5851specific using shadow declaration. 5852 5853Given 5854 namespace a { void f() {} } 5855 using a::f; 5856 void g() { 5857 f(); // Matches this .. 5858 a::f(); // .. but not this. 5859 } 5860declRefExpr(throughUsingDecl(anything())) 5861 matches f() 5862</pre></td></tr> 5863 5864 5865<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> 5866<tr><td colspan="4" class="doc" id="to0"><pre>Matches a DeclRefExpr that refers to a declaration that matches the 5867specified matcher. 5868 5869Example matches x in if(x) 5870 (matcher = declRefExpr(to(varDecl(hasName("x"))))) 5871 bool x; 5872 if (x) {} 5873</pre></td></tr> 5874 5875 5876<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> 5877<tr><td colspan="4" class="doc" id="containsDeclaration0"><pre>Matches the n'th declaration of a declaration statement. 5878 5879Note that this does not work for global declarations because the AST 5880breaks up multiple-declaration DeclStmt's into multiple single-declaration 5881DeclStmt's. 5882Example: Given non-global declarations 5883 int a, b = 0; 5884 int c; 5885 int d = 2, e; 5886declStmt(containsDeclaration( 5887 0, varDecl(hasInitializer(anything())))) 5888 matches only 'int d = 2, e;', and 5889declStmt(containsDeclaration(1, varDecl())) 5890 matches 'int a, b = 0' as well as 'int d = 2, e;' 5891 but 'int c;' is not matched. 5892</pre></td></tr> 5893 5894 5895<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> 5896<tr><td colspan="4" class="doc" id="hasSingleDecl0"><pre>Matches the Decl of a DeclStmt which has a single declaration. 5897 5898Given 5899 int a, b; 5900 int c; 5901declStmt(hasSingleDecl(anything())) 5902 matches 'int c;' but not 'int a, b;'. 5903</pre></td></tr> 5904 5905 5906<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclaratorDecl.html">DeclaratorDecl</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> 5907<tr><td colspan="4" class="doc" id="hasTypeLoc0"><pre>Matches if the type location of the declarator decl's type matches 5908the inner matcher. 5909 5910Given 5911 int x; 5912declaratorDecl(hasTypeLoc(loc(asString("int")))) 5913 matches int x 5914</pre></td></tr> 5915 5916 5917<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> 5918<tr><td colspan="4" class="doc" id="hasDeclContext0"><pre>Matches declarations whose declaration context, interpreted as a 5919Decl, matches InnerMatcher. 5920 5921Given 5922 namespace N { 5923 namespace M { 5924 class D {}; 5925 } 5926 } 5927 5928cxxRcordDecl(hasDeclContext(namedDecl(hasName("M")))) matches the 5929declaration of class D. 5930</pre></td></tr> 5931 5932 5933<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DecltypeType.html">DecltypeType</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_1Type.html">Type</a>></td></tr> 5934<tr><td colspan="4" class="doc" id="hasUnderlyingType0"><pre>Matches DecltypeType nodes to find out the underlying type. 5935 5936Given 5937 decltype(1) a = 1; 5938 decltype(2.0) b = 2.0; 5939decltypeType(hasUnderlyingType(isInteger())) 5940 matches the type of "a" 5941 5942Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DecltypeType.html">DecltypeType</a>> 5943</pre></td></tr> 5944 5945 5946<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> 5947<tr><td colspan="4" class="doc" id="hasBody0"><pre>Matches a 'for', 'while', 'do while' statement or a function 5948definition that has a given body. 5949 5950Given 5951 for (;;) {} 5952hasBody(compoundStmt()) 5953 matches 'for (;;) {}' 5954with compoundStmt() 5955 matching '{}' 5956</pre></td></tr> 5957 5958 5959<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> 5960<tr><td colspan="4" class="doc" id="hasCondition3"><pre>Matches the condition expression of an if statement, for loop, 5961switch statement or conditional operator. 5962 5963Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true)))) 5964 if (true) {} 5965</pre></td></tr> 5966 5967 5968<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ElaboratedType.html">ElaboratedType</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> 5969<tr><td colspan="4" class="doc" id="hasQualifier0"><pre>Matches ElaboratedTypes whose qualifier, a NestedNameSpecifier, 5970matches InnerMatcher if the qualifier exists. 5971 5972Given 5973 namespace N { 5974 namespace M { 5975 class D {}; 5976 } 5977 } 5978 N::M::D d; 5979 5980elaboratedType(hasQualifier(hasPrefix(specifiesNamespace(hasName("N")))) 5981matches the type of the variable declaration of d. 5982</pre></td></tr> 5983 5984 5985<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ElaboratedType.html">ElaboratedType</a>></td><td class="name" onclick="toggle('namesType0')"><a name="namesType0Anchor">namesType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 5986<tr><td colspan="4" class="doc" id="namesType0"><pre>Matches ElaboratedTypes whose named type matches InnerMatcher. 5987 5988Given 5989 namespace N { 5990 namespace M { 5991 class D {}; 5992 } 5993 } 5994 N::M::D d; 5995 5996elaboratedType(namesType(recordType( 5997hasDeclaration(namedDecl(hasName("D")))))) matches the type of the variable 5998declaration of d. 5999</pre></td></tr> 6000 6001 6002<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>></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> 6003<tr><td colspan="4" class="doc" id="hasDeclaration10"><pre>Matches a node if the declaration associated with that node 6004matches the given matcher. 6005 6006The associated declaration is: 6007- for type nodes, the declaration of the underlying type 6008- for CallExpr, the declaration of the callee 6009- for MemberExpr, the declaration of the referenced member 6010- for CXXConstructExpr, the declaration of the constructor 6011- for CXXNewExpr, the declaration of the operator new 6012- for ObjCIvarExpr, the declaration of the ivar 6013 6014For type nodes, hasDeclaration will generally match the declaration of the 6015sugared type. Given 6016 class X {}; 6017 typedef X Y; 6018 Y y; 6019in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 6020typedefDecl. A common use case is to match the underlying, desugared type. 6021This can be achieved by using the hasUnqualifiedDesugaredType matcher: 6022 varDecl(hasType(hasUnqualifiedDesugaredType( 6023 recordType(hasDeclaration(decl()))))) 6024In this matcher, the decl will match the CXXRecordDecl of class X. 6025 6026Usable 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>>, 6027 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>>, 6028 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, 6029 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<<a href="https://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, 6030 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, 6031 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, 6032 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 6033</pre></td></tr> 6034 6035 6036<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> 6037<tr><td colspan="4" class="doc" id="hasDestinationType0"><pre>Matches casts whose destination type matches a given matcher. 6038 6039(Note: Clang's AST refers to other conversions as "casts" too, and calls 6040actual casts "explicit" casts.) 6041</pre></td></tr> 6042 6043 6044<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</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_1Decl.html">Decl</a>> InnerMatcher</td></tr> 6045<tr><td colspan="4" class="doc" id="hasType4"><pre>Overloaded to match the declaration of the expression's or value 6046declaration's type. 6047 6048In case of a value declaration (for example a variable declaration), 6049this resolves one layer of indirection. For example, in the value 6050declaration "X x;", cxxRecordDecl(hasName("X")) matches the declaration of 6051X, while varDecl(hasType(cxxRecordDecl(hasName("X")))) matches the 6052declaration of x. 6053 6054Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) 6055 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) 6056 and friend class X (matcher = friendDecl(hasType("X")) 6057 class X {}; 6058 void y(X &x) { x; X z; } 6059 class Y { friend class X; }; 6060 6061Usable 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_1ValueDecl.html">ValueDecl</a>> 6062</pre></td></tr> 6063 6064 6065<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> 6066<tr><td colspan="4" class="doc" id="hasType0"><pre>Matches if the expression's or declaration's type matches a type 6067matcher. 6068 6069Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) 6070 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) 6071 and U (matcher = typedefDecl(hasType(asString("int"))) 6072 and friend class X (matcher = friendDecl(hasType("X")) 6073 class X {}; 6074 void y(X &x) { x; X z; } 6075 typedef int U; 6076 class Y { friend class X; }; 6077</pre></td></tr> 6078 6079 6080<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>ast_matchers::Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 6081<tr><td colspan="4" class="doc" id="ignoringElidableConstructorCall0"><pre>Matches expressions that match InnerMatcher that are possibly wrapped in an 6082elidable constructor and other corresponding bookkeeping nodes. 6083 6084In C++17, elidable copy constructors are no longer being generated in the 6085AST as it is not permitted by the standard. They are, however, part of the 6086AST in C++14 and earlier. So, a matcher must abstract over these differences 6087to work in all language modes. This matcher skips elidable constructor-call 6088AST nodes, `ExprWithCleanups` nodes wrapping elidable constructor-calls and 6089various implicit nodes inside the constructor calls, all of which will not 6090appear in the C++17 AST. 6091 6092Given 6093 6094struct H {}; 6095H G(); 6096void f() { 6097 H D = G(); 6098} 6099 6100``varDecl(hasInitializer(ignoringElidableConstructorCall(callExpr())))`` 6101matches ``H D = G()`` in C++11 through C++17 (and beyond). 6102</pre></td></tr> 6103 6104 6105<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> 6106<tr><td colspan="4" class="doc" id="ignoringImpCasts0"><pre>Matches expressions that match InnerMatcher after any implicit casts 6107are stripped off. 6108 6109Parentheses and explicit casts are not discarded. 6110Given 6111 int arr[5]; 6112 int a = 0; 6113 char b = 0; 6114 const int c = a; 6115 int *d = arr; 6116 long e = (long) 0l; 6117The matchers 6118 varDecl(hasInitializer(ignoringImpCasts(integerLiteral()))) 6119 varDecl(hasInitializer(ignoringImpCasts(declRefExpr()))) 6120would match the declarations for a, b, c, and d, but not e. 6121While 6122 varDecl(hasInitializer(integerLiteral())) 6123 varDecl(hasInitializer(declRefExpr())) 6124only match the declarations for b, c, and d. 6125</pre></td></tr> 6126 6127 6128<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> 6129<tr><td colspan="4" class="doc" id="ignoringImplicit0"><pre>Matches expressions that match InnerMatcher after any implicit AST 6130nodes are stripped off. 6131 6132Parentheses and explicit casts are not discarded. 6133Given 6134 class C {}; 6135 C a = C(); 6136 C b; 6137 C c = b; 6138The matchers 6139 varDecl(hasInitializer(ignoringImplicit(cxxConstructExpr()))) 6140would match the declarations for a, b, and c. 6141While 6142 varDecl(hasInitializer(cxxConstructExpr())) 6143only match the declarations for b and c. 6144</pre></td></tr> 6145 6146 6147<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> 6148<tr><td colspan="4" class="doc" id="ignoringParenCasts0"><pre>Matches expressions that match InnerMatcher after parentheses and 6149casts are stripped off. 6150 6151Implicit and non-C Style casts are also discarded. 6152Given 6153 int a = 0; 6154 char b = (0); 6155 void* c = reinterpret_cast<char*>(0); 6156 char d = char(0); 6157The matcher 6158 varDecl(hasInitializer(ignoringParenCasts(integerLiteral()))) 6159would match the declarations for a, b, c, and d. 6160while 6161 varDecl(hasInitializer(integerLiteral())) 6162only match the declaration for a. 6163</pre></td></tr> 6164 6165 6166<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> 6167<tr><td colspan="4" class="doc" id="ignoringParenImpCasts0"><pre>Matches expressions that match InnerMatcher after implicit casts and 6168parentheses are stripped off. 6169 6170Explicit casts are not discarded. 6171Given 6172 int arr[5]; 6173 int a = 0; 6174 char b = (0); 6175 const int c = a; 6176 int *d = (arr); 6177 long e = ((long) 0l); 6178The matchers 6179 varDecl(hasInitializer(ignoringParenImpCasts(integerLiteral()))) 6180 varDecl(hasInitializer(ignoringParenImpCasts(declRefExpr()))) 6181would match the declarations for a, b, c, and d, but not e. 6182while 6183 varDecl(hasInitializer(integerLiteral())) 6184 varDecl(hasInitializer(declRefExpr())) 6185would only match the declaration for a. 6186</pre></td></tr> 6187 6188 6189<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> 6190<tr><td colspan="4" class="doc" id="ignoringParens1"><pre>Overload ignoringParens for Expr. 6191 6192Given 6193 const char* str = ("my-string"); 6194The matcher 6195 implicitCastExpr(hasSourceExpression(ignoringParens(stringLiteral()))) 6196would match the implicit cast resulting from the assignment. 6197</pre></td></tr> 6198 6199 6200<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> 6201<tr><td colspan="4" class="doc" id="hasInClassInitializer0"><pre>Matches non-static data members that have an in-class initializer. 6202 6203Given 6204 class C { 6205 int a = 2; 6206 int b = 3; 6207 int c; 6208 }; 6209fieldDecl(hasInClassInitializer(integerLiteral(equals(2)))) 6210 matches 'int a;' but not 'int b;'. 6211fieldDecl(hasInClassInitializer(anything())) 6212 matches 'int a;' and 'int b;' but not 'int c;'. 6213</pre></td></tr> 6214 6215 6216<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> 6217<tr><td colspan="4" class="doc" id="hasBody1"><pre>Matches a 'for', 'while', 'do while' statement or a function 6218definition that has a given body. 6219 6220Given 6221 for (;;) {} 6222hasBody(compoundStmt()) 6223 matches 'for (;;) {}' 6224with compoundStmt() 6225 matching '{}' 6226</pre></td></tr> 6227 6228 6229<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> 6230<tr><td colspan="4" class="doc" id="hasCondition1"><pre>Matches the condition expression of an if statement, for loop, 6231switch statement or conditional operator. 6232 6233Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true)))) 6234 if (true) {} 6235</pre></td></tr> 6236 6237 6238<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> 6239<tr><td colspan="4" class="doc" id="hasIncrement0"><pre>Matches the increment statement of a for loop. 6240 6241Example: 6242 forStmt(hasIncrement(unaryOperator(hasOperatorName("++")))) 6243matches '++x' in 6244 for (x; x < N; ++x) { } 6245</pre></td></tr> 6246 6247 6248<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> 6249<tr><td colspan="4" class="doc" id="hasLoopInit0"><pre>Matches the initialization statement of a for loop. 6250 6251Example: 6252 forStmt(hasLoopInit(declStmt())) 6253matches 'int x = 0' in 6254 for (int x = 0; x < N; ++x) { } 6255</pre></td></tr> 6256 6257 6258<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FriendDecl.html">FriendDecl</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> 6259<tr><td colspan="4" class="doc" id="hasType5"><pre>Overloaded to match the declaration of the expression's or value 6260declaration's type. 6261 6262In case of a value declaration (for example a variable declaration), 6263this resolves one layer of indirection. For example, in the value 6264declaration "X x;", cxxRecordDecl(hasName("X")) matches the declaration of 6265X, while varDecl(hasType(cxxRecordDecl(hasName("X")))) matches the 6266declaration of x. 6267 6268Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) 6269 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) 6270 and friend class X (matcher = friendDecl(hasType("X")) 6271 class X {}; 6272 void y(X &x) { x; X z; } 6273 class Y { friend class X; }; 6274 6275Usable 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_1ValueDecl.html">ValueDecl</a>> 6276</pre></td></tr> 6277 6278 6279<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> 6280<tr><td colspan="4" class="doc" id="hasType1"><pre>Matches if the expression's or declaration's type matches a type 6281matcher. 6282 6283Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) 6284 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) 6285 and U (matcher = typedefDecl(hasType(asString("int"))) 6286 and friend class X (matcher = friendDecl(hasType("X")) 6287 class X {}; 6288 void y(X &x) { x; X z; } 6289 typedef int U; 6290 class Y { friend class X; }; 6291</pre></td></tr> 6292 6293 6294<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> 6295<tr><td colspan="4" class="doc" id="hasAnyParameter0"><pre>Matches any parameter of a function or an ObjC method declaration or a 6296block. 6297 6298Does not match the 'this' parameter of a method. 6299 6300Given 6301 class X { void f(int x, int y, int z) {} }; 6302cxxMethodDecl(hasAnyParameter(hasName("y"))) 6303 matches f(int x, int y, int z) {} 6304with hasAnyParameter(...) 6305 matching int y 6306 6307For ObjectiveC, given 6308 @interface I - (void) f:(int) y; @end 6309 6310the matcher objcMethodDecl(hasAnyParameter(hasName("y"))) 6311matches the declaration of method f with hasParameter 6312matching y. 6313 6314For blocks, given 6315 b = ^(int y) { printf("%d", y) }; 6316 6317the matcher blockDecl(hasAnyParameter(hasName("y"))) 6318matches the declaration of the block b with hasParameter 6319matching y. 6320</pre></td></tr> 6321 6322 6323<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> 6324<tr><td colspan="4" class="doc" id="hasAnyTemplateArgument2"><pre>Matches classTemplateSpecializations, templateSpecializationType and 6325functionDecl that have at least one TemplateArgument matching the given 6326InnerMatcher. 6327 6328Given 6329 template<typename T> class A {}; 6330 template<> class A<double> {}; 6331 A<int> a; 6332 6333 template<typename T> f() {}; 6334 void func() { f<int>(); }; 6335 6336classTemplateSpecializationDecl(hasAnyTemplateArgument( 6337 refersToType(asString("int")))) 6338 matches the specialization A<int> 6339 6340functionDecl(hasAnyTemplateArgument(refersToType(asString("int")))) 6341 matches the specialization f<int> 6342</pre></td></tr> 6343 6344 6345<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> 6346<tr><td colspan="4" class="doc" id="hasBody4"><pre>Matches a 'for', 'while', 'do while' statement or a function 6347definition that has a given body. 6348 6349Given 6350 for (;;) {} 6351hasBody(compoundStmt()) 6352 matches 'for (;;) {}' 6353with compoundStmt() 6354 matching '{}' 6355</pre></td></tr> 6356 6357 6358<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> 6359<tr><td colspan="4" class="doc" id="hasExplicitSpecifier0"><pre>Matches the expression in an explicit specifier if present in the given 6360declaration. 6361 6362Given 6363 template<bool b> 6364 struct S { 6365 S(int); // #1 6366 explicit S(double); // #2 6367 operator int(); // #3 6368 explicit operator bool(); // #4 6369 explicit(false) S(bool) // # 7 6370 explicit(true) S(char) // # 8 6371 explicit(b) S(S) // # 9 6372 }; 6373 S(int) -> S<true> // #5 6374 explicit S(double) -> S<false> // #6 6375cxxConstructorDecl(hasExplicitSpecifier(constantExpr())) will match #7, #8 and #9, but not #1 or #2. 6376cxxConversionDecl(hasExplicitSpecifier(constantExpr())) will not match #3 or #4. 6377cxxDeductionGuideDecl(hasExplicitSpecifier(constantExpr())) will not match #5 or #6. 6378</pre></td></tr> 6379 6380 6381<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> 6382<tr><td colspan="4" class="doc" id="hasParameter0"><pre>Matches the n'th parameter of a function or an ObjC method 6383declaration or a block. 6384 6385Given 6386 class X { void f(int x) {} }; 6387cxxMethodDecl(hasParameter(0, hasType(varDecl()))) 6388 matches f(int x) {} 6389with hasParameter(...) 6390 matching int x 6391 6392For ObjectiveC, given 6393 @interface I - (void) f:(int) y; @end 6394 6395the matcher objcMethodDecl(hasParameter(0, hasName("y"))) 6396matches the declaration of method f with hasParameter 6397matching y. 6398</pre></td></tr> 6399 6400 6401<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> 6402<tr><td colspan="4" class="doc" id="hasTemplateArgument2"><pre>Matches classTemplateSpecializations, templateSpecializationType and 6403functionDecl where the n'th TemplateArgument matches the given InnerMatcher. 6404 6405Given 6406 template<typename T, typename U> class A {}; 6407 A<bool, int> b; 6408 A<int, bool> c; 6409 6410 template<typename T> void f() {} 6411 void func() { f<int>(); }; 6412classTemplateSpecializationDecl(hasTemplateArgument( 6413 1, refersToType(asString("int")))) 6414 matches the specialization A<bool, int> 6415 6416functionDecl(hasTemplateArgument(0, refersToType(asString("int")))) 6417 matches the specialization f<int> 6418</pre></td></tr> 6419 6420 6421<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> 6422<tr><td colspan="4" class="doc" id="returns0"><pre>Matches the return type of a function declaration. 6423 6424Given: 6425 class X { int f() { return 1; } }; 6426cxxMethodDecl(returns(asString("int"))) 6427 matches int f() { return 1; } 6428</pre></td></tr> 6429 6430 6431<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> 6432<tr><td colspan="4" class="doc" id="hasCondition0"><pre>Matches the condition expression of an if statement, for loop, 6433switch statement or conditional operator. 6434 6435Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true)))) 6436 if (true) {} 6437</pre></td></tr> 6438 6439 6440<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> 6441<tr><td colspan="4" class="doc" id="hasConditionVariableStatement0"><pre>Matches the condition variable statement in an if statement. 6442 6443Given 6444 if (A* a = GetAPointer()) {} 6445hasConditionVariableStatement(...) 6446 matches 'A* a = GetAPointer()'. 6447</pre></td></tr> 6448 6449 6450<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> 6451<tr><td colspan="4" class="doc" id="hasElse0"><pre>Matches the else-statement of an if statement. 6452 6453Examples matches the if statement 6454 (matcher = ifStmt(hasElse(cxxBoolLiteral(equals(true))))) 6455 if (false) false; else true; 6456</pre></td></tr> 6457 6458 6459<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> 6460<tr><td colspan="4" class="doc" id="hasInitStatement0"><pre>Matches selection statements with initializer. 6461 6462Given: 6463 void foo() { 6464 if (int i = foobar(); i > 0) {} 6465 switch (int i = foobar(); i) {} 6466 for (auto& a = get_range(); auto& x : a) {} 6467 } 6468 void bar() { 6469 if (foobar() > 0) {} 6470 switch (foobar()) {} 6471 for (auto& x : get_range()) {} 6472 } 6473ifStmt(hasInitStatement(anything())) 6474 matches the if statement in foo but not in bar. 6475switchStmt(hasInitStatement(anything())) 6476 matches the switch statement in foo but not in bar. 6477cxxForRangeStmt(hasInitStatement(anything())) 6478 matches the range for statement in foo but not in bar. 6479</pre></td></tr> 6480 6481 6482<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> 6483<tr><td colspan="4" class="doc" id="hasThen0"><pre>Matches the then-statement of an if statement. 6484 6485Examples matches the if statement 6486 (matcher = ifStmt(hasThen(cxxBoolLiteral(equals(true))))) 6487 if (false) true; else false; 6488</pre></td></tr> 6489 6490 6491<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> 6492<tr><td colspan="4" class="doc" id="hasImplicitDestinationType0"><pre>Matches implicit casts whose destination type matches a given 6493matcher. 6494 6495FIXME: Unit test this matcher 6496</pre></td></tr> 6497 6498 6499<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, ast_matchers::Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 6500<tr><td colspan="4" class="doc" id="hasInit0"><pre>Matches the n'th item of an initializer list expression. 6501 6502Example matches y. 6503 (matcher = initListExpr(hasInit(0, expr()))) 6504 int x{y}. 6505</pre></td></tr> 6506 6507 6508<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> 6509<tr><td colspan="4" class="doc" id="hasSyntacticForm0"><pre>Matches the syntactic form of init list expressions 6510(if expression have it). 6511</pre></td></tr> 6512 6513 6514<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</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> 6515<tr><td colspan="4" class="doc" id="hasDeclaration9"><pre>Matches a node if the declaration associated with that node 6516matches the given matcher. 6517 6518The associated declaration is: 6519- for type nodes, the declaration of the underlying type 6520- for CallExpr, the declaration of the callee 6521- for MemberExpr, the declaration of the referenced member 6522- for CXXConstructExpr, the declaration of the constructor 6523- for CXXNewExpr, the declaration of the operator new 6524- for ObjCIvarExpr, the declaration of the ivar 6525 6526For type nodes, hasDeclaration will generally match the declaration of the 6527sugared type. Given 6528 class X {}; 6529 typedef X Y; 6530 Y y; 6531in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 6532typedefDecl. A common use case is to match the underlying, desugared type. 6533This can be achieved by using the hasUnqualifiedDesugaredType matcher: 6534 varDecl(hasType(hasUnqualifiedDesugaredType( 6535 recordType(hasDeclaration(decl()))))) 6536In this matcher, the decl will match the CXXRecordDecl of class X. 6537 6538Usable 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>>, 6539 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>>, 6540 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, 6541 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<<a href="https://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, 6542 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, 6543 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, 6544 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 6545</pre></td></tr> 6546 6547 6548<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</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> 6549<tr><td colspan="4" class="doc" id="hasDeclaration8"><pre>Matches a node if the declaration associated with that node 6550matches the given matcher. 6551 6552The associated declaration is: 6553- for type nodes, the declaration of the underlying type 6554- for CallExpr, the declaration of the callee 6555- for MemberExpr, the declaration of the referenced member 6556- for CXXConstructExpr, the declaration of the constructor 6557- for CXXNewExpr, the declaration of the operator new 6558- for ObjCIvarExpr, the declaration of the ivar 6559 6560For type nodes, hasDeclaration will generally match the declaration of the 6561sugared type. Given 6562 class X {}; 6563 typedef X Y; 6564 Y y; 6565in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 6566typedefDecl. A common use case is to match the underlying, desugared type. 6567This can be achieved by using the hasUnqualifiedDesugaredType matcher: 6568 varDecl(hasType(hasUnqualifiedDesugaredType( 6569 recordType(hasDeclaration(decl()))))) 6570In this matcher, the decl will match the CXXRecordDecl of class X. 6571 6572Usable 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>>, 6573 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>>, 6574 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, 6575 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<<a href="https://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, 6576 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, 6577 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, 6578 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 6579</pre></td></tr> 6580 6581 6582<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LambdaExpr.html">LambdaExpr</a>></td><td class="name" onclick="toggle('hasAnyCapture1')"><a name="hasAnyCapture1Anchor">hasAnyCapture</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXThisExpr.html">CXXThisExpr</a>> InnerMatcher</td></tr> 6583<tr><td colspan="4" class="doc" id="hasAnyCapture1"><pre>Matches any capture of 'this' in a lambda expression. 6584 6585Given 6586 struct foo { 6587 void bar() { 6588 auto f = [this](){}; 6589 } 6590 } 6591lambdaExpr(hasAnyCapture(cxxThisExpr())) 6592 matches [this](){}; 6593</pre></td></tr> 6594 6595 6596<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_1VarDecl.html">VarDecl</a>> InnerMatcher</td></tr> 6597<tr><td colspan="4" class="doc" id="hasAnyCapture0"><pre>Matches any capture of a lambda expression. 6598 6599Given 6600 void foo() { 6601 int x; 6602 auto f = [x](){}; 6603 } 6604lambdaExpr(hasAnyCapture(anything())) 6605 matches [x](){}; 6606</pre></td></tr> 6607 6608 6609<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</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> 6610<tr><td colspan="4" class="doc" id="hasDeclaration7"><pre>Matches a node if the declaration associated with that node 6611matches the given matcher. 6612 6613The associated declaration is: 6614- for type nodes, the declaration of the underlying type 6615- for CallExpr, the declaration of the callee 6616- for MemberExpr, the declaration of the referenced member 6617- for CXXConstructExpr, the declaration of the constructor 6618- for CXXNewExpr, the declaration of the operator new 6619- for ObjCIvarExpr, the declaration of the ivar 6620 6621For type nodes, hasDeclaration will generally match the declaration of the 6622sugared type. Given 6623 class X {}; 6624 typedef X Y; 6625 Y y; 6626in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 6627typedefDecl. A common use case is to match the underlying, desugared type. 6628This can be achieved by using the hasUnqualifiedDesugaredType matcher: 6629 varDecl(hasType(hasUnqualifiedDesugaredType( 6630 recordType(hasDeclaration(decl()))))) 6631In this matcher, the decl will match the CXXRecordDecl of class X. 6632 6633Usable 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>>, 6634 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>>, 6635 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, 6636 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<<a href="https://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, 6637 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, 6638 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, 6639 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 6640</pre></td></tr> 6641 6642 6643<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> 6644<tr><td colspan="4" class="doc" id="hasObjectExpression0"><pre>Matches a member expression where the object expression is matched by a 6645given matcher. Implicit object expressions are included; that is, it matches 6646use of implicit `this`. 6647 6648Given 6649 struct X { 6650 int m; 6651 int f(X x) { x.m; return m; } 6652 }; 6653memberExpr(hasObjectExpression(hasType(cxxRecordDecl(hasName("X"))))) 6654 matches `x.m`, but not `m`; however, 6655memberExpr(hasObjectExpression(hasType(pointsTo( 6656 cxxRecordDecl(hasName("X")))))) 6657 matches `m` (aka. `this->m`), but not `x.m`. 6658</pre></td></tr> 6659 6660 6661<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> 6662<tr><td colspan="4" class="doc" id="member0"><pre>Matches a member expression where the member is matched by a 6663given matcher. 6664 6665Given 6666 struct { int first, second; } first, second; 6667 int i(second.first); 6668 int j(first.second); 6669memberExpr(member(hasName("first"))) 6670 matches second.first 6671 but not first.second (because the member name there is "second"). 6672</pre></td></tr> 6673 6674 6675<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> 6676<tr><td colspan="4" class="doc" id="pointee1"><pre>Narrows PointerType (and similar) matchers to those where the 6677pointee matches a given matcher. 6678 6679Given 6680 int *a; 6681 int const *b; 6682 float const *f; 6683pointerType(pointee(isConstQualified(), isInteger())) 6684 matches "int const *b" 6685 6686Usable 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>>, 6687 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>> 6688</pre></td></tr> 6689 6690 6691<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> 6692<tr><td colspan="4" class="doc" id="hasUnderlyingDecl0"><pre>Matches a NamedDecl whose underlying declaration matches the given 6693matcher. 6694 6695Given 6696 namespace N { template<class T> void f(T t); } 6697 template <class T> void g() { using N::f; f(T()); } 6698unresolvedLookupExpr(hasAnyDeclaration( 6699 namedDecl(hasUnderlyingDecl(hasName("::N::f"))))) 6700 matches the use of f in g() . 6701</pre></td></tr> 6702 6703 6704<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> 6705<tr><td colspan="4" class="doc" id="hasPrefix1"><pre>Matches on the prefix of a NestedNameSpecifierLoc. 6706 6707Given 6708 struct A { struct B { struct C {}; }; }; 6709 A::B::C c; 6710nestedNameSpecifierLoc(hasPrefix(loc(specifiesType(asString("struct A"))))) 6711 matches "A::" 6712</pre></td></tr> 6713 6714 6715<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> 6716<tr><td colspan="4" class="doc" id="loc1"><pre>Matches NestedNameSpecifierLocs for which the given inner 6717NestedNameSpecifier-matcher matches. 6718</pre></td></tr> 6719 6720 6721<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> 6722<tr><td colspan="4" class="doc" id="specifiesTypeLoc0"><pre>Matches nested name specifier locs that specify a type matching the 6723given TypeLoc. 6724 6725Given 6726 struct A { struct B { struct C {}; }; }; 6727 A::B::C c; 6728nestedNameSpecifierLoc(specifiesTypeLoc(loc(type( 6729 hasDeclaration(cxxRecordDecl(hasName("A"))))))) 6730 matches "A::" 6731</pre></td></tr> 6732 6733 6734<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> 6735<tr><td colspan="4" class="doc" id="hasPrefix0"><pre>Matches on the prefix of a NestedNameSpecifier. 6736 6737Given 6738 struct A { struct B { struct C {}; }; }; 6739 A::B::C c; 6740nestedNameSpecifier(hasPrefix(specifiesType(asString("struct A")))) and 6741 matches "A::" 6742</pre></td></tr> 6743 6744 6745<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> 6746<tr><td colspan="4" class="doc" id="specifiesNamespace0"><pre>Matches nested name specifiers that specify a namespace matching the 6747given namespace matcher. 6748 6749Given 6750 namespace ns { struct A {}; } 6751 ns::A a; 6752nestedNameSpecifier(specifiesNamespace(hasName("ns"))) 6753 matches "ns::" 6754</pre></td></tr> 6755 6756 6757<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> 6758<tr><td colspan="4" class="doc" id="specifiesType0"><pre>Matches nested name specifiers that specify a type matching the 6759given QualType matcher without qualifiers. 6760 6761Given 6762 struct A { struct B { struct C {}; }; }; 6763 A::B::C c; 6764nestedNameSpecifier(specifiesType( 6765 hasDeclaration(cxxRecordDecl(hasName("A"))) 6766)) 6767 matches "A::" 6768</pre></td></tr> 6769 6770 6771<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPExecutableDirective.html">OMPExecutableDirective</a>></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> 6772<tr><td colspan="4" class="doc" id="hasAnyClause0"><pre>Matches any clause in an OpenMP directive. 6773 6774Given 6775 6776 #pragma omp parallel 6777 #pragma omp parallel default(none) 6778 6779``ompExecutableDirective(hasAnyClause(anything()))`` matches 6780``omp parallel default(none)``. 6781</pre></td></tr> 6782 6783 6784<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPExecutableDirective.html">OMPExecutableDirective</a>></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> 6785<tr><td colspan="4" class="doc" id="hasStructuredBlock0"><pre>Matches the structured-block of the OpenMP executable directive 6786 6787Prerequisite: the executable directive must not be standalone directive. 6788If it is, it will never match. 6789 6790Given 6791 6792 #pragma omp parallel 6793 ; 6794 #pragma omp parallel 6795 {} 6796 6797``ompExecutableDirective(hasStructuredBlock(nullStmt()))`` will match ``;`` 6798</pre></td></tr> 6799 6800 6801<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> 6802<tr><td colspan="4" class="doc" id="isDerivedFrom1"><pre>Matches C++ classes that are directly or indirectly derived from a class 6803matching Base, or Objective-C classes that directly or indirectly 6804subclass a class matching Base. 6805 6806Note that a class is not considered to be derived from itself. 6807 6808Example matches Y, Z, C (Base == hasName("X")) 6809 class X; 6810 class Y : public X {}; // directly derived 6811 class Z : public Y {}; // indirectly derived 6812 typedef X A; 6813 typedef A B; 6814 class C : public B {}; // derived from a typedef of X 6815 6816In the following example, Bar matches isDerivedFrom(hasName("X")): 6817 class Foo; 6818 typedef Foo X; 6819 class Bar : public Foo {}; // derived from a type that X is a typedef of 6820 6821In the following example, Bar matches isDerivedFrom(hasName("NSObject")) 6822 @interface NSObject @end 6823 @interface Bar : NSObject @end 6824 6825Usable 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>> 6826</pre></td></tr> 6827 6828 6829<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> 6830<tr><td colspan="4" class="doc" id="isDirectlyDerivedFrom1"><pre>Matches C++ or Objective-C classes that are directly derived from a class 6831matching Base. 6832 6833Note that a class is not considered to be derived from itself. 6834 6835Example matches Y, C (Base == hasName("X")) 6836 class X; 6837 class Y : public X {}; // directly derived 6838 class Z : public Y {}; // indirectly derived 6839 typedef X A; 6840 typedef A B; 6841 class C : public B {}; // derived from a typedef of X 6842 6843In the following example, Bar matches isDerivedFrom(hasName("X")): 6844 class Foo; 6845 typedef Foo X; 6846 class Bar : public Foo {}; // derived from a type that X is a typedef of 6847</pre></td></tr> 6848 6849 6850<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> 6851<tr><td colspan="4" class="doc" id="isSameOrDerivedFrom1"><pre>Similar to isDerivedFrom(), but also matches classes that directly 6852match Base. 6853</pre></td></tr> 6854 6855 6856<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> 6857<tr><td colspan="4" class="doc" id="hasAnyArgument3"><pre>Matches any argument of a call expression or a constructor call 6858expression, or an ObjC-message-send expression. 6859 6860Given 6861 void x(int, int, int) { int y; x(1, y, 42); } 6862callExpr(hasAnyArgument(declRefExpr())) 6863 matches x(1, y, 42) 6864with hasAnyArgument(...) 6865 matching y 6866 6867For ObjectiveC, given 6868 @interface I - (void) f:(int) y; @end 6869 void foo(I *i) { [i f:12]; } 6870objcMessageExpr(hasAnyArgument(integerLiteral(equals(12)))) 6871 matches [i f:12] 6872</pre></td></tr> 6873 6874 6875<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</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> 6876<tr><td colspan="4" class="doc" id="hasArgument2"><pre>Matches the n'th argument of a call expression or a constructor 6877call expression. 6878 6879Example matches y in x(y) 6880 (matcher = callExpr(hasArgument(0, declRefExpr()))) 6881 void x(int) { int y; x(y); } 6882</pre></td></tr> 6883 6884 6885<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> 6886<tr><td colspan="4" class="doc" id="hasReceiver0"><pre>Matches if the Objective-C message is sent to an instance, 6887and the inner matcher matches on that instance. 6888 6889For example the method call in 6890 NSString *x = @"hello"; 6891 [x containsString:@"h"]; 6892is matched by 6893objcMessageExpr(hasReceiver(declRefExpr(to(varDecl(hasName("x")))))) 6894</pre></td></tr> 6895 6896 6897<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> 6898<tr><td colspan="4" class="doc" id="hasReceiverType0"><pre>Matches on the receiver of an ObjectiveC Message expression. 6899 6900Example 6901matcher = objCMessageExpr(hasReceiverType(asString("UIWebView *"))); 6902matches the [webView ...] message invocation. 6903 NSString *webViewJavaScript = ... 6904 UIWebView *webView = ... 6905 [webView stringByEvaluatingJavaScriptFromString:webViewJavascript]; 6906</pre></td></tr> 6907 6908 6909<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> 6910<tr><td colspan="4" class="doc" id="hasAnyParameter1"><pre>Matches any parameter of a function or an ObjC method declaration or a 6911block. 6912 6913Does not match the 'this' parameter of a method. 6914 6915Given 6916 class X { void f(int x, int y, int z) {} }; 6917cxxMethodDecl(hasAnyParameter(hasName("y"))) 6918 matches f(int x, int y, int z) {} 6919with hasAnyParameter(...) 6920 matching int y 6921 6922For ObjectiveC, given 6923 @interface I - (void) f:(int) y; @end 6924 6925the matcher objcMethodDecl(hasAnyParameter(hasName("y"))) 6926matches the declaration of method f with hasParameter 6927matching y. 6928 6929For blocks, given 6930 b = ^(int y) { printf("%d", y) }; 6931 6932the matcher blockDecl(hasAnyParameter(hasName("y"))) 6933matches the declaration of the block b with hasParameter 6934matching y. 6935</pre></td></tr> 6936 6937 6938<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> 6939<tr><td colspan="4" class="doc" id="hasParameter1"><pre>Matches the n'th parameter of a function or an ObjC method 6940declaration or a block. 6941 6942Given 6943 class X { void f(int x) {} }; 6944cxxMethodDecl(hasParameter(0, hasType(varDecl()))) 6945 matches f(int x) {} 6946with hasParameter(...) 6947 matching int x 6948 6949For ObjectiveC, given 6950 @interface I - (void) f:(int) y; @end 6951 6952the matcher objcMethodDecl(hasParameter(0, hasName("y"))) 6953matches the declaration of method f with hasParameter 6954matching y. 6955</pre></td></tr> 6956 6957 6958<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> 6959<tr><td colspan="4" class="doc" id="hasSourceExpression1"><pre>Matches if the cast's source expression 6960or opaque value's source expression matches the given matcher. 6961 6962Example 1: matches "a string" 6963(matcher = castExpr(hasSourceExpression(cxxConstructExpr()))) 6964class URL { URL(string); }; 6965URL url = "a string"; 6966 6967Example 2: matches 'b' (matcher = 6968opaqueValueExpr(hasSourceExpression(implicitCastExpr(declRefExpr()))) 6969int a = b ?: 1; 6970</pre></td></tr> 6971 6972 6973<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> 6974<tr><td colspan="4" class="doc" id="hasAnyDeclaration0"><pre>Matches an OverloadExpr if any of the declarations in the set of 6975overloads matches the given matcher. 6976 6977Given 6978 template <typename T> void foo(T); 6979 template <typename T> void bar(T); 6980 template <typename T> void baz(T t) { 6981 foo(t); 6982 bar(t); 6983 } 6984unresolvedLookupExpr(hasAnyDeclaration( 6985 functionTemplateDecl(hasName("foo")))) 6986 matches foo in foo(t); but not bar in bar(t); 6987</pre></td></tr> 6988 6989 6990<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> 6991<tr><td colspan="4" class="doc" id="innerType0"><pre>Matches ParenType nodes where the inner type is a specific type. 6992 6993Given 6994 int (*ptr_to_array)[4]; 6995 int (*ptr_to_func)(int); 6996 6997varDecl(hasType(pointsTo(parenType(innerType(functionType()))))) matches 6998ptr_to_func but not ptr_to_array. 6999 7000Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ParenType.html">ParenType</a>> 7001</pre></td></tr> 7002 7003 7004<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> 7005<tr><td colspan="4" class="doc" id="pointee2"><pre>Narrows PointerType (and similar) matchers to those where the 7006pointee matches a given matcher. 7007 7008Given 7009 int *a; 7010 int const *b; 7011 float const *f; 7012pointerType(pointee(isConstQualified(), isInteger())) 7013 matches "int const *b" 7014 7015Usable 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>>, 7016 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>> 7017</pre></td></tr> 7018 7019 7020<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> 7021<tr><td colspan="4" class="doc" id="hasCanonicalType0"><pre>Matches QualTypes whose canonical type matches InnerMatcher. 7022 7023Given: 7024 typedef int &int_ref; 7025 int a; 7026 int_ref b = a; 7027 7028varDecl(hasType(qualType(referenceType()))))) will not match the 7029declaration of b but varDecl(hasType(qualType(hasCanonicalType(referenceType())))))) does. 7030</pre></td></tr> 7031 7032 7033<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></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> 7034<tr><td colspan="4" class="doc" id="hasDeclaration6"><pre>Matches a node if the declaration associated with that node 7035matches the given matcher. 7036 7037The associated declaration is: 7038- for type nodes, the declaration of the underlying type 7039- for CallExpr, the declaration of the callee 7040- for MemberExpr, the declaration of the referenced member 7041- for CXXConstructExpr, the declaration of the constructor 7042- for CXXNewExpr, the declaration of the operator new 7043- for ObjCIvarExpr, the declaration of the ivar 7044 7045For type nodes, hasDeclaration will generally match the declaration of the 7046sugared type. Given 7047 class X {}; 7048 typedef X Y; 7049 Y y; 7050in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 7051typedefDecl. A common use case is to match the underlying, desugared type. 7052This can be achieved by using the hasUnqualifiedDesugaredType matcher: 7053 varDecl(hasType(hasUnqualifiedDesugaredType( 7054 recordType(hasDeclaration(decl()))))) 7055In this matcher, the decl will match the CXXRecordDecl of class X. 7056 7057Usable 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>>, 7058 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>>, 7059 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, 7060 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<<a href="https://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, 7061 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, 7062 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, 7063 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 7064</pre></td></tr> 7065 7066 7067<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> 7068<tr><td colspan="4" class="doc" id="ignoringParens0"><pre>Matches types that match InnerMatcher after any parens are stripped. 7069 7070Given 7071 void (*fp)(void); 7072The matcher 7073 varDecl(hasType(pointerType(pointee(ignoringParens(functionType()))))) 7074would match the declaration for fp. 7075</pre></td></tr> 7076 7077 7078<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> 7079<tr><td colspan="4" class="doc" id="pointsTo1"><pre>Overloaded to match the pointee type's declaration. 7080</pre></td></tr> 7081 7082 7083<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> 7084<tr><td colspan="4" class="doc" id="pointsTo0"><pre>Matches if the matched type is a pointer type and the pointee type 7085matches the specified matcher. 7086 7087Example matches y->x() 7088 (matcher = cxxMemberCallExpr(on(hasType(pointsTo 7089 cxxRecordDecl(hasName("Y"))))))) 7090 class Y { public: void x(); }; 7091 void z() { Y *y; y->x(); } 7092</pre></td></tr> 7093 7094 7095<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> 7096<tr><td colspan="4" class="doc" id="references1"><pre>Overloaded to match the referenced type's declaration. 7097</pre></td></tr> 7098 7099 7100<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> 7101<tr><td colspan="4" class="doc" id="references0"><pre>Matches if the matched type is a reference type and the referenced 7102type matches the specified matcher. 7103 7104Example matches X &x and const X &y 7105 (matcher = varDecl(hasType(references(cxxRecordDecl(hasName("X")))))) 7106 class X { 7107 void a(X b) { 7108 X &x = b; 7109 const X &y = b; 7110 } 7111 }; 7112</pre></td></tr> 7113 7114 7115<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>></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> 7116<tr><td colspan="4" class="doc" id="hasDeclaration5"><pre>Matches a node if the declaration associated with that node 7117matches the given matcher. 7118 7119The associated declaration is: 7120- for type nodes, the declaration of the underlying type 7121- for CallExpr, the declaration of the callee 7122- for MemberExpr, the declaration of the referenced member 7123- for CXXConstructExpr, the declaration of the constructor 7124- for CXXNewExpr, the declaration of the operator new 7125- for ObjCIvarExpr, the declaration of the ivar 7126 7127For type nodes, hasDeclaration will generally match the declaration of the 7128sugared type. Given 7129 class X {}; 7130 typedef X Y; 7131 Y y; 7132in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 7133typedefDecl. A common use case is to match the underlying, desugared type. 7134This can be achieved by using the hasUnqualifiedDesugaredType matcher: 7135 varDecl(hasType(hasUnqualifiedDesugaredType( 7136 recordType(hasDeclaration(decl()))))) 7137In this matcher, the decl will match the CXXRecordDecl of class X. 7138 7139Usable 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>>, 7140 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>>, 7141 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, 7142 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<<a href="https://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, 7143 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, 7144 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, 7145 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 7146</pre></td></tr> 7147 7148 7149<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> 7150<tr><td colspan="4" class="doc" id="pointee3"><pre>Narrows PointerType (and similar) matchers to those where the 7151pointee matches a given matcher. 7152 7153Given 7154 int *a; 7155 int const *b; 7156 float const *f; 7157pointerType(pointee(isConstQualified(), isInteger())) 7158 matches "int const *b" 7159 7160Usable 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>>, 7161 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>> 7162</pre></td></tr> 7163 7164 7165<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> 7166<tr><td colspan="4" class="doc" id="hasReturnValue0"><pre>Matches the return value expression of a return statement 7167 7168Given 7169 return a + b; 7170hasReturnValue(binaryOperator()) 7171 matches 'return a + b' 7172with binaryOperator() 7173 matching 'a + b' 7174</pre></td></tr> 7175 7176 7177<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> 7178<tr><td colspan="4" class="doc" id="hasAnySubstatement1"><pre>Matches compound statements where at least one substatement matches 7179a given matcher. Also matches StmtExprs that have CompoundStmt as children. 7180 7181Given 7182 { {}; 1+2; } 7183hasAnySubstatement(compoundStmt()) 7184 matches '{ {}; 1+2; }' 7185with compoundStmt() 7186 matching '{}' 7187</pre></td></tr> 7188 7189 7190<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> 7191<tr><td colspan="4" class="doc" id="alignOfExpr0"><pre>Same as unaryExprOrTypeTraitExpr, but only matching 7192alignof. 7193</pre></td></tr> 7194 7195 7196<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> 7197<tr><td colspan="4" class="doc" id="forFunction0"><pre>Matches declaration of the function the statement belongs to 7198 7199Given: 7200F& operator=(const F& o) { 7201 std::copy_if(o.begin(), o.end(), begin(), [](V v) { return v > 0; }); 7202 return *this; 7203} 7204returnStmt(forFunction(hasName("operator="))) 7205 matches 'return *this' 7206 but does not match 'return v > 0' 7207</pre></td></tr> 7208 7209 7210<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> 7211<tr><td colspan="4" class="doc" id="sizeOfExpr0"><pre>Same as unaryExprOrTypeTraitExpr, but only matching 7212sizeof. 7213</pre></td></tr> 7214 7215 7216<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1SubstTemplateTypeParmType.html">SubstTemplateTypeParmType</a>></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> 7217<tr><td colspan="4" class="doc" id="hasReplacementType0"><pre>Matches template type parameter substitutions that have a replacement 7218type that matches the provided matcher. 7219 7220Given 7221 template <typename T> 7222 double F(T t); 7223 int i; 7224 double j = F(i); 7225 7226substTemplateTypeParmType(hasReplacementType(type())) matches int 7227</pre></td></tr> 7228 7229 7230<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> 7231<tr><td colspan="4" class="doc" id="forEachSwitchCase0"><pre>Matches each case or default statement belonging to the given switch 7232statement. This matcher may produce multiple matches. 7233 7234Given 7235 switch (1) { case 1: case 2: default: switch (2) { case 3: case 4: ; } } 7236switchStmt(forEachSwitchCase(caseStmt().bind("c"))).bind("s") 7237 matches four times, with "c" binding each of "case 1:", "case 2:", 7238"case 3:" and "case 4:", and "s" respectively binding "switch (1)", 7239"switch (1)", "switch (2)" and "switch (2)". 7240</pre></td></tr> 7241 7242 7243<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> 7244<tr><td colspan="4" class="doc" id="hasCondition4"><pre>Matches the condition expression of an if statement, for loop, 7245switch statement or conditional operator. 7246 7247Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true)))) 7248 if (true) {} 7249</pre></td></tr> 7250 7251 7252<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> 7253<tr><td colspan="4" class="doc" id="hasInitStatement1"><pre>Matches selection statements with initializer. 7254 7255Given: 7256 void foo() { 7257 if (int i = foobar(); i > 0) {} 7258 switch (int i = foobar(); i) {} 7259 for (auto& a = get_range(); auto& x : a) {} 7260 } 7261 void bar() { 7262 if (foobar() > 0) {} 7263 switch (foobar()) {} 7264 for (auto& x : get_range()) {} 7265 } 7266ifStmt(hasInitStatement(anything())) 7267 matches the if statement in foo but not in bar. 7268switchStmt(hasInitStatement(anything())) 7269 matches the switch statement in foo but not in bar. 7270cxxForRangeStmt(hasInitStatement(anything())) 7271 matches the range for statement in foo but not in bar. 7272</pre></td></tr> 7273 7274 7275<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>></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> 7276<tr><td colspan="4" class="doc" id="hasDeclaration4"><pre>Matches a node if the declaration associated with that node 7277matches the given matcher. 7278 7279The associated declaration is: 7280- for type nodes, the declaration of the underlying type 7281- for CallExpr, the declaration of the callee 7282- for MemberExpr, the declaration of the referenced member 7283- for CXXConstructExpr, the declaration of the constructor 7284- for CXXNewExpr, the declaration of the operator new 7285- for ObjCIvarExpr, the declaration of the ivar 7286 7287For type nodes, hasDeclaration will generally match the declaration of the 7288sugared type. Given 7289 class X {}; 7290 typedef X Y; 7291 Y y; 7292in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 7293typedefDecl. A common use case is to match the underlying, desugared type. 7294This can be achieved by using the hasUnqualifiedDesugaredType matcher: 7295 varDecl(hasType(hasUnqualifiedDesugaredType( 7296 recordType(hasDeclaration(decl()))))) 7297In this matcher, the decl will match the CXXRecordDecl of class X. 7298 7299Usable 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>>, 7300 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>>, 7301 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, 7302 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<<a href="https://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, 7303 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, 7304 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, 7305 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 7306</pre></td></tr> 7307 7308 7309<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> 7310<tr><td colspan="4" class="doc" id="isExpr0"><pre>Matches a sugar TemplateArgument that refers to a certain expression. 7311 7312Given 7313 struct B { int next; }; 7314 template<int(B::*next_ptr)> struct A {}; 7315 A<&B::next> a; 7316templateSpecializationType(hasAnyTemplateArgument( 7317 isExpr(hasDescendant(declRefExpr(to(fieldDecl(hasName("next")))))))) 7318 matches the specialization A<&B::next> with fieldDecl(...) matching 7319 B::next 7320</pre></td></tr> 7321 7322 7323<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> 7324<tr><td colspan="4" class="doc" id="refersToDeclaration0"><pre>Matches a canonical TemplateArgument that refers to a certain 7325declaration. 7326 7327Given 7328 struct B { int next; }; 7329 template<int(B::*next_ptr)> struct A {}; 7330 A<&B::next> a; 7331classTemplateSpecializationDecl(hasAnyTemplateArgument( 7332 refersToDeclaration(fieldDecl(hasName("next"))))) 7333 matches the specialization A<&B::next> with fieldDecl(...) matching 7334 B::next 7335</pre></td></tr> 7336 7337 7338<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> 7339<tr><td colspan="4" class="doc" id="refersToIntegralType0"><pre>Matches a TemplateArgument that referes to an integral type. 7340 7341Given 7342 template<int T> struct C {}; 7343 C<42> c; 7344classTemplateSpecializationDecl( 7345 hasAnyTemplateArgument(refersToIntegralType(asString("int")))) 7346 matches the implicit instantiation of C in C<42>. 7347</pre></td></tr> 7348 7349 7350<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> 7351<tr><td colspan="4" class="doc" id="refersToTemplate0"><pre>Matches a TemplateArgument that refers to a certain template. 7352 7353Given 7354 template<template <typename> class S> class X {}; 7355 template<typename T> class Y {}; 7356 X<Y> xi; 7357classTemplateSpecializationDecl(hasAnyTemplateArgument( 7358 refersToTemplate(templateName()))) 7359 matches the specialization X<Y> 7360</pre></td></tr> 7361 7362 7363<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> 7364<tr><td colspan="4" class="doc" id="refersToType0"><pre>Matches a TemplateArgument that refers to a certain type. 7365 7366Given 7367 struct X {}; 7368 template<typename T> struct A {}; 7369 A<X> a; 7370classTemplateSpecializationDecl(hasAnyTemplateArgument( 7371 refersToType(class(hasName("X"))))) 7372 matches the specialization A<X> 7373</pre></td></tr> 7374 7375 7376<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</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> 7377<tr><td colspan="4" class="doc" id="hasAnyTemplateArgument1"><pre>Matches classTemplateSpecializations, templateSpecializationType and 7378functionDecl that have at least one TemplateArgument matching the given 7379InnerMatcher. 7380 7381Given 7382 template<typename T> class A {}; 7383 template<> class A<double> {}; 7384 A<int> a; 7385 7386 template<typename T> f() {}; 7387 void func() { f<int>(); }; 7388 7389classTemplateSpecializationDecl(hasAnyTemplateArgument( 7390 refersToType(asString("int")))) 7391 matches the specialization A<int> 7392 7393functionDecl(hasAnyTemplateArgument(refersToType(asString("int")))) 7394 matches the specialization f<int> 7395</pre></td></tr> 7396 7397 7398<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>></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> 7399<tr><td colspan="4" class="doc" id="hasDeclaration3"><pre>Matches a node if the declaration associated with that node 7400matches the given matcher. 7401 7402The associated declaration is: 7403- for type nodes, the declaration of the underlying type 7404- for CallExpr, the declaration of the callee 7405- for MemberExpr, the declaration of the referenced member 7406- for CXXConstructExpr, the declaration of the constructor 7407- for CXXNewExpr, the declaration of the operator new 7408- for ObjCIvarExpr, the declaration of the ivar 7409 7410For type nodes, hasDeclaration will generally match the declaration of the 7411sugared type. Given 7412 class X {}; 7413 typedef X Y; 7414 Y y; 7415in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 7416typedefDecl. A common use case is to match the underlying, desugared type. 7417This can be achieved by using the hasUnqualifiedDesugaredType matcher: 7418 varDecl(hasType(hasUnqualifiedDesugaredType( 7419 recordType(hasDeclaration(decl()))))) 7420In this matcher, the decl will match the CXXRecordDecl of class X. 7421 7422Usable 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>>, 7423 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>>, 7424 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, 7425 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<<a href="https://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, 7426 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, 7427 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, 7428 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 7429</pre></td></tr> 7430 7431 7432<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</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> 7433<tr><td colspan="4" class="doc" id="hasTemplateArgument1"><pre>Matches classTemplateSpecializations, templateSpecializationType and 7434functionDecl where the n'th TemplateArgument matches the given InnerMatcher. 7435 7436Given 7437 template<typename T, typename U> class A {}; 7438 A<bool, int> b; 7439 A<int, bool> c; 7440 7441 template<typename T> void f() {} 7442 void func() { f<int>(); }; 7443classTemplateSpecializationDecl(hasTemplateArgument( 7444 1, refersToType(asString("int")))) 7445 matches the specialization A<bool, int> 7446 7447functionDecl(hasTemplateArgument(0, refersToType(asString("int")))) 7448 matches the specialization f<int> 7449</pre></td></tr> 7450 7451 7452<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</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> 7453<tr><td colspan="4" class="doc" id="hasDeclaration2"><pre>Matches a node if the declaration associated with that node 7454matches the given matcher. 7455 7456The associated declaration is: 7457- for type nodes, the declaration of the underlying type 7458- for CallExpr, the declaration of the callee 7459- for MemberExpr, the declaration of the referenced member 7460- for CXXConstructExpr, the declaration of the constructor 7461- for CXXNewExpr, the declaration of the operator new 7462- for ObjCIvarExpr, the declaration of the ivar 7463 7464For type nodes, hasDeclaration will generally match the declaration of the 7465sugared type. Given 7466 class X {}; 7467 typedef X Y; 7468 Y y; 7469in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 7470typedefDecl. A common use case is to match the underlying, desugared type. 7471This can be achieved by using the hasUnqualifiedDesugaredType matcher: 7472 varDecl(hasType(hasUnqualifiedDesugaredType( 7473 recordType(hasDeclaration(decl()))))) 7474In this matcher, the decl will match the CXXRecordDecl of class X. 7475 7476Usable 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>>, 7477 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>>, 7478 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, 7479 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<<a href="https://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, 7480 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, 7481 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, 7482 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 7483</pre></td></tr> 7484 7485 7486<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> 7487<tr><td colspan="4" class="doc" id="loc0"><pre>Matches TypeLocs for which the given inner 7488QualType-matcher matches. 7489</pre></td></tr> 7490 7491 7492<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> 7493<tr><td colspan="4" class="doc" id="hasType2"><pre>Matches if the expression's or declaration's type matches a type 7494matcher. 7495 7496Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) 7497 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) 7498 and U (matcher = typedefDecl(hasType(asString("int"))) 7499 and friend class X (matcher = friendDecl(hasType("X")) 7500 class X {}; 7501 void y(X &x) { x; X z; } 7502 typedef int U; 7503 class Y { friend class X; }; 7504</pre></td></tr> 7505 7506 7507<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</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> 7508<tr><td colspan="4" class="doc" id="hasDeclaration1"><pre>Matches a node if the declaration associated with that node 7509matches the given matcher. 7510 7511The associated declaration is: 7512- for type nodes, the declaration of the underlying type 7513- for CallExpr, the declaration of the callee 7514- for MemberExpr, the declaration of the referenced member 7515- for CXXConstructExpr, the declaration of the constructor 7516- for CXXNewExpr, the declaration of the operator new 7517- for ObjCIvarExpr, the declaration of the ivar 7518 7519For type nodes, hasDeclaration will generally match the declaration of the 7520sugared type. Given 7521 class X {}; 7522 typedef X Y; 7523 Y y; 7524in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 7525typedefDecl. A common use case is to match the underlying, desugared type. 7526This can be achieved by using the hasUnqualifiedDesugaredType matcher: 7527 varDecl(hasType(hasUnqualifiedDesugaredType( 7528 recordType(hasDeclaration(decl()))))) 7529In this matcher, the decl will match the CXXRecordDecl of class X. 7530 7531Usable 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>>, 7532 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>>, 7533 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, 7534 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<<a href="https://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, 7535 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, 7536 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, 7537 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 7538</pre></td></tr> 7539 7540 7541<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> 7542<tr><td colspan="4" class="doc" id="hasUnqualifiedDesugaredType0"><pre>Matches if the matched type matches the unqualified desugared 7543type of the matched node. 7544 7545For example, in: 7546 class A {}; 7547 using B = A; 7548The matcher type(hasUnqualifiedDesugaredType(recordType())) matches 7549both B and A. 7550</pre></td></tr> 7551 7552 7553<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> 7554<tr><td colspan="4" class="doc" id="hasArgumentOfType0"><pre>Matches unary expressions that have a specific type of argument. 7555 7556Given 7557 int a, c; float b; int s = sizeof(a) + sizeof(b) + alignof(c); 7558unaryExprOrTypeTraitExpr(hasArgumentOfType(asString("int")) 7559 matches sizeof(a) and alignof(c) 7560</pre></td></tr> 7561 7562 7563<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> 7564<tr><td colspan="4" class="doc" id="hasUnaryOperand0"><pre>Matches if the operand of a unary operator matches. 7565 7566Example matches true (matcher = hasUnaryOperand( 7567 cxxBoolLiteral(equals(true)))) 7568 !true 7569</pre></td></tr> 7570 7571 7572<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> 7573<tr><td colspan="4" class="doc" id="hasObjectExpression1"><pre>Matches a member expression where the object expression is matched by a 7574given matcher. Implicit object expressions are included; that is, it matches 7575use of implicit `this`. 7576 7577Given 7578 struct X { 7579 int m; 7580 int f(X x) { x.m; return m; } 7581 }; 7582memberExpr(hasObjectExpression(hasType(cxxRecordDecl(hasName("X"))))) 7583 matches `x.m`, but not `m`; however, 7584memberExpr(hasObjectExpression(hasType(pointsTo( 7585 cxxRecordDecl(hasName("X")))))) 7586 matches `m` (aka. `this->m`), but not `x.m`. 7587</pre></td></tr> 7588 7589 7590<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</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> 7591<tr><td colspan="4" class="doc" id="hasDeclaration0"><pre>Matches a node if the declaration associated with that node 7592matches the given matcher. 7593 7594The associated declaration is: 7595- for type nodes, the declaration of the underlying type 7596- for CallExpr, the declaration of the callee 7597- for MemberExpr, the declaration of the referenced member 7598- for CXXConstructExpr, the declaration of the constructor 7599- for CXXNewExpr, the declaration of the operator new 7600- for ObjCIvarExpr, the declaration of the ivar 7601 7602For type nodes, hasDeclaration will generally match the declaration of the 7603sugared type. Given 7604 class X {}; 7605 typedef X Y; 7606 Y y; 7607in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 7608typedefDecl. A common use case is to match the underlying, desugared type. 7609This can be achieved by using the hasUnqualifiedDesugaredType matcher: 7610 varDecl(hasType(hasUnqualifiedDesugaredType( 7611 recordType(hasDeclaration(decl()))))) 7612In this matcher, the decl will match the CXXRecordDecl of class X. 7613 7614Usable 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>>, 7615 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>>, 7616 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, 7617 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<<a href="https://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, 7618 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, 7619 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, 7620 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 7621</pre></td></tr> 7622 7623 7624<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingDecl.html">UsingDecl</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> 7625<tr><td colspan="4" class="doc" id="hasAnyUsingShadowDecl0"><pre>Matches any using shadow declaration. 7626 7627Given 7628 namespace X { void b(); } 7629 using X::b; 7630usingDecl(hasAnyUsingShadowDecl(hasName("b")))) 7631 matches using X::b </pre></td></tr> 7632 7633 7634<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> 7635<tr><td colspan="4" class="doc" id="hasTargetDecl0"><pre>Matches a using shadow declaration where the target declaration is 7636matched by the given matcher. 7637 7638Given 7639 namespace X { int a; void b(); } 7640 using X::a; 7641 using X::b; 7642usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(functionDecl()))) 7643 matches using X::b but not using X::a </pre></td></tr> 7644 7645 7646<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</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> 7647<tr><td colspan="4" class="doc" id="hasType6"><pre>Overloaded to match the declaration of the expression's or value 7648declaration's type. 7649 7650In case of a value declaration (for example a variable declaration), 7651this resolves one layer of indirection. For example, in the value 7652declaration "X x;", cxxRecordDecl(hasName("X")) matches the declaration of 7653X, while varDecl(hasType(cxxRecordDecl(hasName("X")))) matches the 7654declaration of x. 7655 7656Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) 7657 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) 7658 and friend class X (matcher = friendDecl(hasType("X")) 7659 class X {}; 7660 void y(X &x) { x; X z; } 7661 class Y { friend class X; }; 7662 7663Usable 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_1ValueDecl.html">ValueDecl</a>> 7664</pre></td></tr> 7665 7666 7667<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> 7668<tr><td colspan="4" class="doc" id="hasType3"><pre>Matches if the expression's or declaration's type matches a type 7669matcher. 7670 7671Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) 7672 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) 7673 and U (matcher = typedefDecl(hasType(asString("int"))) 7674 and friend class X (matcher = friendDecl(hasType("X")) 7675 class X {}; 7676 void y(X &x) { x; X z; } 7677 typedef int U; 7678 class Y { friend class X; }; 7679</pre></td></tr> 7680 7681 7682<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> 7683<tr><td colspan="4" class="doc" id="hasInitializer0"><pre>Matches a variable declaration that has an initializer expression 7684that matches the given matcher. 7685 7686Example matches x (matcher = varDecl(hasInitializer(callExpr()))) 7687 bool y() { return true; } 7688 bool x = y(); 7689</pre></td></tr> 7690 7691 7692<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> 7693<tr><td colspan="4" class="doc" id="hasSizeExpr0"><pre>Matches VariableArrayType nodes that have a specific size 7694expression. 7695 7696Given 7697 void f(int b) { 7698 int a[b]; 7699 } 7700variableArrayType(hasSizeExpr(ignoringImpCasts(declRefExpr(to( 7701 varDecl(hasName("b"))))))) 7702 matches "int a[b]" 7703</pre></td></tr> 7704 7705 7706<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> 7707<tr><td colspan="4" class="doc" id="hasBody2"><pre>Matches a 'for', 'while', 'do while' statement or a function 7708definition that has a given body. 7709 7710Given 7711 for (;;) {} 7712hasBody(compoundStmt()) 7713 matches 'for (;;) {}' 7714with compoundStmt() 7715 matching '{}' 7716</pre></td></tr> 7717 7718 7719<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> 7720<tr><td colspan="4" class="doc" id="hasCondition2"><pre>Matches the condition expression of an if statement, for loop, 7721switch statement or conditional operator. 7722 7723Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true)))) 7724 if (true) {} 7725</pre></td></tr> 7726 7727<!--END_TRAVERSAL_MATCHERS --> 7728</table> 7729 7730</div> 7731</body> 7732</html> 7733 7734 7735