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