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