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