1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 2 "http://www.w3.org/TR/html4/strict.dtd"> 3<html> 4<head> 5<title>AST Matcher Reference</title> 6<link type="text/css" rel="stylesheet" href="../menu.css" /> 7<link type="text/css" rel="stylesheet" href="../content.css" /> 8<style type="text/css"> 9td { 10 padding: .33em; 11} 12td.doc { 13 display: none; 14 border-bottom: 1px solid black; 15} 16td.name:hover { 17 color: blue; 18 cursor: pointer; 19} 20</style> 21<script type="text/javascript"> 22function toggle(id) { 23 if (!id) return; 24 row = document.getElementById(id); 25 if (row.style.display != 'table-cell') 26 row.style.display = 'table-cell'; 27 else 28 row.style.display = 'none'; 29} 30</script> 31</head> 32<body onLoad="toggle(location.hash.substring(1, location.hash.length - 6))"> 33 34<!--#include virtual="../menu.html.incl"--> 35 36<div id="content"> 37 38<h1>AST Matcher Reference</h1> 39 40<p>This document shows all currently implemented matchers. The matchers are grouped 41by category and node type they match. You can click on matcher names to show the 42matcher's source documentation.</p> 43 44<p>There are three different basic categories of matchers: 45<ul> 46<li><a href="#decl-matchers">Node Matchers:</a> Matchers that match a specific type of AST node.</li> 47<li><a href="#narrowing-matchers">Narrowing Matchers:</a> Matchers that match attributes on AST nodes.</li> 48<li><a href="#traversal-matchers">Traversal Matchers:</a> Matchers that allow traversal between AST nodes.</li> 49</ul> 50</p> 51 52<p>Within each category the matchers are ordered by node type they match on. 53Note that if a matcher can match multiple node types, it will it will appear 54multiple times. This means that by searching for Matcher<Stmt> you can 55find all matchers that can be used to match on Stmt nodes.</p> 56 57<p>The exception to that rule are matchers that can match on any node. Those 58are marked with a * and are listed in the beginning of each category.</p> 59 60<p>Note that the categorization of matchers is a great help when you combine 61them into matcher expressions. You will usually want to form matcher expressions 62that read like english sentences by alternating between node matchers and 63narrowing or traversal matchers, like this: 64<pre> 65recordDecl(hasDescendant( 66 ifStmt(hasTrueExpression( 67 expr(hasDescendant( 68 ifStmt())))))) 69</pre> 70</p> 71 72<!-- ======================================================================= --> 73<h2 id="decl-matchers">Node Matchers</h2> 74<!-- ======================================================================= --> 75 76<p>Node matchers are at the core of matcher expressions - they specify the type 77of node that is expected. Every match expression starts with a node matcher, 78which can then be further refined with a narrowing or traversal matcher. All 79traversal matchers take node matchers as their arguments.</p> 80 81<p>For convenience, all node matchers take an arbitrary number of arguments 82and implicitly act as allOf matchers.</p> 83 84<p>Node matchers are the only matchers that support the bind("id") call to 85bind the matched node to the given string, to be later retrieved from the 86match callback.</p> 87 88<p>It is important to remember that the arguments to node matchers are 89predicates on the same node, just with additional information about the type. 90This is often useful to make matcher expression more readable by inlining bind 91calls into redundant node matchers inside another node matcher: 92<pre> 93// This binds the CXXRecordDecl to "id", as the decl() matcher will stay on 94// the same node. 95recordDecl(decl().bind("id"), hasName("::MyClass")) 96</pre> 97</p> 98 99<table> 100<tr style="text-align:left"><th>Return type</th><th>Name</th><th>Parameters</th></tr> 101<!-- START_DECL_MATCHERS --> 102 103<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>></td><td class="name" onclick="toggle('cxxCtorInitializer0')"><a name="cxxCtorInitializer0Anchor">cxxCtorInitializer</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>>...</td></tr> 104<tr><td colspan="4" class="doc" id="cxxCtorInitializer0"><pre>Matches constructor initializers. 105 106Examples matches i(42). 107 class C { 108 C() : i(42) {} 109 int i; 110 }; 111</pre></td></tr> 112 113 114<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('accessSpecDecl0')"><a name="accessSpecDecl0Anchor">accessSpecDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AccessSpecDecl.html">AccessSpecDecl</a>>...</td></tr> 115<tr><td colspan="4" class="doc" id="accessSpecDecl0"><pre>Matches C++ access specifier declarations. 116 117Given 118 class C { 119 public: 120 int a; 121 }; 122accessSpecDecl() 123 matches 'public:' 124</pre></td></tr> 125 126 127<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('blockDecl0')"><a name="blockDecl0Anchor">blockDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockDecl.html">BlockDecl</a>>...</td></tr> 128<tr><td colspan="4" class="doc" id="blockDecl0"><pre>Matches block declarations. 129 130Example matches the declaration of the nameless block printing an input 131integer. 132 133 myFunc(^(int p) { 134 printf("%d", p); 135 }) 136</pre></td></tr> 137 138 139<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('classTemplateDecl0')"><a name="classTemplateDecl0Anchor">classTemplateDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ClassTemplateDecl.html">ClassTemplateDecl</a>>...</td></tr> 140<tr><td colspan="4" class="doc" id="classTemplateDecl0"><pre>Matches C++ class template declarations. 141 142Example matches Z 143 template<class T> class Z {}; 144</pre></td></tr> 145 146 147<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('classTemplatePartialSpecializationDecl0')"><a name="classTemplatePartialSpecializationDecl0Anchor">classTemplatePartialSpecializationDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ClassTemplatePartialSpecializationDecl.html">ClassTemplatePartialSpecializationDecl</a>>...</td></tr> 148<tr><td colspan="4" class="doc" id="classTemplatePartialSpecializationDecl0"><pre>Matches C++ class template partial specializations. 149 150Given 151 template<class T1, class T2, int I> 152 class A {}; 153 154 template<class T, int I> 155 class A<T, T*, I> {}; 156 157 template<> 158 class A<int, int, 1> {}; 159classTemplatePartialSpecializationDecl() 160 matches the specialization A<T,T*,I> but not A<int,int,1> 161</pre></td></tr> 162 163 164<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('classTemplateSpecializationDecl0')"><a name="classTemplateSpecializationDecl0Anchor">classTemplateSpecializationDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html">ClassTemplateSpecializationDecl</a>>...</td></tr> 165<tr><td colspan="4" class="doc" id="classTemplateSpecializationDecl0"><pre>Matches C++ class template specializations. 166 167Given 168 template<typename T> class A {}; 169 template<> class A<double> {}; 170 A<int> a; 171classTemplateSpecializationDecl() 172 matches the specializations A<int> and A<double> 173</pre></td></tr> 174 175 176<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('cxxConstructorDecl0')"><a name="cxxConstructorDecl0Anchor">cxxConstructorDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html">CXXConstructorDecl</a>>...</td></tr> 177<tr><td colspan="4" class="doc" id="cxxConstructorDecl0"><pre>Matches C++ constructor declarations. 178 179Example matches Foo::Foo() and Foo::Foo(int) 180 class Foo { 181 public: 182 Foo(); 183 Foo(int); 184 int DoSomething(); 185 }; 186</pre></td></tr> 187 188 189<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('cxxConversionDecl0')"><a name="cxxConversionDecl0Anchor">cxxConversionDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConversionDecl.html">CXXConversionDecl</a>>...</td></tr> 190<tr><td colspan="4" class="doc" id="cxxConversionDecl0"><pre>Matches conversion operator declarations. 191 192Example matches the operator. 193 class X { operator int() const; }; 194</pre></td></tr> 195 196 197<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('cxxDestructorDecl0')"><a name="cxxDestructorDecl0Anchor">cxxDestructorDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXDestructorDecl.html">CXXDestructorDecl</a>>...</td></tr> 198<tr><td colspan="4" class="doc" id="cxxDestructorDecl0"><pre>Matches explicit C++ destructor declarations. 199 200Example matches Foo::~Foo() 201 class Foo { 202 public: 203 virtual ~Foo(); 204 }; 205</pre></td></tr> 206 207 208<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('cxxMethodDecl0')"><a name="cxxMethodDecl0Anchor">cxxMethodDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>>...</td></tr> 209<tr><td colspan="4" class="doc" id="cxxMethodDecl0"><pre>Matches method declarations. 210 211Example matches y 212 class X { void y(); }; 213</pre></td></tr> 214 215 216<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('cxxRecordDecl0')"><a name="cxxRecordDecl0Anchor">cxxRecordDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>>...</td></tr> 217<tr><td colspan="4" class="doc" id="cxxRecordDecl0"><pre>Matches C++ class declarations. 218 219Example matches X, Z 220 class X; 221 template<class T> class Z {}; 222</pre></td></tr> 223 224 225<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('decl0')"><a name="decl0Anchor">decl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>...</td></tr> 226<tr><td colspan="4" class="doc" id="decl0"><pre>Matches declarations. 227 228Examples matches X, C, and the friend declaration inside C; 229 void X(); 230 class C { 231 friend X; 232 }; 233</pre></td></tr> 234 235 236<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('declaratorDecl0')"><a name="declaratorDecl0Anchor">declaratorDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclaratorDecl.html">DeclaratorDecl</a>>...</td></tr> 237<tr><td colspan="4" class="doc" id="declaratorDecl0"><pre>Matches declarator declarations (field, variable, function 238and non-type template parameter declarations). 239 240Given 241 class X { int y; }; 242declaratorDecl() 243 matches int y. 244</pre></td></tr> 245 246 247<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('enumConstantDecl0')"><a name="enumConstantDecl0Anchor">enumConstantDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1EnumConstantDecl.html">EnumConstantDecl</a>>...</td></tr> 248<tr><td colspan="4" class="doc" id="enumConstantDecl0"><pre>Matches enum constants. 249 250Example matches A, B, C 251 enum X { 252 A, B, C 253 }; 254</pre></td></tr> 255 256 257<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('enumDecl0')"><a name="enumDecl0Anchor">enumDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1EnumDecl.html">EnumDecl</a>>...</td></tr> 258<tr><td colspan="4" class="doc" id="enumDecl0"><pre>Matches enum declarations. 259 260Example matches X 261 enum X { 262 A, B, C 263 }; 264</pre></td></tr> 265 266 267<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('fieldDecl0')"><a name="fieldDecl0Anchor">fieldDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html">FieldDecl</a>>...</td></tr> 268<tr><td colspan="4" class="doc" id="fieldDecl0"><pre>Matches field declarations. 269 270Given 271 class X { int m; }; 272fieldDecl() 273 matches 'm'. 274</pre></td></tr> 275 276 277<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('friendDecl0')"><a name="friendDecl0Anchor">friendDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FriendDecl.html">FriendDecl</a>>...</td></tr> 278<tr><td colspan="4" class="doc" id="friendDecl0"><pre>Matches friend declarations. 279 280Given 281 class X { friend void foo(); }; 282friendDecl() 283 matches 'friend void foo()'. 284</pre></td></tr> 285 286 287<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('functionDecl0')"><a name="functionDecl0Anchor">functionDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>...</td></tr> 288<tr><td colspan="4" class="doc" id="functionDecl0"><pre>Matches function declarations. 289 290Example matches f 291 void f(); 292</pre></td></tr> 293 294 295<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('functionTemplateDecl0')"><a name="functionTemplateDecl0Anchor">functionTemplateDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionTemplateDecl.html">FunctionTemplateDecl</a>>...</td></tr> 296<tr><td colspan="4" class="doc" id="functionTemplateDecl0"><pre>Matches C++ function template declarations. 297 298Example matches f 299 template<class T> void f(T t) {} 300</pre></td></tr> 301 302 303<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('indirectFieldDecl0')"><a name="indirectFieldDecl0Anchor">indirectFieldDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IndirectFieldDecl.html">IndirectFieldDecl</a>>...</td></tr> 304<tr><td colspan="4" class="doc" id="indirectFieldDecl0"><pre>Matches indirect field declarations. 305 306Given 307 struct X { struct { int a; }; }; 308indirectFieldDecl() 309 matches 'a'. 310</pre></td></tr> 311 312 313<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('labelDecl0')"><a name="labelDecl0Anchor">labelDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelDecl.html">LabelDecl</a>>...</td></tr> 314<tr><td colspan="4" class="doc" id="labelDecl0"><pre>Matches a declaration of label. 315 316Given 317 goto FOO; 318 FOO: bar(); 319labelDecl() 320 matches 'FOO:' 321</pre></td></tr> 322 323 324<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('linkageSpecDecl0')"><a name="linkageSpecDecl0Anchor">linkageSpecDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LinkageSpecDecl.html">LinkageSpecDecl</a>>...</td></tr> 325<tr><td colspan="4" class="doc" id="linkageSpecDecl0"><pre>Matches a declaration of a linkage specification. 326 327Given 328 extern "C" {} 329linkageSpecDecl() 330 matches "extern "C" {}" 331</pre></td></tr> 332 333 334<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('namedDecl0')"><a name="namedDecl0Anchor">namedDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>>...</td></tr> 335<tr><td colspan="4" class="doc" id="namedDecl0"><pre>Matches a declaration of anything that could have a name. 336 337Example matches X, S, the anonymous union type, i, and U; 338 typedef int X; 339 struct S { 340 union { 341 int i; 342 } U; 343 }; 344</pre></td></tr> 345 346 347<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('namespaceAliasDecl0')"><a name="namespaceAliasDecl0Anchor">namespaceAliasDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamespaceAliasDecl.html">NamespaceAliasDecl</a>>...</td></tr> 348<tr><td colspan="4" class="doc" id="namespaceAliasDecl0"><pre>Matches a declaration of a namespace alias. 349 350Given 351 namespace test {} 352 namespace alias = ::test; 353namespaceAliasDecl() 354 matches "namespace alias" but not "namespace test" 355</pre></td></tr> 356 357 358<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('namespaceDecl0')"><a name="namespaceDecl0Anchor">namespaceDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamespaceDecl.html">NamespaceDecl</a>>...</td></tr> 359<tr><td colspan="4" class="doc" id="namespaceDecl0"><pre>Matches a declaration of a namespace. 360 361Given 362 namespace {} 363 namespace test {} 364namespaceDecl() 365 matches "namespace {}" and "namespace test {}" 366</pre></td></tr> 367 368 369<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('nonTypeTemplateParmDecl0')"><a name="nonTypeTemplateParmDecl0Anchor">nonTypeTemplateParmDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NonTypeTemplateParmDecl.html">NonTypeTemplateParmDecl</a>>...</td></tr> 370<tr><td colspan="4" class="doc" id="nonTypeTemplateParmDecl0"><pre>Matches non-type template parameter declarations. 371 372Given 373 template <typename T, int N> struct C {}; 374nonTypeTemplateParmDecl() 375 matches 'N', but not 'T'. 376</pre></td></tr> 377 378 379<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('objcCategoryDecl0')"><a name="objcCategoryDecl0Anchor">objcCategoryDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCCategoryDecl.html">ObjCCategoryDecl</a>>...</td></tr> 380<tr><td colspan="4" class="doc" id="objcCategoryDecl0"><pre>Matches Objective-C category declarations. 381 382Example matches Foo (Additions) 383 @interface Foo (Additions) 384 @end 385</pre></td></tr> 386 387 388<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('objcCategoryImplDecl0')"><a name="objcCategoryImplDecl0Anchor">objcCategoryImplDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCCategoryImplDecl.html">ObjCCategoryImplDecl</a>>...</td></tr> 389<tr><td colspan="4" class="doc" id="objcCategoryImplDecl0"><pre>Matches Objective-C category definitions. 390 391Example matches Foo (Additions) 392 @implementation Foo (Additions) 393 @end 394</pre></td></tr> 395 396 397<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('objcImplementationDecl0')"><a name="objcImplementationDecl0Anchor">objcImplementationDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCImplementationDecl.html">ObjCImplementationDecl</a>>...</td></tr> 398<tr><td colspan="4" class="doc" id="objcImplementationDecl0"><pre>Matches Objective-C implementation declarations. 399 400Example matches Foo 401 @implementation Foo 402 @end 403</pre></td></tr> 404 405 406<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('objcInterfaceDecl0')"><a name="objcInterfaceDecl0Anchor">objcInterfaceDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCInterfaceDecl.html">ObjCInterfaceDecl</a>>...</td></tr> 407<tr><td colspan="4" class="doc" id="objcInterfaceDecl0"><pre>Matches Objective-C interface declarations. 408 409Example matches Foo 410 @interface Foo 411 @end 412</pre></td></tr> 413 414 415<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('objcIvarDecl0')"><a name="objcIvarDecl0Anchor">objcIvarDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCIvarDecl.html">ObjCIvarDecl</a>>...</td></tr> 416<tr><td colspan="4" class="doc" id="objcIvarDecl0"><pre>Matches Objective-C instance variable declarations. 417 418Example matches _enabled 419 @implementation Foo { 420 BOOL _enabled; 421 } 422 @end 423</pre></td></tr> 424 425 426<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('objcMethodDecl0')"><a name="objcMethodDecl0Anchor">objcMethodDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html">ObjCMethodDecl</a>>...</td></tr> 427<tr><td colspan="4" class="doc" id="objcMethodDecl0"><pre>Matches Objective-C method declarations. 428 429Example matches both declaration and definition of -[Foo method] 430 @interface Foo 431 - (void)method; 432 @end 433 434 @implementation Foo 435 - (void)method {} 436 @end 437</pre></td></tr> 438 439 440<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('objcPropertyDecl0')"><a name="objcPropertyDecl0Anchor">objcPropertyDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCPropertyDecl.html">ObjCPropertyDecl</a>>...</td></tr> 441<tr><td colspan="4" class="doc" id="objcPropertyDecl0"><pre>Matches Objective-C property declarations. 442 443Example matches enabled 444 @interface Foo 445 @property BOOL enabled; 446 @end 447</pre></td></tr> 448 449 450<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('objcProtocolDecl0')"><a name="objcProtocolDecl0Anchor">objcProtocolDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCProtocolDecl.html">ObjCProtocolDecl</a>>...</td></tr> 451<tr><td colspan="4" class="doc" id="objcProtocolDecl0"><pre>Matches Objective-C protocol declarations. 452 453Example matches FooDelegate 454 @protocol FooDelegate 455 @end 456</pre></td></tr> 457 458 459<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('parmVarDecl0')"><a name="parmVarDecl0Anchor">parmVarDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html">ParmVarDecl</a>>...</td></tr> 460<tr><td colspan="4" class="doc" id="parmVarDecl0"><pre>Matches parameter variable declarations. 461 462Given 463 void f(int x); 464parmVarDecl() 465 matches int x. 466</pre></td></tr> 467 468 469<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('recordDecl0')"><a name="recordDecl0Anchor">recordDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1RecordDecl.html">RecordDecl</a>>...</td></tr> 470<tr><td colspan="4" class="doc" id="recordDecl0"><pre>Matches class, struct, and union declarations. 471 472Example matches X, Z, U, and S 473 class X; 474 template<class T> class Z {}; 475 struct S {}; 476 union U {}; 477</pre></td></tr> 478 479 480<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('staticAssertDecl0')"><a name="staticAssertDecl0Anchor">staticAssertDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1StaticAssertDecl.html">StaticAssertDecl</a>>...</td></tr> 481<tr><td colspan="4" class="doc" id="staticAssertDecl0"><pre>Matches a C++ static_assert declaration. 482 483Example: 484 staticAssertExpr() 485matches 486 static_assert(sizeof(S) == sizeof(int)) 487in 488 struct S { 489 int x; 490 }; 491 static_assert(sizeof(S) == sizeof(int)); 492</pre></td></tr> 493 494 495<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('templateTypeParmDecl0')"><a name="templateTypeParmDecl0Anchor">templateTypeParmDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmDecl.html">TemplateTypeParmDecl</a>>...</td></tr> 496<tr><td colspan="4" class="doc" id="templateTypeParmDecl0"><pre>Matches template type parameter declarations. 497 498Given 499 template <typename T, int N> struct C {}; 500templateTypeParmDecl() 501 matches 'T', but not 'N'. 502</pre></td></tr> 503 504 505<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('translationUnitDecl0')"><a name="translationUnitDecl0Anchor">translationUnitDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TranslationUnitDecl.html">TranslationUnitDecl</a>>...</td></tr> 506<tr><td colspan="4" class="doc" id="translationUnitDecl0"><pre>Matches the top declaration context. 507 508Given 509 int X; 510 namespace NS { 511 int Y; 512 } // namespace NS 513decl(hasDeclContext(translationUnitDecl())) 514 matches "int X", but not "int Y". 515</pre></td></tr> 516 517 518<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('typeAliasDecl0')"><a name="typeAliasDecl0Anchor">typeAliasDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeAliasDecl.html">TypeAliasDecl</a>>...</td></tr> 519<tr><td colspan="4" class="doc" id="typeAliasDecl0"><pre>Matches type alias declarations. 520 521Given 522 typedef int X; 523 using Y = int; 524typeAliasDecl() 525 matches "using Y = int", but not "typedef int X" 526</pre></td></tr> 527 528 529<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('typeAliasTemplateDecl0')"><a name="typeAliasTemplateDecl0Anchor">typeAliasTemplateDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeAliasTemplateDecl.html">TypeAliasTemplateDecl</a>>...</td></tr> 530<tr><td colspan="4" class="doc" id="typeAliasTemplateDecl0"><pre>Matches type alias template declarations. 531 532typeAliasTemplateDecl() matches 533 template <typename T> 534 using Y = X<T>; 535</pre></td></tr> 536 537 538<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('typedefDecl0')"><a name="typedefDecl0Anchor">typedefDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefDecl.html">TypedefDecl</a>>...</td></tr> 539<tr><td colspan="4" class="doc" id="typedefDecl0"><pre>Matches typedef declarations. 540 541Given 542 typedef int X; 543 using Y = int; 544typedefDecl() 545 matches "typedef int X", but not "using Y = int" 546</pre></td></tr> 547 548 549<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('typedefNameDecl0')"><a name="typedefNameDecl0Anchor">typedefNameDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefNameDecl.html">TypedefNameDecl</a>>...</td></tr> 550<tr><td colspan="4" class="doc" id="typedefNameDecl0"><pre>Matches typedef name declarations. 551 552Given 553 typedef int X; 554 using Y = int; 555typedefNameDecl() 556 matches "typedef int X" and "using Y = int" 557</pre></td></tr> 558 559 560<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('unresolvedUsingTypenameDecl0')"><a name="unresolvedUsingTypenameDecl0Anchor">unresolvedUsingTypenameDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingTypenameDecl.html">UnresolvedUsingTypenameDecl</a>>...</td></tr> 561<tr><td colspan="4" class="doc" id="unresolvedUsingTypenameDecl0"><pre>Matches unresolved using value declarations that involve the 562typename. 563 564Given 565 template <typename T> 566 struct Base { typedef T Foo; }; 567 568 template<typename T> 569 struct S : private Base<T> { 570 using typename Base<T>::Foo; 571 }; 572unresolvedUsingTypenameDecl() 573 matches using Base<T>::Foo </pre></td></tr> 574 575 576<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('unresolvedUsingValueDecl0')"><a name="unresolvedUsingValueDecl0Anchor">unresolvedUsingValueDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingValueDecl.html">UnresolvedUsingValueDecl</a>>...</td></tr> 577<tr><td colspan="4" class="doc" id="unresolvedUsingValueDecl0"><pre>Matches unresolved using value declarations. 578 579Given 580 template<typename X> 581 class C : private X { 582 using X::x; 583 }; 584unresolvedUsingValueDecl() 585 matches using X::x </pre></td></tr> 586 587 588<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('usingDecl0')"><a name="usingDecl0Anchor">usingDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingDecl.html">UsingDecl</a>>...</td></tr> 589<tr><td colspan="4" class="doc" id="usingDecl0"><pre>Matches using declarations. 590 591Given 592 namespace X { int x; } 593 using X::x; 594usingDecl() 595 matches using X::x </pre></td></tr> 596 597 598<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('usingDirectiveDecl0')"><a name="usingDirectiveDecl0Anchor">usingDirectiveDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UsingDirectiveDecl.html">UsingDirectiveDecl</a>>...</td></tr> 599<tr><td colspan="4" class="doc" id="usingDirectiveDecl0"><pre>Matches using namespace declarations. 600 601Given 602 namespace X { int x; } 603 using namespace X; 604usingDirectiveDecl() 605 matches using namespace X </pre></td></tr> 606 607 608<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('valueDecl0')"><a name="valueDecl0Anchor">valueDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</a>>...</td></tr> 609<tr><td colspan="4" class="doc" id="valueDecl0"><pre>Matches any value declaration. 610 611Example matches A, B, C and F 612 enum X { A, B, C }; 613 void F(); 614</pre></td></tr> 615 616 617<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('varDecl0')"><a name="varDecl0Anchor">varDecl</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>...</td></tr> 618<tr><td colspan="4" class="doc" id="varDecl0"><pre>Matches variable declarations. 619 620Note: this does not match declarations of member variables, which are 621"field" declarations in Clang parlance. 622 623Example matches a 624 int a; 625</pre></td></tr> 626 627 628<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifierLoc.html">NestedNameSpecifierLoc</a>></td><td class="name" onclick="toggle('nestedNameSpecifierLoc0')"><a name="nestedNameSpecifierLoc0Anchor">nestedNameSpecifierLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifierLoc.html">NestedNameSpecifierLoc</a>>...</td></tr> 629<tr><td colspan="4" class="doc" id="nestedNameSpecifierLoc0"><pre>Same as nestedNameSpecifier but matches NestedNameSpecifierLoc. 630</pre></td></tr> 631 632 633<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifier.html">NestedNameSpecifier</a>></td><td class="name" onclick="toggle('nestedNameSpecifier0')"><a name="nestedNameSpecifier0Anchor">nestedNameSpecifier</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifier.html">NestedNameSpecifier</a>>...</td></tr> 634<tr><td colspan="4" class="doc" id="nestedNameSpecifier0"><pre>Matches nested name specifiers. 635 636Given 637 namespace ns { 638 struct A { static void f(); }; 639 void A::f() {} 640 void g() { A::f(); } 641 } 642 ns::A a; 643nestedNameSpecifier() 644 matches "ns::" and both "A::" 645</pre></td></tr> 646 647 648<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPClause.html">OMPClause</a>></td><td class="name" onclick="toggle('ompDefaultClause0')"><a name="ompDefaultClause0Anchor">ompDefaultClause</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPDefaultClause.html">OMPDefaultClause</a>>...</td></tr> 649<tr><td colspan="4" class="doc" id="ompDefaultClause0"><pre>Matches OpenMP ``default`` clause. 650 651Given 652 653 #pragma omp parallel default(none) 654 #pragma omp parallel default(shared) 655 #pragma omp parallel 656 657``ompDefaultClause()`` matches ``default(none)`` and ``default(shared)``. 658</pre></td></tr> 659 660 661<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('qualType0')"><a name="qualType0Anchor">qualType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>...</td></tr> 662<tr><td colspan="4" class="doc" id="qualType0"><pre>Matches QualTypes in the clang AST. 663</pre></td></tr> 664 665 666<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('addrLabelExpr0')"><a name="addrLabelExpr0Anchor">addrLabelExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>...</td></tr> 667<tr><td colspan="4" class="doc" id="addrLabelExpr0"><pre>Matches address of label statements (GNU extension). 668 669Given 670 FOO: bar(); 671 void *ptr = &&FOO; 672 goto *bar; 673addrLabelExpr() 674 matches '&&FOO' 675</pre></td></tr> 676 677 678<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('arraySubscriptExpr0')"><a name="arraySubscriptExpr0Anchor">arraySubscriptExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ArraySubscriptExpr.html">ArraySubscriptExpr</a>>...</td></tr> 679<tr><td colspan="4" class="doc" id="arraySubscriptExpr0"><pre>Matches array subscript expressions. 680 681Given 682 int i = a[1]; 683arraySubscriptExpr() 684 matches "a[1]" 685</pre></td></tr> 686 687 688<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('asmStmt0')"><a name="asmStmt0Anchor">asmStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AsmStmt.html">AsmStmt</a>>...</td></tr> 689<tr><td colspan="4" class="doc" id="asmStmt0"><pre>Matches asm statements. 690 691 int i = 100; 692 __asm("mov al, 2"); 693asmStmt() 694 matches '__asm("mov al, 2")' 695</pre></td></tr> 696 697 698<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('atomicExpr0')"><a name="atomicExpr0Anchor">atomicExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AtomicExpr.html">AtomicExpr</a>>...</td></tr> 699<tr><td colspan="4" class="doc" id="atomicExpr0"><pre>Matches atomic builtins. 700Example matches __atomic_load_n(ptr, 1) 701 void foo() { int *ptr; __atomic_load_n(ptr, 1); } 702</pre></td></tr> 703 704 705<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('autoreleasePoolStmt0')"><a name="autoreleasePoolStmt0Anchor">autoreleasePoolStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCAutoreleasePoolStmt.html">ObjCAutoreleasePoolStmt</a>>...</td></tr> 706<tr><td colspan="4" class="doc" id="autoreleasePoolStmt0"><pre>Matches an Objective-C autorelease pool statement. 707 708Given 709 @autoreleasepool { 710 int x = 0; 711 } 712autoreleasePoolStmt(stmt()) matches the declaration of "x" 713inside the autorelease pool. 714</pre></td></tr> 715 716 717<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('binaryConditionalOperator0')"><a name="binaryConditionalOperator0Anchor">binaryConditionalOperator</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BinaryConditionalOperator.html">BinaryConditionalOperator</a>>...</td></tr> 718<tr><td colspan="4" class="doc" id="binaryConditionalOperator0"><pre>Matches binary conditional operator expressions (GNU extension). 719 720Example matches a ?: b 721 (a ?: b) + 42; 722</pre></td></tr> 723 724 725<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('binaryOperator0')"><a name="binaryOperator0Anchor">binaryOperator</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html">BinaryOperator</a>>...</td></tr> 726<tr><td colspan="4" class="doc" id="binaryOperator0"><pre>Matches binary operator expressions. 727 728Example matches a || b 729 !(a || b) 730</pre></td></tr> 731 732 733<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('blockExpr0')"><a name="blockExpr0Anchor">blockExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockExpr.html">BlockExpr</a>>...</td></tr> 734<tr><td colspan="4" class="doc" id="blockExpr0"><pre>Matches a reference to a block. 735 736Example: matches "^{}": 737 void f() { ^{}(); } 738</pre></td></tr> 739 740 741<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('breakStmt0')"><a name="breakStmt0Anchor">breakStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BreakStmt.html">BreakStmt</a>>...</td></tr> 742<tr><td colspan="4" class="doc" id="breakStmt0"><pre>Matches break statements. 743 744Given 745 while (true) { break; } 746breakStmt() 747 matches 'break' 748</pre></td></tr> 749 750 751<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cStyleCastExpr0')"><a name="cStyleCastExpr0Anchor">cStyleCastExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CStyleCastExpr.html">CStyleCastExpr</a>>...</td></tr> 752<tr><td colspan="4" class="doc" id="cStyleCastExpr0"><pre>Matches a C-style cast expression. 753 754Example: Matches (int) 2.2f in 755 int i = (int) 2.2f; 756</pre></td></tr> 757 758 759<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('callExpr0')"><a name="callExpr0Anchor">callExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>...</td></tr> 760<tr><td colspan="4" class="doc" id="callExpr0"><pre>Matches call expressions. 761 762Example matches x.y() and y() 763 X x; 764 x.y(); 765 y(); 766</pre></td></tr> 767 768 769<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('caseStmt0')"><a name="caseStmt0Anchor">caseStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CaseStmt.html">CaseStmt</a>>...</td></tr> 770<tr><td colspan="4" class="doc" id="caseStmt0"><pre>Matches case statements inside switch statements. 771 772Given 773 switch(a) { case 42: break; default: break; } 774caseStmt() 775 matches 'case 42:'. 776</pre></td></tr> 777 778 779<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('castExpr0')"><a name="castExpr0Anchor">castExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CastExpr.html">CastExpr</a>>...</td></tr> 780<tr><td colspan="4" class="doc" id="castExpr0"><pre>Matches any cast nodes of Clang's AST. 781 782Example: castExpr() matches each of the following: 783 (int) 3; 784 const_cast<Expr *>(SubExpr); 785 char c = 0; 786but does not match 787 int i = (0); 788 int k = 0; 789</pre></td></tr> 790 791 792<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('characterLiteral0')"><a name="characterLiteral0Anchor">characterLiteral</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>>...</td></tr> 793<tr><td colspan="4" class="doc" id="characterLiteral0"><pre>Matches character literals (also matches wchar_t). 794 795Not matching Hex-encoded chars (e.g. 0x1234, which is a IntegerLiteral), 796though. 797 798Example matches 'a', L'a' 799 char ch = 'a'; 800 wchar_t chw = L'a'; 801</pre></td></tr> 802 803 804<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('chooseExpr0')"><a name="chooseExpr0Anchor">chooseExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ChooseExpr.html">ChooseExpr</a>>...</td></tr> 805<tr><td colspan="4" class="doc" id="chooseExpr0"><pre>Matches GNU __builtin_choose_expr. 806</pre></td></tr> 807 808 809<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('compoundLiteralExpr0')"><a name="compoundLiteralExpr0Anchor">compoundLiteralExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CompoundLiteralExpr.html">CompoundLiteralExpr</a>>...</td></tr> 810<tr><td colspan="4" class="doc" id="compoundLiteralExpr0"><pre>Matches compound (i.e. non-scalar) literals 811 812Example match: {1}, (1, 2) 813 int array[4] = {1}; 814 vector int myvec = (vector int)(1, 2); 815</pre></td></tr> 816 817 818<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('compoundStmt0')"><a name="compoundStmt0Anchor">compoundStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CompoundStmt.html">CompoundStmt</a>>...</td></tr> 819<tr><td colspan="4" class="doc" id="compoundStmt0"><pre>Matches compound statements. 820 821Example matches '{}' and '{{}}' in 'for (;;) {{}}' 822 for (;;) {{}} 823</pre></td></tr> 824 825 826<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('conditionalOperator0')"><a name="conditionalOperator0Anchor">conditionalOperator</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ConditionalOperator.html">ConditionalOperator</a>>...</td></tr> 827<tr><td colspan="4" class="doc" id="conditionalOperator0"><pre>Matches conditional operator expressions. 828 829Example matches a ? b : c 830 (a ? b : c) + 42 831</pre></td></tr> 832 833 834<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('constantExpr0')"><a name="constantExpr0Anchor">constantExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ConstantExpr.html">ConstantExpr</a>>...</td></tr> 835<tr><td colspan="4" class="doc" id="constantExpr0"><pre>Matches a constant expression wrapper. 836 837Example matches the constant in the case statement: 838 (matcher = constantExpr()) 839 switch (a) { 840 case 37: break; 841 } 842</pre></td></tr> 843 844 845<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('continueStmt0')"><a name="continueStmt0Anchor">continueStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ContinueStmt.html">ContinueStmt</a>>...</td></tr> 846<tr><td colspan="4" class="doc" id="continueStmt0"><pre>Matches continue statements. 847 848Given 849 while (true) { continue; } 850continueStmt() 851 matches 'continue' 852</pre></td></tr> 853 854 855<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cudaKernelCallExpr0')"><a name="cudaKernelCallExpr0Anchor">cudaKernelCallExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CUDAKernelCallExpr.html">CUDAKernelCallExpr</a>>...</td></tr> 856<tr><td colspan="4" class="doc" id="cudaKernelCallExpr0"><pre>Matches CUDA kernel call expression. 857 858Example matches, 859 kernel<<<i,j>>>(); 860</pre></td></tr> 861 862 863<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxBindTemporaryExpr0')"><a name="cxxBindTemporaryExpr0Anchor">cxxBindTemporaryExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBindTemporaryExpr.html">CXXBindTemporaryExpr</a>>...</td></tr> 864<tr><td colspan="4" class="doc" id="cxxBindTemporaryExpr0"><pre>Matches nodes where temporaries are created. 865 866Example matches FunctionTakesString(GetStringByValue()) 867 (matcher = cxxBindTemporaryExpr()) 868 FunctionTakesString(GetStringByValue()); 869 FunctionTakesStringByPointer(GetStringPointer()); 870</pre></td></tr> 871 872 873<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxBoolLiteral0')"><a name="cxxBoolLiteral0Anchor">cxxBoolLiteral</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBoolLiteralExpr.html">CXXBoolLiteralExpr</a>>...</td></tr> 874<tr><td colspan="4" class="doc" id="cxxBoolLiteral0"><pre>Matches bool literals. 875 876Example matches true 877 true 878</pre></td></tr> 879 880 881<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxCatchStmt0')"><a name="cxxCatchStmt0Anchor">cxxCatchStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCatchStmt.html">CXXCatchStmt</a>>...</td></tr> 882<tr><td colspan="4" class="doc" id="cxxCatchStmt0"><pre>Matches catch statements. 883 884 try {} catch(int i) {} 885cxxCatchStmt() 886 matches 'catch(int i)' 887</pre></td></tr> 888 889 890<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxConstCastExpr0')"><a name="cxxConstCastExpr0Anchor">cxxConstCastExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstCastExpr.html">CXXConstCastExpr</a>>...</td></tr> 891<tr><td colspan="4" class="doc" id="cxxConstCastExpr0"><pre>Matches a const_cast expression. 892 893Example: Matches const_cast<int*>(&r) in 894 int n = 42; 895 const int &r(n); 896 int* p = const_cast<int*>(&r); 897</pre></td></tr> 898 899 900<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxConstructExpr0')"><a name="cxxConstructExpr0Anchor">cxxConstructExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>...</td></tr> 901<tr><td colspan="4" class="doc" id="cxxConstructExpr0"><pre>Matches constructor call expressions (including implicit ones). 902 903Example matches string(ptr, n) and ptr within arguments of f 904 (matcher = cxxConstructExpr()) 905 void f(const string &a, const string &b); 906 char *ptr; 907 int n; 908 f(string(ptr, n), ptr); 909</pre></td></tr> 910 911 912<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxDefaultArgExpr0')"><a name="cxxDefaultArgExpr0Anchor">cxxDefaultArgExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXDefaultArgExpr.html">CXXDefaultArgExpr</a>>...</td></tr> 913<tr><td colspan="4" class="doc" id="cxxDefaultArgExpr0"><pre>Matches the value of a default argument at the call site. 914 915Example matches the CXXDefaultArgExpr placeholder inserted for the 916 default value of the second parameter in the call expression f(42) 917 (matcher = cxxDefaultArgExpr()) 918 void f(int x, int y = 0); 919 f(42); 920</pre></td></tr> 921 922 923<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxDeleteExpr0')"><a name="cxxDeleteExpr0Anchor">cxxDeleteExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXDeleteExpr.html">CXXDeleteExpr</a>>...</td></tr> 924<tr><td colspan="4" class="doc" id="cxxDeleteExpr0"><pre>Matches delete expressions. 925 926Given 927 delete X; 928cxxDeleteExpr() 929 matches 'delete X'. 930</pre></td></tr> 931 932 933<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxDependentScopeMemberExpr0')"><a name="cxxDependentScopeMemberExpr0Anchor">cxxDependentScopeMemberExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXDependentScopeMemberExpr.html">CXXDependentScopeMemberExpr</a>>...</td></tr> 934<tr><td colspan="4" class="doc" id="cxxDependentScopeMemberExpr0"><pre>Matches member expressions where the actual member referenced could not be 935resolved because the base expression or the member name was dependent. 936 937Given 938 template <class T> void f() { T t; t.g(); } 939cxxDependentScopeMemberExpr() 940 matches t.g 941</pre></td></tr> 942 943 944<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxDynamicCastExpr0')"><a name="cxxDynamicCastExpr0Anchor">cxxDynamicCastExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXDynamicCastExpr.html">CXXDynamicCastExpr</a>>...</td></tr> 945<tr><td colspan="4" class="doc" id="cxxDynamicCastExpr0"><pre>Matches a dynamic_cast expression. 946 947Example: 948 cxxDynamicCastExpr() 949matches 950 dynamic_cast<D*>(&b); 951in 952 struct B { virtual ~B() {} }; struct D : B {}; 953 B b; 954 D* p = dynamic_cast<D*>(&b); 955</pre></td></tr> 956 957 958<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxForRangeStmt0')"><a name="cxxForRangeStmt0Anchor">cxxForRangeStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXForRangeStmt.html">CXXForRangeStmt</a>>...</td></tr> 959<tr><td colspan="4" class="doc" id="cxxForRangeStmt0"><pre>Matches range-based for statements. 960 961cxxForRangeStmt() matches 'for (auto a : i)' 962 int i[] = {1, 2, 3}; for (auto a : i); 963 for(int j = 0; j < 5; ++j); 964</pre></td></tr> 965 966 967<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxFunctionalCastExpr0')"><a name="cxxFunctionalCastExpr0Anchor">cxxFunctionalCastExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXFunctionalCastExpr.html">CXXFunctionalCastExpr</a>>...</td></tr> 968<tr><td colspan="4" class="doc" id="cxxFunctionalCastExpr0"><pre>Matches functional cast expressions 969 970Example: Matches Foo(bar); 971 Foo f = bar; 972 Foo g = (Foo) bar; 973 Foo h = Foo(bar); 974</pre></td></tr> 975 976 977<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxMemberCallExpr0')"><a name="cxxMemberCallExpr0Anchor">cxxMemberCallExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMemberCallExpr.html">CXXMemberCallExpr</a>>...</td></tr> 978<tr><td colspan="4" class="doc" id="cxxMemberCallExpr0"><pre>Matches member call expressions. 979 980Example matches x.y() 981 X x; 982 x.y(); 983</pre></td></tr> 984 985 986<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxNewExpr0')"><a name="cxxNewExpr0Anchor">cxxNewExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>...</td></tr> 987<tr><td colspan="4" class="doc" id="cxxNewExpr0"><pre>Matches new expressions. 988 989Given 990 new X; 991cxxNewExpr() 992 matches 'new X'. 993</pre></td></tr> 994 995 996<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxNullPtrLiteralExpr0')"><a name="cxxNullPtrLiteralExpr0Anchor">cxxNullPtrLiteralExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNullPtrLiteralExpr.html">CXXNullPtrLiteralExpr</a>>...</td></tr> 997<tr><td colspan="4" class="doc" id="cxxNullPtrLiteralExpr0"><pre>Matches nullptr literal. 998</pre></td></tr> 999 1000 1001<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxOperatorCallExpr0')"><a name="cxxOperatorCallExpr0Anchor">cxxOperatorCallExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>>...</td></tr> 1002<tr><td colspan="4" class="doc" id="cxxOperatorCallExpr0"><pre>Matches overloaded operator calls. 1003 1004Note that if an operator isn't overloaded, it won't match. Instead, use 1005binaryOperator matcher. 1006Currently it does not match operators such as new delete. 1007FIXME: figure out why these do not match? 1008 1009Example matches both operator<<((o << b), c) and operator<<(o, b) 1010 (matcher = cxxOperatorCallExpr()) 1011 ostream &operator<< (ostream &out, int i) { }; 1012 ostream &o; int b = 1, c = 1; 1013 o << b << c; 1014</pre></td></tr> 1015 1016 1017<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxReinterpretCastExpr0')"><a name="cxxReinterpretCastExpr0Anchor">cxxReinterpretCastExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXReinterpretCastExpr.html">CXXReinterpretCastExpr</a>>...</td></tr> 1018<tr><td colspan="4" class="doc" id="cxxReinterpretCastExpr0"><pre>Matches a reinterpret_cast expression. 1019 1020Either the source expression or the destination type can be matched 1021using has(), but hasDestinationType() is more specific and can be 1022more readable. 1023 1024Example matches reinterpret_cast<char*>(&p) in 1025 void* p = reinterpret_cast<char*>(&p); 1026</pre></td></tr> 1027 1028 1029<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxStaticCastExpr0')"><a name="cxxStaticCastExpr0Anchor">cxxStaticCastExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXStaticCastExpr.html">CXXStaticCastExpr</a>>...</td></tr> 1030<tr><td colspan="4" class="doc" id="cxxStaticCastExpr0"><pre>Matches a C++ static_cast expression. 1031 1032See also: hasDestinationType 1033See also: reinterpretCast 1034 1035Example: 1036 cxxStaticCastExpr() 1037matches 1038 static_cast<long>(8) 1039in 1040 long eight(static_cast<long>(8)); 1041</pre></td></tr> 1042 1043 1044<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxStdInitializerListExpr0')"><a name="cxxStdInitializerListExpr0Anchor">cxxStdInitializerListExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXStdInitializerListExpr.html">CXXStdInitializerListExpr</a>>...</td></tr> 1045<tr><td colspan="4" class="doc" id="cxxStdInitializerListExpr0"><pre>Matches C++ initializer list expressions. 1046 1047Given 1048 std::vector<int> a({ 1, 2, 3 }); 1049 std::vector<int> b = { 4, 5 }; 1050 int c[] = { 6, 7 }; 1051 std::pair<int, int> d = { 8, 9 }; 1052cxxStdInitializerListExpr() 1053 matches "{ 1, 2, 3 }" and "{ 4, 5 }" 1054</pre></td></tr> 1055 1056 1057<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxTemporaryObjectExpr0')"><a name="cxxTemporaryObjectExpr0Anchor">cxxTemporaryObjectExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXTemporaryObjectExpr.html">CXXTemporaryObjectExpr</a>>...</td></tr> 1058<tr><td colspan="4" class="doc" id="cxxTemporaryObjectExpr0"><pre>Matches functional cast expressions having N != 1 arguments 1059 1060Example: Matches Foo(bar, bar) 1061 Foo h = Foo(bar, bar); 1062</pre></td></tr> 1063 1064 1065<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxThisExpr0')"><a name="cxxThisExpr0Anchor">cxxThisExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXThisExpr.html">CXXThisExpr</a>>...</td></tr> 1066<tr><td colspan="4" class="doc" id="cxxThisExpr0"><pre>Matches implicit and explicit this expressions. 1067 1068Example matches the implicit this expression in "return i". 1069 (matcher = cxxThisExpr()) 1070struct foo { 1071 int i; 1072 int f() { return i; } 1073}; 1074</pre></td></tr> 1075 1076 1077<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxThrowExpr0')"><a name="cxxThrowExpr0Anchor">cxxThrowExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXThrowExpr.html">CXXThrowExpr</a>>...</td></tr> 1078<tr><td colspan="4" class="doc" id="cxxThrowExpr0"><pre>Matches throw expressions. 1079 1080 try { throw 5; } catch(int i) {} 1081cxxThrowExpr() 1082 matches 'throw 5' 1083</pre></td></tr> 1084 1085 1086<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxTryStmt0')"><a name="cxxTryStmt0Anchor">cxxTryStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXTryStmt.html">CXXTryStmt</a>>...</td></tr> 1087<tr><td colspan="4" class="doc" id="cxxTryStmt0"><pre>Matches try statements. 1088 1089 try {} catch(int i) {} 1090cxxTryStmt() 1091 matches 'try {}' 1092</pre></td></tr> 1093 1094 1095<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxUnresolvedConstructExpr0')"><a name="cxxUnresolvedConstructExpr0Anchor">cxxUnresolvedConstructExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXUnresolvedConstructExpr.html">CXXUnresolvedConstructExpr</a>>...</td></tr> 1096<tr><td colspan="4" class="doc" id="cxxUnresolvedConstructExpr0"><pre>Matches unresolved constructor call expressions. 1097 1098Example matches T(t) in return statement of f 1099 (matcher = cxxUnresolvedConstructExpr()) 1100 template <typename T> 1101 void f(const T& t) { return T(t); } 1102</pre></td></tr> 1103 1104 1105<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('declRefExpr0')"><a name="declRefExpr0Anchor">declRefExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>...</td></tr> 1106<tr><td colspan="4" class="doc" id="declRefExpr0"><pre>Matches expressions that refer to declarations. 1107 1108Example matches x in if (x) 1109 bool x; 1110 if (x) {} 1111</pre></td></tr> 1112 1113 1114<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('declStmt0')"><a name="declStmt0Anchor">declStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html">DeclStmt</a>>...</td></tr> 1115<tr><td colspan="4" class="doc" id="declStmt0"><pre>Matches declaration statements. 1116 1117Given 1118 int a; 1119declStmt() 1120 matches 'int a'. 1121</pre></td></tr> 1122 1123 1124<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('defaultStmt0')"><a name="defaultStmt0Anchor">defaultStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DefaultStmt.html">DefaultStmt</a>>...</td></tr> 1125<tr><td colspan="4" class="doc" id="defaultStmt0"><pre>Matches default statements inside switch statements. 1126 1127Given 1128 switch(a) { case 42: break; default: break; } 1129defaultStmt() 1130 matches 'default:'. 1131</pre></td></tr> 1132 1133 1134<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('designatedInitExpr0')"><a name="designatedInitExpr0Anchor">designatedInitExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DesignatedInitExpr.html">DesignatedInitExpr</a>>...</td></tr> 1135<tr><td colspan="4" class="doc" id="designatedInitExpr0"><pre>Matches C99 designated initializer expressions [C99 6.7.8]. 1136 1137Example: Matches { [2].y = 1.0, [0].x = 1.0 } 1138 point ptarray[10] = { [2].y = 1.0, [0].x = 1.0 }; 1139</pre></td></tr> 1140 1141 1142<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('doStmt0')"><a name="doStmt0Anchor">doStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DoStmt.html">DoStmt</a>>...</td></tr> 1143<tr><td colspan="4" class="doc" id="doStmt0"><pre>Matches do statements. 1144 1145Given 1146 do {} while (true); 1147doStmt() 1148 matches 'do {} while(true)' 1149</pre></td></tr> 1150 1151 1152<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('explicitCastExpr0')"><a name="explicitCastExpr0Anchor">explicitCastExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ExplicitCastExpr.html">ExplicitCastExpr</a>>...</td></tr> 1153<tr><td colspan="4" class="doc" id="explicitCastExpr0"><pre>Matches explicit cast expressions. 1154 1155Matches any cast expression written in user code, whether it be a 1156C-style cast, a functional-style cast, or a keyword cast. 1157 1158Does not match implicit conversions. 1159 1160Note: the name "explicitCast" is chosen to match Clang's terminology, as 1161Clang uses the term "cast" to apply to implicit conversions as well as to 1162actual cast expressions. 1163 1164See also: hasDestinationType. 1165 1166Example: matches all five of the casts in 1167 int((int)(reinterpret_cast<int>(static_cast<int>(const_cast<int>(42))))) 1168but does not match the implicit conversion in 1169 long ell = 42; 1170</pre></td></tr> 1171 1172 1173<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('expr0')"><a name="expr0Anchor">expr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>>...</td></tr> 1174<tr><td colspan="4" class="doc" id="expr0"><pre>Matches expressions. 1175 1176Example matches x() 1177 void f() { x(); } 1178</pre></td></tr> 1179 1180 1181<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('exprWithCleanups0')"><a name="exprWithCleanups0Anchor">exprWithCleanups</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ExprWithCleanups.html">ExprWithCleanups</a>>...</td></tr> 1182<tr><td colspan="4" class="doc" id="exprWithCleanups0"><pre>Matches expressions that introduce cleanups to be run at the end 1183of the sub-expression's evaluation. 1184 1185Example matches std::string() 1186 const std::string str = std::string(); 1187</pre></td></tr> 1188 1189 1190<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('floatLiteral0')"><a name="floatLiteral0Anchor">floatLiteral</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>>...</td></tr> 1191<tr><td colspan="4" class="doc" id="floatLiteral0"><pre>Matches float literals of all sizes / encodings, e.g. 11921.0, 1.0f, 1.0L and 1e10. 1193 1194Does not match implicit conversions such as 1195 float a = 10; 1196</pre></td></tr> 1197 1198 1199<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('forStmt0')"><a name="forStmt0Anchor">forStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ForStmt.html">ForStmt</a>>...</td></tr> 1200<tr><td colspan="4" class="doc" id="forStmt0"><pre>Matches for statements. 1201 1202Example matches 'for (;;) {}' 1203 for (;;) {} 1204 int i[] = {1, 2, 3}; for (auto a : i); 1205</pre></td></tr> 1206 1207 1208<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('gnuNullExpr0')"><a name="gnuNullExpr0Anchor">gnuNullExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1GNUNullExpr.html">GNUNullExpr</a>>...</td></tr> 1209<tr><td colspan="4" class="doc" id="gnuNullExpr0"><pre>Matches GNU __null expression. 1210</pre></td></tr> 1211 1212 1213<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('gotoStmt0')"><a name="gotoStmt0Anchor">gotoStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1GotoStmt.html">GotoStmt</a>>...</td></tr> 1214<tr><td colspan="4" class="doc" id="gotoStmt0"><pre>Matches goto statements. 1215 1216Given 1217 goto FOO; 1218 FOO: bar(); 1219gotoStmt() 1220 matches 'goto FOO' 1221</pre></td></tr> 1222 1223 1224<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('ifStmt0')"><a name="ifStmt0Anchor">ifStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IfStmt.html">IfStmt</a>>...</td></tr> 1225<tr><td colspan="4" class="doc" id="ifStmt0"><pre>Matches if statements. 1226 1227Example matches 'if (x) {}' 1228 if (x) {} 1229</pre></td></tr> 1230 1231 1232<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('imaginaryLiteral0')"><a name="imaginaryLiteral0Anchor">imaginaryLiteral</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ImaginaryLiteral.html">ImaginaryLiteral</a>>...</td></tr> 1233<tr><td colspan="4" class="doc" id="imaginaryLiteral0"><pre>Matches imaginary literals, which are based on integer and floating 1234point literals e.g.: 1i, 1.0i 1235</pre></td></tr> 1236 1237 1238<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('implicitCastExpr0')"><a name="implicitCastExpr0Anchor">implicitCastExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ImplicitCastExpr.html">ImplicitCastExpr</a>>...</td></tr> 1239<tr><td colspan="4" class="doc" id="implicitCastExpr0"><pre>Matches the implicit cast nodes of Clang's AST. 1240 1241This matches many different places, including function call return value 1242eliding, as well as any type conversions. 1243</pre></td></tr> 1244 1245 1246<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('implicitValueInitExpr0')"><a name="implicitValueInitExpr0Anchor">implicitValueInitExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ImplicitValueInitExpr.html">ImplicitValueInitExpr</a>>...</td></tr> 1247<tr><td colspan="4" class="doc" id="implicitValueInitExpr0"><pre>Matches implicit initializers of init list expressions. 1248 1249Given 1250 point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 }; 1251implicitValueInitExpr() 1252 matches "[0].y" (implicitly) 1253</pre></td></tr> 1254 1255 1256<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('initListExpr0')"><a name="initListExpr0Anchor">initListExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1InitListExpr.html">InitListExpr</a>>...</td></tr> 1257<tr><td colspan="4" class="doc" id="initListExpr0"><pre>Matches init list expressions. 1258 1259Given 1260 int a[] = { 1, 2 }; 1261 struct B { int x, y; }; 1262 B b = { 5, 6 }; 1263initListExpr() 1264 matches "{ 1, 2 }" and "{ 5, 6 }" 1265</pre></td></tr> 1266 1267 1268<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('integerLiteral0')"><a name="integerLiteral0Anchor">integerLiteral</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>>...</td></tr> 1269<tr><td colspan="4" class="doc" id="integerLiteral0"><pre>Matches integer literals of all sizes / encodings, e.g. 12701, 1L, 0x1 and 1U. 1271 1272Does not match character-encoded integers such as L'a'. 1273</pre></td></tr> 1274 1275 1276<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('labelStmt0')"><a name="labelStmt0Anchor">labelStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>...</td></tr> 1277<tr><td colspan="4" class="doc" id="labelStmt0"><pre>Matches label statements. 1278 1279Given 1280 goto FOO; 1281 FOO: bar(); 1282labelStmt() 1283 matches 'FOO:' 1284</pre></td></tr> 1285 1286 1287<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('lambdaExpr0')"><a name="lambdaExpr0Anchor">lambdaExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LambdaExpr.html">LambdaExpr</a>>...</td></tr> 1288<tr><td colspan="4" class="doc" id="lambdaExpr0"><pre>Matches lambda expressions. 1289 1290Example matches [&](){return 5;} 1291 [&](){return 5;} 1292</pre></td></tr> 1293 1294 1295<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('materializeTemporaryExpr0')"><a name="materializeTemporaryExpr0Anchor">materializeTemporaryExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MaterializeTemporaryExpr.html">MaterializeTemporaryExpr</a>>...</td></tr> 1296<tr><td colspan="4" class="doc" id="materializeTemporaryExpr0"><pre>Matches nodes where temporaries are materialized. 1297 1298Example: Given 1299 struct T {void func();}; 1300 T f(); 1301 void g(T); 1302materializeTemporaryExpr() matches 'f()' in these statements 1303 T u(f()); 1304 g(f()); 1305 f().func(); 1306but does not match 1307 f(); 1308</pre></td></tr> 1309 1310 1311<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('memberExpr0')"><a name="memberExpr0Anchor">memberExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>...</td></tr> 1312<tr><td colspan="4" class="doc" id="memberExpr0"><pre>Matches member expressions. 1313 1314Given 1315 class Y { 1316 void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; } 1317 int a; static int b; 1318 }; 1319memberExpr() 1320 matches this->x, x, y.x, a, this->b 1321</pre></td></tr> 1322 1323 1324<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('nullStmt0')"><a name="nullStmt0Anchor">nullStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NullStmt.html">NullStmt</a>>...</td></tr> 1325<tr><td colspan="4" class="doc" id="nullStmt0"><pre>Matches null statements. 1326 1327 foo();; 1328nullStmt() 1329 matches the second ';' 1330</pre></td></tr> 1331 1332 1333<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('objcCatchStmt0')"><a name="objcCatchStmt0Anchor">objcCatchStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCAtCatchStmt.html">ObjCAtCatchStmt</a>>...</td></tr> 1334<tr><td colspan="4" class="doc" id="objcCatchStmt0"><pre>Matches Objective-C @catch statements. 1335 1336Example matches @catch 1337 @try {} 1338 @catch (...) {} 1339</pre></td></tr> 1340 1341 1342<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('objcFinallyStmt0')"><a name="objcFinallyStmt0Anchor">objcFinallyStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCAtFinallyStmt.html">ObjCAtFinallyStmt</a>>...</td></tr> 1343<tr><td colspan="4" class="doc" id="objcFinallyStmt0"><pre>Matches Objective-C @finally statements. 1344 1345Example matches @finally 1346 @try {} 1347 @finally {} 1348</pre></td></tr> 1349 1350 1351<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('objcIvarRefExpr0')"><a name="objcIvarRefExpr0Anchor">objcIvarRefExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCIvarRefExpr.html">ObjCIvarRefExpr</a>>...</td></tr> 1352<tr><td colspan="4" class="doc" id="objcIvarRefExpr0"><pre>Matches a reference to an ObjCIvar. 1353 1354Example: matches "a" in "init" method: 1355@implementation A { 1356 NSString *a; 1357} 1358- (void) init { 1359 a = @"hello"; 1360} 1361</pre></td></tr> 1362 1363 1364<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('objcMessageExpr0')"><a name="objcMessageExpr0Anchor">objcMessageExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>>...</td></tr> 1365<tr><td colspan="4" class="doc" id="objcMessageExpr0"><pre>Matches ObjectiveC Message invocation expressions. 1366 1367The innermost message send invokes the "alloc" class method on the 1368NSString class, while the outermost message send invokes the 1369"initWithString" instance method on the object returned from 1370NSString's "alloc". This matcher should match both message sends. 1371 [[NSString alloc] initWithString:@"Hello"] 1372</pre></td></tr> 1373 1374 1375<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('objcThrowStmt0')"><a name="objcThrowStmt0Anchor">objcThrowStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCAtThrowStmt.html">ObjCAtThrowStmt</a>>...</td></tr> 1376<tr><td colspan="4" class="doc" id="objcThrowStmt0"><pre>Matches Objective-C statements. 1377 1378Example matches @throw obj; 1379</pre></td></tr> 1380 1381 1382<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('objcTryStmt0')"><a name="objcTryStmt0Anchor">objcTryStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCAtTryStmt.html">ObjCAtTryStmt</a>>...</td></tr> 1383<tr><td colspan="4" class="doc" id="objcTryStmt0"><pre>Matches Objective-C @try statements. 1384 1385Example matches @try 1386 @try {} 1387 @catch (...) {} 1388</pre></td></tr> 1389 1390 1391<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('ompExecutableDirective0')"><a name="ompExecutableDirective0Anchor">ompExecutableDirective</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPExecutableDirective.html">OMPExecutableDirective</a>>...</td></tr> 1392<tr><td colspan="4" class="doc" id="ompExecutableDirective0"><pre>Matches any ``#pragma omp`` executable directive. 1393 1394Given 1395 1396 #pragma omp parallel 1397 #pragma omp parallel default(none) 1398 #pragma omp taskyield 1399 1400``ompExecutableDirective()`` matches ``omp parallel``, 1401``omp parallel default(none)`` and ``omp taskyield``. 1402</pre></td></tr> 1403 1404 1405<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('opaqueValueExpr0')"><a name="opaqueValueExpr0Anchor">opaqueValueExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OpaqueValueExpr.html">OpaqueValueExpr</a>>...</td></tr> 1406<tr><td colspan="4" class="doc" id="opaqueValueExpr0"><pre>Matches opaque value expressions. They are used as helpers 1407to reference another expressions and can be met 1408in BinaryConditionalOperators, for example. 1409 1410Example matches 'a' 1411 (a ?: c) + 42; 1412</pre></td></tr> 1413 1414 1415<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('parenExpr0')"><a name="parenExpr0Anchor">parenExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ParenExpr.html">ParenExpr</a>>...</td></tr> 1416<tr><td colspan="4" class="doc" id="parenExpr0"><pre>Matches parentheses used in expressions. 1417 1418Example matches (foo() + 1) 1419 int foo() { return 1; } 1420 int a = (foo() + 1); 1421</pre></td></tr> 1422 1423 1424<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('parenListExpr0')"><a name="parenListExpr0Anchor">parenListExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ParenListExpr.html">ParenListExpr</a>>...</td></tr> 1425<tr><td colspan="4" class="doc" id="parenListExpr0"><pre>Matches paren list expressions. 1426ParenListExprs don't have a predefined type and are used for late parsing. 1427In the final AST, they can be met in template declarations. 1428 1429Given 1430 template<typename T> class X { 1431 void f() { 1432 X x(*this); 1433 int a = 0, b = 1; int i = (a, b); 1434 } 1435 }; 1436parenListExpr() matches "*this" but NOT matches (a, b) because (a, b) 1437has a predefined type and is a ParenExpr, not a ParenListExpr. 1438</pre></td></tr> 1439 1440 1441<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('predefinedExpr0')"><a name="predefinedExpr0Anchor">predefinedExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1PredefinedExpr.html">PredefinedExpr</a>>...</td></tr> 1442<tr><td colspan="4" class="doc" id="predefinedExpr0"><pre>Matches predefined identifier expressions [C99 6.4.2.2]. 1443 1444Example: Matches __func__ 1445 printf("%s", __func__); 1446</pre></td></tr> 1447 1448 1449<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('returnStmt0')"><a name="returnStmt0Anchor">returnStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ReturnStmt.html">ReturnStmt</a>>...</td></tr> 1450<tr><td colspan="4" class="doc" id="returnStmt0"><pre>Matches return statements. 1451 1452Given 1453 return 1; 1454returnStmt() 1455 matches 'return 1' 1456</pre></td></tr> 1457 1458 1459<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('stmt0')"><a name="stmt0Anchor">stmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>>...</td></tr> 1460<tr><td colspan="4" class="doc" id="stmt0"><pre>Matches statements. 1461 1462Given 1463 { ++a; } 1464stmt() 1465 matches both the compound statement '{ ++a; }' and '++a'. 1466</pre></td></tr> 1467 1468 1469<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('stmtExpr0')"><a name="stmtExpr0Anchor">stmtExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1StmtExpr.html">StmtExpr</a>>...</td></tr> 1470<tr><td colspan="4" class="doc" id="stmtExpr0"><pre>Matches statement expression (GNU extension). 1471 1472Example match: ({ int X = 4; X; }) 1473 int C = ({ int X = 4; X; }); 1474</pre></td></tr> 1475 1476 1477<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('stringLiteral0')"><a name="stringLiteral0Anchor">stringLiteral</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1StringLiteral.html">StringLiteral</a>>...</td></tr> 1478<tr><td colspan="4" class="doc" id="stringLiteral0"><pre>Matches string literals (also matches wide string literals). 1479 1480Example matches "abcd", L"abcd" 1481 char *s = "abcd"; 1482 wchar_t *ws = L"abcd"; 1483</pre></td></tr> 1484 1485 1486<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('substNonTypeTemplateParmExpr0')"><a name="substNonTypeTemplateParmExpr0Anchor">substNonTypeTemplateParmExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1SubstNonTypeTemplateParmExpr.html">SubstNonTypeTemplateParmExpr</a>>...</td></tr> 1487<tr><td colspan="4" class="doc" id="substNonTypeTemplateParmExpr0"><pre>Matches substitutions of non-type template parameters. 1488 1489Given 1490 template <int N> 1491 struct A { static const int n = N; }; 1492 struct B : public A<42> {}; 1493substNonTypeTemplateParmExpr() 1494 matches "N" in the right-hand side of "static const int n = N;" 1495</pre></td></tr> 1496 1497 1498<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('switchCase0')"><a name="switchCase0Anchor">switchCase</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1SwitchCase.html">SwitchCase</a>>...</td></tr> 1499<tr><td colspan="4" class="doc" id="switchCase0"><pre>Matches case and default statements inside switch statements. 1500 1501Given 1502 switch(a) { case 42: break; default: break; } 1503switchCase() 1504 matches 'case 42:' and 'default:'. 1505</pre></td></tr> 1506 1507 1508<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('switchStmt0')"><a name="switchStmt0Anchor">switchStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1SwitchStmt.html">SwitchStmt</a>>...</td></tr> 1509<tr><td colspan="4" class="doc" id="switchStmt0"><pre>Matches switch statements. 1510 1511Given 1512 switch(a) { case 42: break; default: break; } 1513switchStmt() 1514 matches 'switch(a)'. 1515</pre></td></tr> 1516 1517 1518<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('unaryExprOrTypeTraitExpr0')"><a name="unaryExprOrTypeTraitExpr0Anchor">unaryExprOrTypeTraitExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html">UnaryExprOrTypeTraitExpr</a>>...</td></tr> 1519<tr><td colspan="4" class="doc" id="unaryExprOrTypeTraitExpr0"><pre>Matches sizeof (C99), alignof (C++11) and vec_step (OpenCL) 1520 1521Given 1522 Foo x = bar; 1523 int y = sizeof(x) + alignof(x); 1524unaryExprOrTypeTraitExpr() 1525 matches sizeof(x) and alignof(x) 1526</pre></td></tr> 1527 1528 1529<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('unaryOperator0')"><a name="unaryOperator0Anchor">unaryOperator</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnaryOperator.html">UnaryOperator</a>>...</td></tr> 1530<tr><td colspan="4" class="doc" id="unaryOperator0"><pre>Matches unary operator expressions. 1531 1532Example matches !a 1533 !a || b 1534</pre></td></tr> 1535 1536 1537<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('unresolvedLookupExpr0')"><a name="unresolvedLookupExpr0Anchor">unresolvedLookupExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedLookupExpr.html">UnresolvedLookupExpr</a>>...</td></tr> 1538<tr><td colspan="4" class="doc" id="unresolvedLookupExpr0"><pre>Matches reference to a name that can be looked up during parsing 1539but could not be resolved to a specific declaration. 1540 1541Given 1542 template<typename T> 1543 T foo() { T a; return a; } 1544 template<typename T> 1545 void bar() { 1546 foo<T>(); 1547 } 1548unresolvedLookupExpr() 1549 matches foo<T>() </pre></td></tr> 1550 1551 1552<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('unresolvedMemberExpr0')"><a name="unresolvedMemberExpr0Anchor">unresolvedMemberExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedMemberExpr.html">UnresolvedMemberExpr</a>>...</td></tr> 1553<tr><td colspan="4" class="doc" id="unresolvedMemberExpr0"><pre>Matches unresolved member expressions. 1554 1555Given 1556 struct X { 1557 template <class T> void f(); 1558 void g(); 1559 }; 1560 template <class T> void h() { X x; x.f<T>(); x.g(); } 1561unresolvedMemberExpr() 1562 matches x.f<T> 1563</pre></td></tr> 1564 1565 1566<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('userDefinedLiteral0')"><a name="userDefinedLiteral0Anchor">userDefinedLiteral</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UserDefinedLiteral.html">UserDefinedLiteral</a>>...</td></tr> 1567<tr><td colspan="4" class="doc" id="userDefinedLiteral0"><pre>Matches user defined literal operator call. 1568 1569Example match: "foo"_suffix 1570</pre></td></tr> 1571 1572 1573<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('whileStmt0')"><a name="whileStmt0Anchor">whileStmt</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1WhileStmt.html">WhileStmt</a>>...</td></tr> 1574<tr><td colspan="4" class="doc" id="whileStmt0"><pre>Matches while statements. 1575 1576Given 1577 while (true) {} 1578whileStmt() 1579 matches 'while (true) {}'. 1580</pre></td></tr> 1581 1582 1583<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>></td><td class="name" onclick="toggle('templateArgument0')"><a name="templateArgument0Anchor">templateArgument</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>>...</td></tr> 1584<tr><td colspan="4" class="doc" id="templateArgument0"><pre>Matches template arguments. 1585 1586Given 1587 template <typename T> struct C {}; 1588 C<int> c; 1589templateArgument() 1590 matches 'int' in C<int>. 1591</pre></td></tr> 1592 1593 1594<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateName.html">TemplateName</a>></td><td class="name" onclick="toggle('templateName0')"><a name="templateName0Anchor">templateName</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateName.html">TemplateName</a>>...</td></tr> 1595<tr><td colspan="4" class="doc" id="templateName0"><pre>Matches template name. 1596 1597Given 1598 template <typename T> class X { }; 1599 X<int> xi; 1600templateName() 1601 matches 'X' in X<int>. 1602</pre></td></tr> 1603 1604 1605<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td><td class="name" onclick="toggle('typeLoc0')"><a name="typeLoc0Anchor">typeLoc</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>>...</td></tr> 1606<tr><td colspan="4" class="doc" id="typeLoc0"><pre>Matches TypeLocs in the clang AST. 1607</pre></td></tr> 1608 1609 1610<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('arrayType0')"><a name="arrayType0Anchor">arrayType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ArrayType.html">ArrayType</a>>...</td></tr> 1611<tr><td colspan="4" class="doc" id="arrayType0"><pre>Matches all kinds of arrays. 1612 1613Given 1614 int a[] = { 2, 3 }; 1615 int b[4]; 1616 void f() { int c[a[0]]; } 1617arrayType() 1618 matches "int a[]", "int b[4]" and "int c[a[0]]"; 1619</pre></td></tr> 1620 1621 1622<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('atomicType0')"><a name="atomicType0Anchor">atomicType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AtomicType.html">AtomicType</a>>...</td></tr> 1623<tr><td colspan="4" class="doc" id="atomicType0"><pre>Matches atomic types. 1624 1625Given 1626 _Atomic(int) i; 1627atomicType() 1628 matches "_Atomic(int) i" 1629</pre></td></tr> 1630 1631 1632<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('autoType0')"><a name="autoType0Anchor">autoType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AutoType.html">AutoType</a>>...</td></tr> 1633<tr><td colspan="4" class="doc" id="autoType0"><pre>Matches types nodes representing C++11 auto types. 1634 1635Given: 1636 auto n = 4; 1637 int v[] = { 2, 3 } 1638 for (auto i : v) { } 1639autoType() 1640 matches "auto n" and "auto i" 1641</pre></td></tr> 1642 1643 1644<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('blockPointerType0')"><a name="blockPointerType0Anchor">blockPointerType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BlockPointerType.html">BlockPointerType</a>>...</td></tr> 1645<tr><td colspan="4" class="doc" id="blockPointerType0"><pre>Matches block pointer types, i.e. types syntactically represented as 1646"void (^)(int)". 1647 1648The pointee is always required to be a FunctionType. 1649</pre></td></tr> 1650 1651 1652<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('builtinType0')"><a name="builtinType0Anchor">builtinType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BuiltinType.html">BuiltinType</a>>...</td></tr> 1653<tr><td colspan="4" class="doc" id="builtinType0"><pre>Matches builtin Types. 1654 1655Given 1656 struct A {}; 1657 A a; 1658 int b; 1659 float c; 1660 bool d; 1661builtinType() 1662 matches "int b", "float c" and "bool d" 1663</pre></td></tr> 1664 1665 1666<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('complexType0')"><a name="complexType0Anchor">complexType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ComplexType.html">ComplexType</a>>...</td></tr> 1667<tr><td colspan="4" class="doc" id="complexType0"><pre>Matches C99 complex types. 1668 1669Given 1670 _Complex float f; 1671complexType() 1672 matches "_Complex float f" 1673</pre></td></tr> 1674 1675 1676<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('constantArrayType0')"><a name="constantArrayType0Anchor">constantArrayType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ConstantArrayType.html">ConstantArrayType</a>>...</td></tr> 1677<tr><td colspan="4" class="doc" id="constantArrayType0"><pre>Matches C arrays with a specified constant size. 1678 1679Given 1680 void() { 1681 int a[2]; 1682 int b[] = { 2, 3 }; 1683 int c[b[0]]; 1684 } 1685constantArrayType() 1686 matches "int a[2]" 1687</pre></td></tr> 1688 1689 1690<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('decayedType0')"><a name="decayedType0Anchor">decayedType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DecayedType.html">DecayedType</a>>...</td></tr> 1691<tr><td colspan="4" class="doc" id="decayedType0"><pre>Matches decayed type 1692Example matches i[] in declaration of f. 1693 (matcher = valueDecl(hasType(decayedType(hasDecayedType(pointerType()))))) 1694Example matches i[1]. 1695 (matcher = expr(hasType(decayedType(hasDecayedType(pointerType()))))) 1696 void f(int i[]) { 1697 i[1] = 0; 1698 } 1699</pre></td></tr> 1700 1701 1702<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('decltypeType0')"><a name="decltypeType0Anchor">decltypeType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DecltypeType.html">DecltypeType</a>>...</td></tr> 1703<tr><td colspan="4" class="doc" id="decltypeType0"><pre>Matches types nodes representing C++11 decltype(<expr>) types. 1704 1705Given: 1706 short i = 1; 1707 int j = 42; 1708 decltype(i + j) result = i + j; 1709decltypeType() 1710 matches "decltype(i + j)" 1711</pre></td></tr> 1712 1713 1714<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('dependentSizedArrayType0')"><a name="dependentSizedArrayType0Anchor">dependentSizedArrayType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DependentSizedArrayType.html">DependentSizedArrayType</a>>...</td></tr> 1715<tr><td colspan="4" class="doc" id="dependentSizedArrayType0"><pre>Matches C++ arrays whose size is a value-dependent expression. 1716 1717Given 1718 template<typename T, int Size> 1719 class array { 1720 T data[Size]; 1721 }; 1722dependentSizedArrayType 1723 matches "T data[Size]" 1724</pre></td></tr> 1725 1726 1727<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('elaboratedType0')"><a name="elaboratedType0Anchor">elaboratedType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ElaboratedType.html">ElaboratedType</a>>...</td></tr> 1728<tr><td colspan="4" class="doc" id="elaboratedType0"><pre>Matches types specified with an elaborated type keyword or with a 1729qualified name. 1730 1731Given 1732 namespace N { 1733 namespace M { 1734 class D {}; 1735 } 1736 } 1737 class C {}; 1738 1739 class C c; 1740 N::M::D d; 1741 1742elaboratedType() matches the type of the variable declarations of both 1743c and d. 1744</pre></td></tr> 1745 1746 1747<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('enumType0')"><a name="enumType0Anchor">enumType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>...</td></tr> 1748<tr><td colspan="4" class="doc" id="enumType0"><pre>Matches enum types. 1749 1750Given 1751 enum C { Green }; 1752 enum class S { Red }; 1753 1754 C c; 1755 S s; 1756 1757enumType() matches the type of the variable declarations of both c and 1758s. 1759</pre></td></tr> 1760 1761 1762<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('functionProtoType0')"><a name="functionProtoType0Anchor">functionProtoType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionProtoType.html">FunctionProtoType</a>>...</td></tr> 1763<tr><td colspan="4" class="doc" id="functionProtoType0"><pre>Matches FunctionProtoType nodes. 1764 1765Given 1766 int (*f)(int); 1767 void g(); 1768functionProtoType() 1769 matches "int (*f)(int)" and the type of "g" in C++ mode. 1770 In C mode, "g" is not matched because it does not contain a prototype. 1771</pre></td></tr> 1772 1773 1774<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('functionType0')"><a name="functionType0Anchor">functionType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionType.html">FunctionType</a>>...</td></tr> 1775<tr><td colspan="4" class="doc" id="functionType0"><pre>Matches FunctionType nodes. 1776 1777Given 1778 int (*f)(int); 1779 void g(); 1780functionType() 1781 matches "int (*f)(int)" and the type of "g". 1782</pre></td></tr> 1783 1784 1785<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('incompleteArrayType0')"><a name="incompleteArrayType0Anchor">incompleteArrayType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IncompleteArrayType.html">IncompleteArrayType</a>>...</td></tr> 1786<tr><td colspan="4" class="doc" id="incompleteArrayType0"><pre>Matches C arrays with unspecified size. 1787 1788Given 1789 int a[] = { 2, 3 }; 1790 int b[42]; 1791 void f(int c[]) { int d[a[0]]; }; 1792incompleteArrayType() 1793 matches "int a[]" and "int c[]" 1794</pre></td></tr> 1795 1796 1797<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('injectedClassNameType0')"><a name="injectedClassNameType0Anchor">injectedClassNameType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>...</td></tr> 1798<tr><td colspan="4" class="doc" id="injectedClassNameType0"><pre>Matches injected class name types. 1799 1800Example matches S s, but not S<T> s. 1801 (matcher = parmVarDecl(hasType(injectedClassNameType()))) 1802 template <typename T> struct S { 1803 void f(S s); 1804 void g(S<T> s); 1805 }; 1806</pre></td></tr> 1807 1808 1809<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('lValueReferenceType0')"><a name="lValueReferenceType0Anchor">lValueReferenceType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LValueReferenceType.html">LValueReferenceType</a>>...</td></tr> 1810<tr><td colspan="4" class="doc" id="lValueReferenceType0"><pre>Matches lvalue reference types. 1811 1812Given: 1813 int *a; 1814 int &b = *a; 1815 int &&c = 1; 1816 auto &d = b; 1817 auto &&e = c; 1818 auto &&f = 2; 1819 int g = 5; 1820 1821lValueReferenceType() matches the types of b, d, and e. e is 1822matched since the type is deduced as int& by reference collapsing rules. 1823</pre></td></tr> 1824 1825 1826<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('memberPointerType0')"><a name="memberPointerType0Anchor">memberPointerType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberPointerType.html">MemberPointerType</a>>...</td></tr> 1827<tr><td colspan="4" class="doc" id="memberPointerType0"><pre>Matches member pointer types. 1828Given 1829 struct A { int i; } 1830 A::* ptr = A::i; 1831memberPointerType() 1832 matches "A::* ptr" 1833</pre></td></tr> 1834 1835 1836<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('objcObjectPointerType0')"><a name="objcObjectPointerType0Anchor">objcObjectPointerType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCObjectPointerType.html">ObjCObjectPointerType</a>>...</td></tr> 1837<tr><td colspan="4" class="doc" id="objcObjectPointerType0"><pre>Matches an Objective-C object pointer type, which is different from 1838a pointer type, despite being syntactically similar. 1839 1840Given 1841 int *a; 1842 1843 @interface Foo 1844 @end 1845 Foo *f; 1846pointerType() 1847 matches "Foo *f", but does not match "int *a". 1848</pre></td></tr> 1849 1850 1851<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('parenType0')"><a name="parenType0Anchor">parenType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ParenType.html">ParenType</a>>...</td></tr> 1852<tr><td colspan="4" class="doc" id="parenType0"><pre>Matches ParenType nodes. 1853 1854Given 1855 int (*ptr_to_array)[4]; 1856 int *array_of_ptrs[4]; 1857 1858varDecl(hasType(pointsTo(parenType()))) matches ptr_to_array but not 1859array_of_ptrs. 1860</pre></td></tr> 1861 1862 1863<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('pointerType0')"><a name="pointerType0Anchor">pointerType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1PointerType.html">PointerType</a>>...</td></tr> 1864<tr><td colspan="4" class="doc" id="pointerType0"><pre>Matches pointer types, but does not match Objective-C object pointer 1865types. 1866 1867Given 1868 int *a; 1869 int &b = *a; 1870 int c = 5; 1871 1872 @interface Foo 1873 @end 1874 Foo *f; 1875pointerType() 1876 matches "int *a", but does not match "Foo *f". 1877</pre></td></tr> 1878 1879 1880<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('rValueReferenceType0')"><a name="rValueReferenceType0Anchor">rValueReferenceType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1RValueReferenceType.html">RValueReferenceType</a>>...</td></tr> 1881<tr><td colspan="4" class="doc" id="rValueReferenceType0"><pre>Matches rvalue reference types. 1882 1883Given: 1884 int *a; 1885 int &b = *a; 1886 int &&c = 1; 1887 auto &d = b; 1888 auto &&e = c; 1889 auto &&f = 2; 1890 int g = 5; 1891 1892rValueReferenceType() matches the types of c and f. e is not 1893matched as it is deduced to int& by reference collapsing rules. 1894</pre></td></tr> 1895 1896 1897<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('recordType0')"><a name="recordType0Anchor">recordType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>...</td></tr> 1898<tr><td colspan="4" class="doc" id="recordType0"><pre>Matches record types (e.g. structs, classes). 1899 1900Given 1901 class C {}; 1902 struct S {}; 1903 1904 C c; 1905 S s; 1906 1907recordType() matches the type of the variable declarations of both c 1908and s. 1909</pre></td></tr> 1910 1911 1912<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('referenceType0')"><a name="referenceType0Anchor">referenceType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ReferenceType.html">ReferenceType</a>>...</td></tr> 1913<tr><td colspan="4" class="doc" id="referenceType0"><pre>Matches both lvalue and rvalue reference types. 1914 1915Given 1916 int *a; 1917 int &b = *a; 1918 int &&c = 1; 1919 auto &d = b; 1920 auto &&e = c; 1921 auto &&f = 2; 1922 int g = 5; 1923 1924referenceType() matches the types of b, c, d, e, and f. 1925</pre></td></tr> 1926 1927 1928<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('substTemplateTypeParmType0')"><a name="substTemplateTypeParmType0Anchor">substTemplateTypeParmType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1SubstTemplateTypeParmType.html">SubstTemplateTypeParmType</a>>...</td></tr> 1929<tr><td colspan="4" class="doc" id="substTemplateTypeParmType0"><pre>Matches types that represent the result of substituting a type for a 1930template type parameter. 1931 1932Given 1933 template <typename T> 1934 void F(T t) { 1935 int i = 1 + t; 1936 } 1937 1938substTemplateTypeParmType() matches the type of 't' but not '1' 1939</pre></td></tr> 1940 1941 1942<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('tagType0')"><a name="tagType0Anchor">tagType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>...</td></tr> 1943<tr><td colspan="4" class="doc" id="tagType0"><pre>Matches tag types (record and enum types). 1944 1945Given 1946 enum E {}; 1947 class C {}; 1948 1949 E e; 1950 C c; 1951 1952tagType() matches the type of the variable declarations of both e 1953and c. 1954</pre></td></tr> 1955 1956 1957<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('templateSpecializationType0')"><a name="templateSpecializationType0Anchor">templateSpecializationType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>...</td></tr> 1958<tr><td colspan="4" class="doc" id="templateSpecializationType0"><pre>Matches template specialization types. 1959 1960Given 1961 template <typename T> 1962 class C { }; 1963 1964 template class C<int>; // A 1965 C<char> var; // B 1966 1967templateSpecializationType() matches the type of the explicit 1968instantiation in A and the type of the variable declaration in B. 1969</pre></td></tr> 1970 1971 1972<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('templateTypeParmType0')"><a name="templateTypeParmType0Anchor">templateTypeParmType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>...</td></tr> 1973<tr><td colspan="4" class="doc" id="templateTypeParmType0"><pre>Matches template type parameter types. 1974 1975Example matches T, but not int. 1976 (matcher = templateTypeParmType()) 1977 template <typename T> void f(int i); 1978</pre></td></tr> 1979 1980 1981<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('type0')"><a name="type0Anchor">type</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>>...</td></tr> 1982<tr><td colspan="4" class="doc" id="type0"><pre>Matches Types in the clang AST. 1983</pre></td></tr> 1984 1985 1986<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('typedefType0')"><a name="typedefType0Anchor">typedefType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>...</td></tr> 1987<tr><td colspan="4" class="doc" id="typedefType0"><pre>Matches typedef types. 1988 1989Given 1990 typedef int X; 1991typedefType() 1992 matches "typedef int X" 1993</pre></td></tr> 1994 1995 1996<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('unaryTransformType0')"><a name="unaryTransformType0Anchor">unaryTransformType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnaryTransformType.html">UnaryTransformType</a>>...</td></tr> 1997<tr><td colspan="4" class="doc" id="unaryTransformType0"><pre>Matches types nodes representing unary type transformations. 1998 1999Given: 2000 typedef __underlying_type(T) type; 2001unaryTransformType() 2002 matches "__underlying_type(T)" 2003</pre></td></tr> 2004 2005 2006<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('variableArrayType0')"><a name="variableArrayType0Anchor">variableArrayType</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VariableArrayType.html">VariableArrayType</a>>...</td></tr> 2007<tr><td colspan="4" class="doc" id="variableArrayType0"><pre>Matches C arrays with a specified size that is not an 2008integer-constant-expression. 2009 2010Given 2011 void f() { 2012 int a[] = { 2, 3 } 2013 int b[42]; 2014 int c[a[0]]; 2015 } 2016variableArrayType() 2017 matches "int c[a[0]]" 2018</pre></td></tr> 2019 2020<!--END_DECL_MATCHERS --> 2021</table> 2022 2023<!-- ======================================================================= --> 2024<h2 id="narrowing-matchers">Narrowing Matchers</h2> 2025<!-- ======================================================================= --> 2026 2027<p>Narrowing matchers match certain attributes on the current node, thus 2028narrowing down the set of nodes of the current type to match on.</p> 2029 2030<p>There are special logical narrowing matchers (allOf, anyOf, anything and unless) 2031which allow users to create more powerful match expressions.</p> 2032 2033<table> 2034<tr style="text-align:left"><th>Return type</th><th>Name</th><th>Parameters</th></tr> 2035<!-- START_NARROWING_MATCHERS --> 2036 2037<tr><td>Matcher<*></td><td class="name" onclick="toggle('allOf0')"><a name="allOf0Anchor">allOf</a></td><td>Matcher<*>, ..., Matcher<*></td></tr> 2038<tr><td colspan="4" class="doc" id="allOf0"><pre>Matches if all given matchers match. 2039 2040Usable as: Any Matcher 2041</pre></td></tr> 2042 2043 2044<tr><td>Matcher<*></td><td class="name" onclick="toggle('anyOf0')"><a name="anyOf0Anchor">anyOf</a></td><td>Matcher<*>, ..., Matcher<*></td></tr> 2045<tr><td colspan="4" class="doc" id="anyOf0"><pre>Matches if any of the given matchers matches. 2046 2047Usable as: Any Matcher 2048</pre></td></tr> 2049 2050 2051<tr><td>Matcher<*></td><td class="name" onclick="toggle('anything0')"><a name="anything0Anchor">anything</a></td><td></td></tr> 2052<tr><td colspan="4" class="doc" id="anything0"><pre>Matches any node. 2053 2054Useful when another matcher requires a child matcher, but there's no 2055additional constraint. This will often be used with an explicit conversion 2056to an internal::Matcher<> type such as TypeMatcher. 2057 2058Example: DeclarationMatcher(anything()) matches all declarations, e.g., 2059"int* p" and "void f()" in 2060 int* p; 2061 void f(); 2062 2063Usable as: Any Matcher 2064</pre></td></tr> 2065 2066 2067<tr><td>Matcher<*></td><td class="name" onclick="toggle('unless0')"><a name="unless0Anchor">unless</a></td><td>Matcher<*></td></tr> 2068<tr><td colspan="4" class="doc" id="unless0"><pre>Matches if the provided matcher does not match. 2069 2070Example matches Y (matcher = cxxRecordDecl(unless(hasName("X")))) 2071 class X {}; 2072 class Y {}; 2073 2074Usable as: Any Matcher 2075</pre></td></tr> 2076 2077 2078<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html">BinaryOperator</a>></td><td class="name" onclick="toggle('hasOperatorName0')"><a name="hasOperatorName0Anchor">hasOperatorName</a></td><td>std::string Name</td></tr> 2079<tr><td colspan="4" class="doc" id="hasOperatorName0"><pre>Matches the operator Name of operator expressions (binary or 2080unary). 2081 2082Example matches a || b (matcher = binaryOperator(hasOperatorName("||"))) 2083 !(a || b) 2084</pre></td></tr> 2085 2086 2087<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html">BinaryOperator</a>></td><td class="name" onclick="toggle('isAssignmentOperator0')"><a name="isAssignmentOperator0Anchor">isAssignmentOperator</a></td><td></td></tr> 2088<tr><td colspan="4" class="doc" id="isAssignmentOperator0"><pre>Matches all kinds of assignment operators. 2089 2090Example 1: matches a += b (matcher = binaryOperator(isAssignmentOperator())) 2091 if (a == b) 2092 a += b; 2093 2094Example 2: matches s1 = s2 2095 (matcher = cxxOperatorCallExpr(isAssignmentOperator())) 2096 struct S { S& operator=(const S&); }; 2097 void x() { S s1, s2; s1 = s2; }) 2098</pre></td></tr> 2099 2100 2101<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBoolLiteralExpr.html">CXXBoolLiteralExpr</a>></td><td class="name" onclick="toggle('equals5')"><a name="equals5Anchor">equals</a></td><td>bool Value</td></tr> 2102<tr><td colspan="4" class="doc" id="equals5"><pre></pre></td></tr> 2103 2104 2105<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBoolLiteralExpr.html">CXXBoolLiteralExpr</a>></td><td class="name" onclick="toggle('equals2')"><a name="equals2Anchor">equals</a></td><td>const ValueT Value</td></tr> 2106<tr><td colspan="4" class="doc" id="equals2"><pre>Matches literals that are equal to the given value of type ValueT. 2107 2108Given 2109 f('false, 3.14, 42); 2110characterLiteral(equals(0)) 2111 matches 'cxxBoolLiteral(equals(false)) and cxxBoolLiteral(equals(0)) 2112 match false 2113floatLiteral(equals(3.14)) and floatLiteral(equals(314e-2)) 2114 match 3.14 2115integerLiteral(equals(42)) 2116 matches 42 2117 2118Note that you cannot directly match a negative numeric literal because the 2119minus sign is not part of the literal: It is a unary operator whose operand 2120is the positive numeric literal. Instead, you must use a unaryOperator() 2121matcher to match the minus sign: 2122 2123unaryOperator(hasOperatorName("-"), 2124 hasUnaryOperand(integerLiteral(equals(13)))) 2125 2126Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBoolLiteralExpr.html">CXXBoolLiteralExpr</a>>, 2127 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>> 2128</pre></td></tr> 2129 2130 2131<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBoolLiteralExpr.html">CXXBoolLiteralExpr</a>></td><td class="name" onclick="toggle('equals11')"><a name="equals11Anchor">equals</a></td><td>double Value</td></tr> 2132<tr><td colspan="4" class="doc" id="equals11"><pre></pre></td></tr> 2133 2134 2135<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBoolLiteralExpr.html">CXXBoolLiteralExpr</a>></td><td class="name" onclick="toggle('equals8')"><a name="equals8Anchor">equals</a></td><td>unsigned Value</td></tr> 2136<tr><td colspan="4" class="doc" id="equals8"><pre></pre></td></tr> 2137 2138 2139<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCatchStmt.html">CXXCatchStmt</a>></td><td class="name" onclick="toggle('isCatchAll0')"><a name="isCatchAll0Anchor">isCatchAll</a></td><td></td></tr> 2140<tr><td colspan="4" class="doc" id="isCatchAll0"><pre>Matches a C++ catch statement that has a catch-all handler. 2141 2142Given 2143 try { 2144 // ... 2145 } catch (int) { 2146 // ... 2147 } catch (...) { 2148 // ... 2149 } 2150cxxCatchStmt(isCatchAll()) matches catch(...) but not catch(int). 2151</pre></td></tr> 2152 2153 2154<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>></td><td class="name" onclick="toggle('argumentCountIs1')"><a name="argumentCountIs1Anchor">argumentCountIs</a></td><td>unsigned N</td></tr> 2155<tr><td colspan="4" class="doc" id="argumentCountIs1"><pre>Checks that a call expression or a constructor call expression has 2156a specific number of arguments (including absent default arguments). 2157 2158Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2))) 2159 void f(int x, int y); 2160 f(0, 0); 2161</pre></td></tr> 2162 2163 2164<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>></td><td class="name" onclick="toggle('isListInitialization0')"><a name="isListInitialization0Anchor">isListInitialization</a></td><td></td></tr> 2165<tr><td colspan="4" class="doc" id="isListInitialization0"><pre>Matches a constructor call expression which uses list initialization. 2166</pre></td></tr> 2167 2168 2169<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>></td><td class="name" onclick="toggle('requiresZeroInitialization0')"><a name="requiresZeroInitialization0Anchor">requiresZeroInitialization</a></td><td></td></tr> 2170<tr><td colspan="4" class="doc" id="requiresZeroInitialization0"><pre>Matches a constructor call expression which requires 2171zero initialization. 2172 2173Given 2174void foo() { 2175 struct point { double x; double y; }; 2176 point pt[2] = { { 1.0, 2.0 } }; 2177} 2178initListExpr(has(cxxConstructExpr(requiresZeroInitialization())) 2179will match the implicit array filler for pt[1]. 2180</pre></td></tr> 2181 2182 2183<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html">CXXConstructorDecl</a>></td><td class="name" onclick="toggle('isCopyConstructor0')"><a name="isCopyConstructor0Anchor">isCopyConstructor</a></td><td></td></tr> 2184<tr><td colspan="4" class="doc" id="isCopyConstructor0"><pre>Matches constructor declarations that are copy constructors. 2185 2186Given 2187 struct S { 2188 S(); // #1 2189 S(const S &); // #2 2190 S(S &&); // #3 2191 }; 2192cxxConstructorDecl(isCopyConstructor()) will match #2, but not #1 or #3. 2193</pre></td></tr> 2194 2195 2196<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html">CXXConstructorDecl</a>></td><td class="name" onclick="toggle('isDefaultConstructor0')"><a name="isDefaultConstructor0Anchor">isDefaultConstructor</a></td><td></td></tr> 2197<tr><td colspan="4" class="doc" id="isDefaultConstructor0"><pre>Matches constructor declarations that are default constructors. 2198 2199Given 2200 struct S { 2201 S(); // #1 2202 S(const S &); // #2 2203 S(S &&); // #3 2204 }; 2205cxxConstructorDecl(isDefaultConstructor()) will match #1, but not #2 or #3. 2206</pre></td></tr> 2207 2208 2209<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html">CXXConstructorDecl</a>></td><td class="name" onclick="toggle('isDelegatingConstructor0')"><a name="isDelegatingConstructor0Anchor">isDelegatingConstructor</a></td><td></td></tr> 2210<tr><td colspan="4" class="doc" id="isDelegatingConstructor0"><pre>Matches constructors that delegate to another constructor. 2211 2212Given 2213 struct S { 2214 S(); // #1 2215 S(int) {} // #2 2216 S(S &&) : S() {} // #3 2217 }; 2218 S::S() : S(0) {} // #4 2219cxxConstructorDecl(isDelegatingConstructor()) will match #3 and #4, but not 2220#1 or #2. 2221</pre></td></tr> 2222 2223 2224<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html">CXXConstructorDecl</a>></td><td class="name" onclick="toggle('isExplicit0')"><a name="isExplicit0Anchor">isExplicit</a></td><td></td></tr> 2225<tr><td colspan="4" class="doc" id="isExplicit0"><pre>Matches constructor and conversion declarations that are marked with 2226the explicit keyword. 2227 2228Given 2229 struct S { 2230 S(int); // #1 2231 explicit S(double); // #2 2232 operator int(); // #3 2233 explicit operator bool(); // #4 2234 }; 2235cxxConstructorDecl(isExplicit()) will match #2, but not #1. 2236cxxConversionDecl(isExplicit()) will match #4, but not #3. 2237</pre></td></tr> 2238 2239 2240<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html">CXXConstructorDecl</a>></td><td class="name" onclick="toggle('isMoveConstructor0')"><a name="isMoveConstructor0Anchor">isMoveConstructor</a></td><td></td></tr> 2241<tr><td colspan="4" class="doc" id="isMoveConstructor0"><pre>Matches constructor declarations that are move constructors. 2242 2243Given 2244 struct S { 2245 S(); // #1 2246 S(const S &); // #2 2247 S(S &&); // #3 2248 }; 2249cxxConstructorDecl(isMoveConstructor()) will match #3, but not #1 or #2. 2250</pre></td></tr> 2251 2252 2253<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConversionDecl.html">CXXConversionDecl</a>></td><td class="name" onclick="toggle('isExplicit1')"><a name="isExplicit1Anchor">isExplicit</a></td><td></td></tr> 2254<tr><td colspan="4" class="doc" id="isExplicit1"><pre>Matches constructor and conversion declarations that are marked with 2255the explicit keyword. 2256 2257Given 2258 struct S { 2259 S(int); // #1 2260 explicit S(double); // #2 2261 operator int(); // #3 2262 explicit operator bool(); // #4 2263 }; 2264cxxConstructorDecl(isExplicit()) will match #2, but not #1. 2265cxxConversionDecl(isExplicit()) will match #4, but not #3. 2266</pre></td></tr> 2267 2268 2269<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>></td><td class="name" onclick="toggle('isBaseInitializer0')"><a name="isBaseInitializer0Anchor">isBaseInitializer</a></td><td></td></tr> 2270<tr><td colspan="4" class="doc" id="isBaseInitializer0"><pre>Matches a constructor initializer if it is initializing a base, as 2271opposed to a member. 2272 2273Given 2274 struct B {}; 2275 struct D : B { 2276 int I; 2277 D(int i) : I(i) {} 2278 }; 2279 struct E : B { 2280 E() : B() {} 2281 }; 2282cxxConstructorDecl(hasAnyConstructorInitializer(isBaseInitializer())) 2283 will match E(), but not match D(int). 2284</pre></td></tr> 2285 2286 2287<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>></td><td class="name" onclick="toggle('isMemberInitializer0')"><a name="isMemberInitializer0Anchor">isMemberInitializer</a></td><td></td></tr> 2288<tr><td colspan="4" class="doc" id="isMemberInitializer0"><pre>Matches a constructor initializer if it is initializing a member, as 2289opposed to a base. 2290 2291Given 2292 struct B {}; 2293 struct D : B { 2294 int I; 2295 D(int i) : I(i) {} 2296 }; 2297 struct E : B { 2298 E() : B() {} 2299 }; 2300cxxConstructorDecl(hasAnyConstructorInitializer(isMemberInitializer())) 2301 will match D(int), but not match E(). 2302</pre></td></tr> 2303 2304 2305<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>></td><td class="name" onclick="toggle('isWritten0')"><a name="isWritten0Anchor">isWritten</a></td><td></td></tr> 2306<tr><td colspan="4" class="doc" id="isWritten0"><pre>Matches a constructor initializer if it is explicitly written in 2307code (as opposed to implicitly added by the compiler). 2308 2309Given 2310 struct Foo { 2311 Foo() { } 2312 Foo(int) : foo_("A") { } 2313 string foo_; 2314 }; 2315cxxConstructorDecl(hasAnyConstructorInitializer(isWritten())) 2316 will match Foo(int), but not Foo() 2317</pre></td></tr> 2318 2319 2320<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXDependentScopeMemberExpr.html">CXXDependentScopeMemberExpr</a>></td><td class="name" onclick="toggle('isArrow2')"><a name="isArrow2Anchor">isArrow</a></td><td></td></tr> 2321<tr><td colspan="4" class="doc" id="isArrow2"><pre>Matches member expressions that are called with '->' as opposed 2322to '.'. 2323 2324Member calls on the implicit this pointer match as called with '->'. 2325 2326Given 2327 class Y { 2328 void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; } 2329 template <class T> void f() { this->f<T>(); f<T>(); } 2330 int a; 2331 static int b; 2332 }; 2333 template <class T> 2334 class Z { 2335 void x() { this->m; } 2336 }; 2337memberExpr(isArrow()) 2338 matches this->x, x, y.x, a, this->b 2339cxxDependentScopeMemberExpr(isArrow()) 2340 matches this->m 2341unresolvedMemberExpr(isArrow()) 2342 matches this->f<T>, f<T> 2343</pre></td></tr> 2344 2345 2346<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('isConst0')"><a name="isConst0Anchor">isConst</a></td><td></td></tr> 2347<tr><td colspan="4" class="doc" id="isConst0"><pre>Matches if the given method declaration is const. 2348 2349Given 2350struct A { 2351 void foo() const; 2352 void bar(); 2353}; 2354 2355cxxMethodDecl(isConst()) matches A::foo() but not A::bar() 2356</pre></td></tr> 2357 2358 2359<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('isCopyAssignmentOperator0')"><a name="isCopyAssignmentOperator0Anchor">isCopyAssignmentOperator</a></td><td></td></tr> 2360<tr><td colspan="4" class="doc" id="isCopyAssignmentOperator0"><pre>Matches if the given method declaration declares a copy assignment 2361operator. 2362 2363Given 2364struct A { 2365 A &operator=(const A &); 2366 A &operator=(A &&); 2367}; 2368 2369cxxMethodDecl(isCopyAssignmentOperator()) matches the first method but not 2370the second one. 2371</pre></td></tr> 2372 2373 2374<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('isFinal1')"><a name="isFinal1Anchor">isFinal</a></td><td></td></tr> 2375<tr><td colspan="4" class="doc" id="isFinal1"><pre>Matches if the given method or class declaration is final. 2376 2377Given: 2378 class A final {}; 2379 2380 struct B { 2381 virtual void f(); 2382 }; 2383 2384 struct C : B { 2385 void f() final; 2386 }; 2387matches A and C::f, but not B, C, or B::f 2388</pre></td></tr> 2389 2390 2391<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('isMoveAssignmentOperator0')"><a name="isMoveAssignmentOperator0Anchor">isMoveAssignmentOperator</a></td><td></td></tr> 2392<tr><td colspan="4" class="doc" id="isMoveAssignmentOperator0"><pre>Matches if the given method declaration declares a move assignment 2393operator. 2394 2395Given 2396struct A { 2397 A &operator=(const A &); 2398 A &operator=(A &&); 2399}; 2400 2401cxxMethodDecl(isMoveAssignmentOperator()) matches the second method but not 2402the first one. 2403</pre></td></tr> 2404 2405 2406<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('isOverride0')"><a name="isOverride0Anchor">isOverride</a></td><td></td></tr> 2407<tr><td colspan="4" class="doc" id="isOverride0"><pre>Matches if the given method declaration overrides another method. 2408 2409Given 2410 class A { 2411 public: 2412 virtual void x(); 2413 }; 2414 class B : public A { 2415 public: 2416 virtual void x(); 2417 }; 2418 matches B::x 2419</pre></td></tr> 2420 2421 2422<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('isPure0')"><a name="isPure0Anchor">isPure</a></td><td></td></tr> 2423<tr><td colspan="4" class="doc" id="isPure0"><pre>Matches if the given method declaration is pure. 2424 2425Given 2426 class A { 2427 public: 2428 virtual void x() = 0; 2429 }; 2430 matches A::x 2431</pre></td></tr> 2432 2433 2434<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('isUserProvided0')"><a name="isUserProvided0Anchor">isUserProvided</a></td><td></td></tr> 2435<tr><td colspan="4" class="doc" id="isUserProvided0"><pre>Matches method declarations that are user-provided. 2436 2437Given 2438 struct S { 2439 S(); // #1 2440 S(const S &) = default; // #2 2441 S(S &&) = delete; // #3 2442 }; 2443cxxConstructorDecl(isUserProvided()) will match #1, but not #2 or #3. 2444</pre></td></tr> 2445 2446 2447<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('isVirtual0')"><a name="isVirtual0Anchor">isVirtual</a></td><td></td></tr> 2448<tr><td colspan="4" class="doc" id="isVirtual0"><pre>Matches if the given method declaration is virtual. 2449 2450Given 2451 class A { 2452 public: 2453 virtual void x(); 2454 }; 2455 matches A::x 2456</pre></td></tr> 2457 2458 2459<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('isVirtualAsWritten0')"><a name="isVirtualAsWritten0Anchor">isVirtualAsWritten</a></td><td></td></tr> 2460<tr><td colspan="4" class="doc" id="isVirtualAsWritten0"><pre>Matches if the given method declaration has an explicit "virtual". 2461 2462Given 2463 class A { 2464 public: 2465 virtual void x(); 2466 }; 2467 class B : public A { 2468 public: 2469 void x(); 2470 }; 2471 matches A::x but not B::x 2472</pre></td></tr> 2473 2474 2475<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>></td><td class="name" onclick="toggle('isArray0')"><a name="isArray0Anchor">isArray</a></td><td></td></tr> 2476<tr><td colspan="4" class="doc" id="isArray0"><pre>Matches array new expressions. 2477 2478Given: 2479 MyClass *p1 = new MyClass[10]; 2480cxxNewExpr(isArray()) 2481 matches the expression 'new MyClass[10]'. 2482</pre></td></tr> 2483 2484 2485<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>></td><td class="name" onclick="toggle('hasOverloadedOperatorName1')"><a name="hasOverloadedOperatorName1Anchor">hasOverloadedOperatorName</a></td><td>StringRef Name</td></tr> 2486<tr><td colspan="4" class="doc" id="hasOverloadedOperatorName1"><pre>Matches overloaded operator names. 2487 2488Matches overloaded operator names specified in strings without the 2489"operator" prefix: e.g. "<<". 2490 2491Given: 2492 class A { int operator*(); }; 2493 const A &operator<<(const A &a, const A &b); 2494 A a; 2495 a << a; // <-- This matches 2496 2497cxxOperatorCallExpr(hasOverloadedOperatorName("<<"))) matches the 2498specified line and 2499cxxRecordDecl(hasMethod(hasOverloadedOperatorName("*"))) 2500matches the declaration of A. 2501 2502Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>> 2503</pre></td></tr> 2504 2505 2506<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>></td><td class="name" onclick="toggle('isAssignmentOperator1')"><a name="isAssignmentOperator1Anchor">isAssignmentOperator</a></td><td></td></tr> 2507<tr><td colspan="4" class="doc" id="isAssignmentOperator1"><pre>Matches all kinds of assignment operators. 2508 2509Example 1: matches a += b (matcher = binaryOperator(isAssignmentOperator())) 2510 if (a == b) 2511 a += b; 2512 2513Example 2: matches s1 = s2 2514 (matcher = cxxOperatorCallExpr(isAssignmentOperator())) 2515 struct S { S& operator=(const S&); }; 2516 void x() { S s1, s2; s1 = s2; }) 2517</pre></td></tr> 2518 2519 2520<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('hasDefinition0')"><a name="hasDefinition0Anchor">hasDefinition</a></td><td></td></tr> 2521<tr><td colspan="4" class="doc" id="hasDefinition0"><pre>Matches a class declaration that is defined. 2522 2523Example matches x (matcher = cxxRecordDecl(hasDefinition())) 2524class x {}; 2525class y; 2526</pre></td></tr> 2527 2528 2529<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isDerivedFrom1')"><a name="isDerivedFrom1Anchor">isDerivedFrom</a></td><td>std::string BaseName</td></tr> 2530<tr><td colspan="4" class="doc" id="isDerivedFrom1"><pre>Overloaded method as shortcut for isDerivedFrom(hasName(...)). 2531</pre></td></tr> 2532 2533 2534<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isExplicitTemplateSpecialization2')"><a name="isExplicitTemplateSpecialization2Anchor">isExplicitTemplateSpecialization</a></td><td></td></tr> 2535<tr><td colspan="4" class="doc" id="isExplicitTemplateSpecialization2"><pre>Matches explicit template specializations of function, class, or 2536static member variable template instantiations. 2537 2538Given 2539 template<typename T> void A(T t) { } 2540 template<> void A(int N) { } 2541functionDecl(isExplicitTemplateSpecialization()) 2542 matches the specialization A<int>(). 2543 2544Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>> 2545</pre></td></tr> 2546 2547 2548<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isFinal0')"><a name="isFinal0Anchor">isFinal</a></td><td></td></tr> 2549<tr><td colspan="4" class="doc" id="isFinal0"><pre>Matches if the given method or class declaration is final. 2550 2551Given: 2552 class A final {}; 2553 2554 struct B { 2555 virtual void f(); 2556 }; 2557 2558 struct C : B { 2559 void f() final; 2560 }; 2561matches A and C::f, but not B, C, or B::f 2562</pre></td></tr> 2563 2564 2565<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isLambda0')"><a name="isLambda0Anchor">isLambda</a></td><td></td></tr> 2566<tr><td colspan="4" class="doc" id="isLambda0"><pre>Matches the generated class of lambda expressions. 2567 2568Given: 2569 auto x = []{}; 2570 2571cxxRecordDecl(isLambda()) matches the implicit class declaration of 2572decltype(x) 2573</pre></td></tr> 2574 2575 2576<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isSameOrDerivedFrom1')"><a name="isSameOrDerivedFrom1Anchor">isSameOrDerivedFrom</a></td><td>std::string BaseName</td></tr> 2577<tr><td colspan="4" class="doc" id="isSameOrDerivedFrom1"><pre>Overloaded method as shortcut for 2578isSameOrDerivedFrom(hasName(...)). 2579</pre></td></tr> 2580 2581 2582<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isTemplateInstantiation2')"><a name="isTemplateInstantiation2Anchor">isTemplateInstantiation</a></td><td></td></tr> 2583<tr><td colspan="4" class="doc" id="isTemplateInstantiation2"><pre>Matches template instantiations of function, class, or static 2584member variable template instantiations. 2585 2586Given 2587 template <typename T> class X {}; class A {}; X<A> x; 2588or 2589 template <typename T> class X {}; class A {}; template class X<A>; 2590or 2591 template <typename T> class X {}; class A {}; extern template class X<A>; 2592cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) 2593 matches the template instantiation of X<A>. 2594 2595But given 2596 template <typename T> class X {}; class A {}; 2597 template <> class X<A> {}; X<A> x; 2598cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) 2599 does not match, as X<A> is an explicit template specialization. 2600 2601Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>> 2602</pre></td></tr> 2603 2604 2605<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>></td><td class="name" onclick="toggle('argumentCountIs0')"><a name="argumentCountIs0Anchor">argumentCountIs</a></td><td>unsigned N</td></tr> 2606<tr><td colspan="4" class="doc" id="argumentCountIs0"><pre>Checks that a call expression or a constructor call expression has 2607a specific number of arguments (including absent default arguments). 2608 2609Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2))) 2610 void f(int x, int y); 2611 f(0, 0); 2612</pre></td></tr> 2613 2614 2615<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>></td><td class="name" onclick="toggle('usesADL0')"><a name="usesADL0Anchor">usesADL</a></td><td></td></tr> 2616<tr><td colspan="4" class="doc" id="usesADL0"><pre>Matches call expressions which were resolved using ADL. 2617 2618Example matches y(x) but not y(42) or NS::y(x). 2619 namespace NS { 2620 struct X {}; 2621 void y(X); 2622 } 2623 2624 void y(...); 2625 2626 void test() { 2627 NS::X x; 2628 y(x); // Matches 2629 NS::y(x); // Doesn't match 2630 y(42); // Doesn't match 2631 using NS::y; 2632 y(x); // Found by both unqualified lookup and ADL, doesn't match 2633 } 2634</pre></td></tr> 2635 2636 2637<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CastExpr.html">CastExpr</a>></td><td class="name" onclick="toggle('hasCastKind0')"><a name="hasCastKind0Anchor">hasCastKind</a></td><td>CastKind Kind</td></tr> 2638<tr><td colspan="4" class="doc" id="hasCastKind0"><pre>Matches casts that has a given cast kind. 2639 2640Example: matches the implicit cast around 0 2641(matcher = castExpr(hasCastKind(CK_NullToPointer))) 2642 int *p = 0; 2643 2644If the matcher is use from clang-query, CastKind parameter 2645should be passed as a quoted string. e.g., ofKind("CK_NullToPointer"). 2646</pre></td></tr> 2647 2648 2649<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>></td><td class="name" onclick="toggle('equals4')"><a name="equals4Anchor">equals</a></td><td>bool Value</td></tr> 2650<tr><td colspan="4" class="doc" id="equals4"><pre></pre></td></tr> 2651 2652 2653<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>></td><td class="name" onclick="toggle('equals3')"><a name="equals3Anchor">equals</a></td><td>const ValueT Value</td></tr> 2654<tr><td colspan="4" class="doc" id="equals3"><pre>Matches literals that are equal to the given value of type ValueT. 2655 2656Given 2657 f('false, 3.14, 42); 2658characterLiteral(equals(0)) 2659 matches 'cxxBoolLiteral(equals(false)) and cxxBoolLiteral(equals(0)) 2660 match false 2661floatLiteral(equals(3.14)) and floatLiteral(equals(314e-2)) 2662 match 3.14 2663integerLiteral(equals(42)) 2664 matches 42 2665 2666Note that you cannot directly match a negative numeric literal because the 2667minus sign is not part of the literal: It is a unary operator whose operand 2668is the positive numeric literal. Instead, you must use a unaryOperator() 2669matcher to match the minus sign: 2670 2671unaryOperator(hasOperatorName("-"), 2672 hasUnaryOperand(integerLiteral(equals(13)))) 2673 2674Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBoolLiteralExpr.html">CXXBoolLiteralExpr</a>>, 2675 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>> 2676</pre></td></tr> 2677 2678 2679<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>></td><td class="name" onclick="toggle('equals10')"><a name="equals10Anchor">equals</a></td><td>double Value</td></tr> 2680<tr><td colspan="4" class="doc" id="equals10"><pre></pre></td></tr> 2681 2682 2683<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>></td><td class="name" onclick="toggle('equals7')"><a name="equals7Anchor">equals</a></td><td>unsigned Value</td></tr> 2684<tr><td colspan="4" class="doc" id="equals7"><pre></pre></td></tr> 2685 2686 2687<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html">ClassTemplateSpecializationDecl</a>></td><td class="name" onclick="toggle('templateArgumentCountIs0')"><a name="templateArgumentCountIs0Anchor">templateArgumentCountIs</a></td><td>unsigned N</td></tr> 2688<tr><td colspan="4" class="doc" id="templateArgumentCountIs0"><pre>Matches if the number of template arguments equals N. 2689 2690Given 2691 template<typename T> struct C {}; 2692 C<int> c; 2693classTemplateSpecializationDecl(templateArgumentCountIs(1)) 2694 matches C<int>. 2695</pre></td></tr> 2696 2697 2698<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CompoundStmt.html">CompoundStmt</a>></td><td class="name" onclick="toggle('statementCountIs0')"><a name="statementCountIs0Anchor">statementCountIs</a></td><td>unsigned N</td></tr> 2699<tr><td colspan="4" class="doc" id="statementCountIs0"><pre>Checks that a compound statement contains a specific number of 2700child statements. 2701 2702Example: Given 2703 { for (;;) {} } 2704compoundStmt(statementCountIs(0))) 2705 matches '{}' 2706 but does not match the outer compound statement. 2707</pre></td></tr> 2708 2709 2710<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ConstantArrayType.html">ConstantArrayType</a>></td><td class="name" onclick="toggle('hasSize0')"><a name="hasSize0Anchor">hasSize</a></td><td>unsigned N</td></tr> 2711<tr><td colspan="4" class="doc" id="hasSize0"><pre>Matches nodes that have the specified size. 2712 2713Given 2714 int a[42]; 2715 int b[2 * 21]; 2716 int c[41], d[43]; 2717 char *s = "abcd"; 2718 wchar_t *ws = L"abcd"; 2719 char *w = "a"; 2720constantArrayType(hasSize(42)) 2721 matches "int a[42]" and "int b[2 * 21]" 2722stringLiteral(hasSize(4)) 2723 matches "abcd", L"abcd" 2724</pre></td></tr> 2725 2726 2727<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html">DeclStmt</a>></td><td class="name" onclick="toggle('declCountIs0')"><a name="declCountIs0Anchor">declCountIs</a></td><td>unsigned N</td></tr> 2728<tr><td colspan="4" class="doc" id="declCountIs0"><pre>Matches declaration statements that contain a specific number of 2729declarations. 2730 2731Example: Given 2732 int a, b; 2733 int c; 2734 int d = 2, e; 2735declCountIs(2) 2736 matches 'int a, b;' and 'int d = 2, e;', but not 'int c;'. 2737</pre></td></tr> 2738 2739 2740<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('equalsBoundNode1')"><a name="equalsBoundNode1Anchor">equalsBoundNode</a></td><td>std::string ID</td></tr> 2741<tr><td colspan="4" class="doc" id="equalsBoundNode1"><pre>Matches if a node equals a previously bound node. 2742 2743Matches a node if it equals the node previously bound to ID. 2744 2745Given 2746 class X { int a; int b; }; 2747cxxRecordDecl( 2748 has(fieldDecl(hasName("a"), hasType(type().bind("t")))), 2749 has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t")))))) 2750 matches the class X, as a and b have the same type. 2751 2752Note that when multiple matches are involved via forEach* matchers, 2753equalsBoundNodes acts as a filter. 2754For example: 2755compoundStmt( 2756 forEachDescendant(varDecl().bind("d")), 2757 forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d")))))) 2758will trigger a match for each combination of variable declaration 2759and reference to that variable declaration within a compound statement. 2760</pre></td></tr> 2761 2762 2763<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('equalsNode0')"><a name="equalsNode0Anchor">equalsNode</a></td><td>const Decl* Other</td></tr> 2764<tr><td colspan="4" class="doc" id="equalsNode0"><pre>Matches if a node equals another node. 2765 2766Decl has pointer identity in the AST. 2767</pre></td></tr> 2768 2769 2770<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('hasAttr0')"><a name="hasAttr0Anchor">hasAttr</a></td><td>attr::Kind AttrKind</td></tr> 2771<tr><td colspan="4" class="doc" id="hasAttr0"><pre>Matches declaration that has a given attribute. 2772 2773Given 2774 __attribute__((device)) void f() { ... } 2775decl(hasAttr(clang::attr::CUDADevice)) matches the function declaration of 2776f. If the matcher is used from clang-query, attr::Kind parameter should be 2777passed as a quoted string. e.g., hasAttr("attr::CUDADevice"). 2778</pre></td></tr> 2779 2780 2781<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('isExpansionInFileMatching0')"><a name="isExpansionInFileMatching0Anchor">isExpansionInFileMatching</a></td><td>std::string RegExp</td></tr> 2782<tr><td colspan="4" class="doc" id="isExpansionInFileMatching0"><pre>Matches AST nodes that were expanded within files whose name is 2783partially matching a given regex. 2784 2785Example matches Y but not X 2786 (matcher = cxxRecordDecl(isExpansionInFileMatching("AST.*")) 2787 #include "ASTMatcher.h" 2788 class X {}; 2789ASTMatcher.h: 2790 class Y {}; 2791 2792Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> 2793</pre></td></tr> 2794 2795 2796<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('isExpansionInMainFile0')"><a name="isExpansionInMainFile0Anchor">isExpansionInMainFile</a></td><td></td></tr> 2797<tr><td colspan="4" class="doc" id="isExpansionInMainFile0"><pre>Matches AST nodes that were expanded within the main-file. 2798 2799Example matches X but not Y 2800 (matcher = cxxRecordDecl(isExpansionInMainFile()) 2801 #include <Y.h> 2802 class X {}; 2803Y.h: 2804 class Y {}; 2805 2806Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> 2807</pre></td></tr> 2808 2809 2810<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('isExpansionInSystemHeader0')"><a name="isExpansionInSystemHeader0Anchor">isExpansionInSystemHeader</a></td><td></td></tr> 2811<tr><td colspan="4" class="doc" id="isExpansionInSystemHeader0"><pre>Matches AST nodes that were expanded within system-header-files. 2812 2813Example matches Y but not X 2814 (matcher = cxxRecordDecl(isExpansionInSystemHeader()) 2815 #include <SystemHeader.h> 2816 class X {}; 2817SystemHeader.h: 2818 class Y {}; 2819 2820Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> 2821</pre></td></tr> 2822 2823 2824<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('isImplicit0')"><a name="isImplicit0Anchor">isImplicit</a></td><td></td></tr> 2825<tr><td colspan="4" class="doc" id="isImplicit0"><pre>Matches a declaration that has been implicitly added 2826by the compiler (eg. implicit default/copy constructors). 2827</pre></td></tr> 2828 2829 2830<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('isPrivate0')"><a name="isPrivate0Anchor">isPrivate</a></td><td></td></tr> 2831<tr><td colspan="4" class="doc" id="isPrivate0"><pre>Matches private C++ declarations. 2832 2833Given 2834 class C { 2835 public: int a; 2836 protected: int b; 2837 private: int c; 2838 }; 2839fieldDecl(isPrivate()) 2840 matches 'int c;' 2841</pre></td></tr> 2842 2843 2844<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('isProtected0')"><a name="isProtected0Anchor">isProtected</a></td><td></td></tr> 2845<tr><td colspan="4" class="doc" id="isProtected0"><pre>Matches protected C++ declarations. 2846 2847Given 2848 class C { 2849 public: int a; 2850 protected: int b; 2851 private: int c; 2852 }; 2853fieldDecl(isProtected()) 2854 matches 'int b;' 2855</pre></td></tr> 2856 2857 2858<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('isPublic0')"><a name="isPublic0Anchor">isPublic</a></td><td></td></tr> 2859<tr><td colspan="4" class="doc" id="isPublic0"><pre>Matches public C++ declarations. 2860 2861Given 2862 class C { 2863 public: int a; 2864 protected: int b; 2865 private: int c; 2866 }; 2867fieldDecl(isPublic()) 2868 matches 'int a;' 2869</pre></td></tr> 2870 2871 2872<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DesignatedInitExpr.html">DesignatedInitExpr</a>></td><td class="name" onclick="toggle('designatorCountIs0')"><a name="designatorCountIs0Anchor">designatorCountIs</a></td><td>unsigned N</td></tr> 2873<tr><td colspan="4" class="doc" id="designatorCountIs0"><pre>Matches designated initializer expressions that contain 2874a specific number of designators. 2875 2876Example: Given 2877 point ptarray[10] = { [2].y = 1.0, [0].x = 1.0 }; 2878 point ptarray2[10] = { [2].y = 1.0, [2].x = 0.0, [0].x = 1.0 }; 2879designatorCountIs(2) 2880 matches '{ [2].y = 1.0, [0].x = 1.0 }', 2881 but not '{ [2].y = 1.0, [2].x = 0.0, [0].x = 1.0 }'. 2882</pre></td></tr> 2883 2884 2885<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1EnumDecl.html">EnumDecl</a>></td><td class="name" onclick="toggle('isScoped0')"><a name="isScoped0Anchor">isScoped</a></td><td></td></tr> 2886<tr><td colspan="4" class="doc" id="isScoped0"><pre>Matches C++11 scoped enum declaration. 2887 2888Example matches Y (matcher = enumDecl(isScoped())) 2889enum X {}; 2890enum class Y {}; 2891</pre></td></tr> 2892 2893 2894<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>></td><td class="name" onclick="toggle('isInstantiationDependent0')"><a name="isInstantiationDependent0Anchor">isInstantiationDependent</a></td><td></td></tr> 2895<tr><td colspan="4" class="doc" id="isInstantiationDependent0"><pre>Matches expressions that are instantiation-dependent even if it is 2896neither type- nor value-dependent. 2897 2898In the following example, the expression sizeof(sizeof(T() + T())) 2899is instantiation-dependent (since it involves a template parameter T), 2900but is neither type- nor value-dependent, since the type of the inner 2901sizeof is known (std::size_t) and therefore the size of the outer 2902sizeof is known. 2903 template<typename T> 2904 void f(T x, T y) { sizeof(sizeof(T() + T()); } 2905expr(isInstantiationDependent()) matches sizeof(sizeof(T() + T()) 2906</pre></td></tr> 2907 2908 2909<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>></td><td class="name" onclick="toggle('isTypeDependent0')"><a name="isTypeDependent0Anchor">isTypeDependent</a></td><td></td></tr> 2910<tr><td colspan="4" class="doc" id="isTypeDependent0"><pre>Matches expressions that are type-dependent because the template type 2911is not yet instantiated. 2912 2913For example, the expressions "x" and "x + y" are type-dependent in 2914the following code, but "y" is not type-dependent: 2915 template<typename T> 2916 void add(T x, int y) { 2917 x + y; 2918 } 2919expr(isTypeDependent()) matches x + y 2920</pre></td></tr> 2921 2922 2923<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>></td><td class="name" onclick="toggle('isValueDependent0')"><a name="isValueDependent0Anchor">isValueDependent</a></td><td></td></tr> 2924<tr><td colspan="4" class="doc" id="isValueDependent0"><pre>Matches expression that are value-dependent because they contain a 2925non-type template parameter. 2926 2927For example, the array bound of "Chars" in the following example is 2928value-dependent. 2929 template<int Size> int f() { return Size; } 2930expr(isValueDependent()) matches return Size 2931</pre></td></tr> 2932 2933 2934<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html">FieldDecl</a>></td><td class="name" onclick="toggle('hasBitWidth0')"><a name="hasBitWidth0Anchor">hasBitWidth</a></td><td>unsigned Width</td></tr> 2935<tr><td colspan="4" class="doc" id="hasBitWidth0"><pre>Matches non-static data members that are bit-fields of the specified 2936bit width. 2937 2938Given 2939 class C { 2940 int a : 2; 2941 int b : 4; 2942 int c : 2; 2943 }; 2944fieldDecl(hasBitWidth(2)) 2945 matches 'int a;' and 'int c;' but not 'int b;'. 2946</pre></td></tr> 2947 2948 2949<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html">FieldDecl</a>></td><td class="name" onclick="toggle('isBitField0')"><a name="isBitField0Anchor">isBitField</a></td><td></td></tr> 2950<tr><td colspan="4" class="doc" id="isBitField0"><pre>Matches non-static data members that are bit-fields. 2951 2952Given 2953 class C { 2954 int a : 2; 2955 int b; 2956 }; 2957fieldDecl(isBitField()) 2958 matches 'int a;' but not 'int b;'. 2959</pre></td></tr> 2960 2961 2962<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>></td><td class="name" onclick="toggle('equals1')"><a name="equals1Anchor">equals</a></td><td>const ValueT Value</td></tr> 2963<tr><td colspan="4" class="doc" id="equals1"><pre>Matches literals that are equal to the given value of type ValueT. 2964 2965Given 2966 f('false, 3.14, 42); 2967characterLiteral(equals(0)) 2968 matches 'cxxBoolLiteral(equals(false)) and cxxBoolLiteral(equals(0)) 2969 match false 2970floatLiteral(equals(3.14)) and floatLiteral(equals(314e-2)) 2971 match 3.14 2972integerLiteral(equals(42)) 2973 matches 42 2974 2975Note that you cannot directly match a negative numeric literal because the 2976minus sign is not part of the literal: It is a unary operator whose operand 2977is the positive numeric literal. Instead, you must use a unaryOperator() 2978matcher to match the minus sign: 2979 2980unaryOperator(hasOperatorName("-"), 2981 hasUnaryOperand(integerLiteral(equals(13)))) 2982 2983Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBoolLiteralExpr.html">CXXBoolLiteralExpr</a>>, 2984 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>> 2985</pre></td></tr> 2986 2987 2988<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>></td><td class="name" onclick="toggle('equals12')"><a name="equals12Anchor">equals</a></td><td>double Value</td></tr> 2989<tr><td colspan="4" class="doc" id="equals12"><pre></pre></td></tr> 2990 2991 2992<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('hasDynamicExceptionSpec0')"><a name="hasDynamicExceptionSpec0Anchor">hasDynamicExceptionSpec</a></td><td></td></tr> 2993<tr><td colspan="4" class="doc" id="hasDynamicExceptionSpec0"><pre>Matches functions that have a dynamic exception specification. 2994 2995Given: 2996 void f(); 2997 void g() noexcept; 2998 void h() noexcept(true); 2999 void i() noexcept(false); 3000 void j() throw(); 3001 void k() throw(int); 3002 void l() throw(...); 3003functionDecl(hasDynamicExceptionSpec()) and 3004 functionProtoType(hasDynamicExceptionSpec()) 3005 match the declarations of j, k, and l, but not f, g, h, or i. 3006</pre></td></tr> 3007 3008 3009<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('hasOverloadedOperatorName0')"><a name="hasOverloadedOperatorName0Anchor">hasOverloadedOperatorName</a></td><td>StringRef Name</td></tr> 3010<tr><td colspan="4" class="doc" id="hasOverloadedOperatorName0"><pre>Matches overloaded operator names. 3011 3012Matches overloaded operator names specified in strings without the 3013"operator" prefix: e.g. "<<". 3014 3015Given: 3016 class A { int operator*(); }; 3017 const A &operator<<(const A &a, const A &b); 3018 A a; 3019 a << a; // <-- This matches 3020 3021cxxOperatorCallExpr(hasOverloadedOperatorName("<<"))) matches the 3022specified line and 3023cxxRecordDecl(hasMethod(hasOverloadedOperatorName("*"))) 3024matches the declaration of A. 3025 3026Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>> 3027</pre></td></tr> 3028 3029 3030<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('hasTrailingReturn0')"><a name="hasTrailingReturn0Anchor">hasTrailingReturn</a></td><td></td></tr> 3031<tr><td colspan="4" class="doc" id="hasTrailingReturn0"><pre>Matches a function declared with a trailing return type. 3032 3033Example matches Y (matcher = functionDecl(hasTrailingReturn())) 3034int X() {} 3035auto Y() -> int {} 3036</pre></td></tr> 3037 3038 3039<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isConstexpr1')"><a name="isConstexpr1Anchor">isConstexpr</a></td><td></td></tr> 3040<tr><td colspan="4" class="doc" id="isConstexpr1"><pre>Matches constexpr variable and function declarations, 3041 and if constexpr. 3042 3043Given: 3044 constexpr int foo = 42; 3045 constexpr int bar(); 3046 void baz() { if constexpr(1 > 0) {} } 3047varDecl(isConstexpr()) 3048 matches the declaration of foo. 3049functionDecl(isConstexpr()) 3050 matches the declaration of bar. 3051ifStmt(isConstexpr()) 3052 matches the if statement in baz. 3053</pre></td></tr> 3054 3055 3056<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isDefaulted0')"><a name="isDefaulted0Anchor">isDefaulted</a></td><td></td></tr> 3057<tr><td colspan="4" class="doc" id="isDefaulted0"><pre>Matches defaulted function declarations. 3058 3059Given: 3060 class A { ~A(); }; 3061 class B { ~B() = default; }; 3062functionDecl(isDefaulted()) 3063 matches the declaration of ~B, but not ~A. 3064</pre></td></tr> 3065 3066 3067<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isDefinition3')"><a name="isDefinition3Anchor">isDefinition</a></td><td></td></tr> 3068<tr><td colspan="4" class="doc" id="isDefinition3"><pre>Matches if a declaration has a body attached. 3069 3070Example matches A, va, fa 3071 class A {}; 3072 class B; // Doesn't match, as it has no body. 3073 int va; 3074 extern int vb; // Doesn't match, as it doesn't define the variable. 3075 void fa() {} 3076 void fb(); // Doesn't match, as it has no body. 3077 @interface X 3078 - (void)ma; // Doesn't match, interface is declaration. 3079 @end 3080 @implementation X 3081 - (void)ma {} 3082 @end 3083 3084Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagDecl.html">TagDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>, 3085 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html">ObjCMethodDecl</a>> 3086</pre></td></tr> 3087 3088 3089<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isDeleted0')"><a name="isDeleted0Anchor">isDeleted</a></td><td></td></tr> 3090<tr><td colspan="4" class="doc" id="isDeleted0"><pre>Matches deleted function declarations. 3091 3092Given: 3093 void Func(); 3094 void DeletedFunc() = delete; 3095functionDecl(isDeleted()) 3096 matches the declaration of DeletedFunc, but not Func. 3097</pre></td></tr> 3098 3099 3100<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isExplicitTemplateSpecialization0')"><a name="isExplicitTemplateSpecialization0Anchor">isExplicitTemplateSpecialization</a></td><td></td></tr> 3101<tr><td colspan="4" class="doc" id="isExplicitTemplateSpecialization0"><pre>Matches explicit template specializations of function, class, or 3102static member variable template instantiations. 3103 3104Given 3105 template<typename T> void A(T t) { } 3106 template<> void A(int N) { } 3107functionDecl(isExplicitTemplateSpecialization()) 3108 matches the specialization A<int>(). 3109 3110Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>> 3111</pre></td></tr> 3112 3113 3114<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isExternC0')"><a name="isExternC0Anchor">isExternC</a></td><td></td></tr> 3115<tr><td colspan="4" class="doc" id="isExternC0"><pre>Matches extern "C" function or variable declarations. 3116 3117Given: 3118 extern "C" void f() {} 3119 extern "C" { void g() {} } 3120 void h() {} 3121 extern "C" int x = 1; 3122 extern "C" int y = 2; 3123 int z = 3; 3124functionDecl(isExternC()) 3125 matches the declaration of f and g, but not the declaration of h. 3126varDecl(isExternC()) 3127 matches the declaration of x and y, but not the declaration of z. 3128</pre></td></tr> 3129 3130 3131<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isInline1')"><a name="isInline1Anchor">isInline</a></td><td></td></tr> 3132<tr><td colspan="4" class="doc" id="isInline1"><pre>Matches function and namespace declarations that are marked with 3133the inline keyword. 3134 3135Given 3136 inline void f(); 3137 void g(); 3138 namespace n { 3139 inline namespace m {} 3140 } 3141functionDecl(isInline()) will match ::f(). 3142namespaceDecl(isInline()) will match n::m. 3143</pre></td></tr> 3144 3145 3146<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isMain0')"><a name="isMain0Anchor">isMain</a></td><td></td></tr> 3147<tr><td colspan="4" class="doc" id="isMain0"><pre>Determines whether the function is "main", which is the entry point 3148into an executable program. 3149</pre></td></tr> 3150 3151 3152<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isNoReturn0')"><a name="isNoReturn0Anchor">isNoReturn</a></td><td></td></tr> 3153<tr><td colspan="4" class="doc" id="isNoReturn0"><pre>Matches FunctionDecls that have a noreturn attribute. 3154 3155Given 3156 void nope(); 3157 [[noreturn]] void a(); 3158 __attribute__((noreturn)) void b(); 3159 struct c { [[noreturn]] c(); }; 3160functionDecl(isNoReturn()) 3161 matches all of those except 3162 void nope(); 3163</pre></td></tr> 3164 3165 3166<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isNoThrow0')"><a name="isNoThrow0Anchor">isNoThrow</a></td><td></td></tr> 3167<tr><td colspan="4" class="doc" id="isNoThrow0"><pre>Matches functions that have a non-throwing exception specification. 3168 3169Given: 3170 void f(); 3171 void g() noexcept; 3172 void h() throw(); 3173 void i() throw(int); 3174 void j() noexcept(false); 3175functionDecl(isNoThrow()) and functionProtoType(isNoThrow()) 3176 match the declarations of g, and h, but not f, i or j. 3177</pre></td></tr> 3178 3179 3180<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isStaticStorageClass0')"><a name="isStaticStorageClass0Anchor">isStaticStorageClass</a></td><td></td></tr> 3181<tr><td colspan="4" class="doc" id="isStaticStorageClass0"><pre>Matches variable/function declarations that have "static" storage 3182class specifier ("static" keyword) written in the source. 3183 3184Given: 3185 static void f() {} 3186 static int i = 0; 3187 extern int j; 3188 int k; 3189functionDecl(isStaticStorageClass()) 3190 matches the function declaration f. 3191varDecl(isStaticStorageClass()) 3192 matches the variable declaration i. 3193</pre></td></tr> 3194 3195 3196<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isTemplateInstantiation0')"><a name="isTemplateInstantiation0Anchor">isTemplateInstantiation</a></td><td></td></tr> 3197<tr><td colspan="4" class="doc" id="isTemplateInstantiation0"><pre>Matches template instantiations of function, class, or static 3198member variable template instantiations. 3199 3200Given 3201 template <typename T> class X {}; class A {}; X<A> x; 3202or 3203 template <typename T> class X {}; class A {}; template class X<A>; 3204or 3205 template <typename T> class X {}; class A {}; extern template class X<A>; 3206cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) 3207 matches the template instantiation of X<A>. 3208 3209But given 3210 template <typename T> class X {}; class A {}; 3211 template <> class X<A> {}; X<A> x; 3212cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) 3213 does not match, as X<A> is an explicit template specialization. 3214 3215Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>> 3216</pre></td></tr> 3217 3218 3219<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isVariadic0')"><a name="isVariadic0Anchor">isVariadic</a></td><td></td></tr> 3220<tr><td colspan="4" class="doc" id="isVariadic0"><pre>Matches if a function declaration is variadic. 3221 3222Example matches f, but not g or h. The function i will not match, even when 3223compiled in C mode. 3224 void f(...); 3225 void g(int); 3226 template <typename... Ts> void h(Ts...); 3227 void i(); 3228</pre></td></tr> 3229 3230 3231<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('parameterCountIs0')"><a name="parameterCountIs0Anchor">parameterCountIs</a></td><td>unsigned N</td></tr> 3232<tr><td colspan="4" class="doc" id="parameterCountIs0"><pre>Matches FunctionDecls and FunctionProtoTypes that have a 3233specific parameter count. 3234 3235Given 3236 void f(int i) {} 3237 void g(int i, int j) {} 3238 void h(int i, int j); 3239 void j(int i); 3240 void k(int x, int y, int z, ...); 3241functionDecl(parameterCountIs(2)) 3242 matches g and h 3243functionProtoType(parameterCountIs(2)) 3244 matches g and h 3245functionProtoType(parameterCountIs(3)) 3246 matches k 3247</pre></td></tr> 3248 3249 3250<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionProtoType.html">FunctionProtoType</a>></td><td class="name" onclick="toggle('hasDynamicExceptionSpec1')"><a name="hasDynamicExceptionSpec1Anchor">hasDynamicExceptionSpec</a></td><td></td></tr> 3251<tr><td colspan="4" class="doc" id="hasDynamicExceptionSpec1"><pre>Matches functions that have a dynamic exception specification. 3252 3253Given: 3254 void f(); 3255 void g() noexcept; 3256 void h() noexcept(true); 3257 void i() noexcept(false); 3258 void j() throw(); 3259 void k() throw(int); 3260 void l() throw(...); 3261functionDecl(hasDynamicExceptionSpec()) and 3262 functionProtoType(hasDynamicExceptionSpec()) 3263 match the declarations of j, k, and l, but not f, g, h, or i. 3264</pre></td></tr> 3265 3266 3267<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionProtoType.html">FunctionProtoType</a>></td><td class="name" onclick="toggle('isNoThrow1')"><a name="isNoThrow1Anchor">isNoThrow</a></td><td></td></tr> 3268<tr><td colspan="4" class="doc" id="isNoThrow1"><pre>Matches functions that have a non-throwing exception specification. 3269 3270Given: 3271 void f(); 3272 void g() noexcept; 3273 void h() throw(); 3274 void i() throw(int); 3275 void j() noexcept(false); 3276functionDecl(isNoThrow()) and functionProtoType(isNoThrow()) 3277 match the declarations of g, and h, but not f, i or j. 3278</pre></td></tr> 3279 3280 3281<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionProtoType.html">FunctionProtoType</a>></td><td class="name" onclick="toggle('parameterCountIs1')"><a name="parameterCountIs1Anchor">parameterCountIs</a></td><td>unsigned N</td></tr> 3282<tr><td colspan="4" class="doc" id="parameterCountIs1"><pre>Matches FunctionDecls and FunctionProtoTypes that have a 3283specific parameter count. 3284 3285Given 3286 void f(int i) {} 3287 void g(int i, int j) {} 3288 void h(int i, int j); 3289 void j(int i); 3290 void k(int x, int y, int z, ...); 3291functionDecl(parameterCountIs(2)) 3292 matches g and h 3293functionProtoType(parameterCountIs(2)) 3294 matches g and h 3295functionProtoType(parameterCountIs(3)) 3296 matches k 3297</pre></td></tr> 3298 3299 3300<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IfStmt.html">IfStmt</a>></td><td class="name" onclick="toggle('isConstexpr2')"><a name="isConstexpr2Anchor">isConstexpr</a></td><td></td></tr> 3301<tr><td colspan="4" class="doc" id="isConstexpr2"><pre>Matches constexpr variable and function declarations, 3302 and if constexpr. 3303 3304Given: 3305 constexpr int foo = 42; 3306 constexpr int bar(); 3307 void baz() { if constexpr(1 > 0) {} } 3308varDecl(isConstexpr()) 3309 matches the declaration of foo. 3310functionDecl(isConstexpr()) 3311 matches the declaration of bar. 3312ifStmt(isConstexpr()) 3313 matches the if statement in baz. 3314</pre></td></tr> 3315 3316 3317<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>></td><td class="name" onclick="toggle('equals6')"><a name="equals6Anchor">equals</a></td><td>bool Value</td></tr> 3318<tr><td colspan="4" class="doc" id="equals6"><pre></pre></td></tr> 3319 3320 3321<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>></td><td class="name" onclick="toggle('equals0')"><a name="equals0Anchor">equals</a></td><td>const ValueT Value</td></tr> 3322<tr><td colspan="4" class="doc" id="equals0"><pre>Matches literals that are equal to the given value of type ValueT. 3323 3324Given 3325 f('false, 3.14, 42); 3326characterLiteral(equals(0)) 3327 matches 'cxxBoolLiteral(equals(false)) and cxxBoolLiteral(equals(0)) 3328 match false 3329floatLiteral(equals(3.14)) and floatLiteral(equals(314e-2)) 3330 match 3.14 3331integerLiteral(equals(42)) 3332 matches 42 3333 3334Note that you cannot directly match a negative numeric literal because the 3335minus sign is not part of the literal: It is a unary operator whose operand 3336is the positive numeric literal. Instead, you must use a unaryOperator() 3337matcher to match the minus sign: 3338 3339unaryOperator(hasOperatorName("-"), 3340 hasUnaryOperand(integerLiteral(equals(13)))) 3341 3342Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXBoolLiteralExpr.html">CXXBoolLiteralExpr</a>>, 3343 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>> 3344</pre></td></tr> 3345 3346 3347<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>></td><td class="name" onclick="toggle('equals13')"><a name="equals13Anchor">equals</a></td><td>double Value</td></tr> 3348<tr><td colspan="4" class="doc" id="equals13"><pre></pre></td></tr> 3349 3350 3351<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>></td><td class="name" onclick="toggle('equals9')"><a name="equals9Anchor">equals</a></td><td>unsigned Value</td></tr> 3352<tr><td colspan="4" class="doc" id="equals9"><pre></pre></td></tr> 3353 3354 3355<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>></td><td class="name" onclick="toggle('isArrow0')"><a name="isArrow0Anchor">isArrow</a></td><td></td></tr> 3356<tr><td colspan="4" class="doc" id="isArrow0"><pre>Matches member expressions that are called with '->' as opposed 3357to '.'. 3358 3359Member calls on the implicit this pointer match as called with '->'. 3360 3361Given 3362 class Y { 3363 void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; } 3364 template <class T> void f() { this->f<T>(); f<T>(); } 3365 int a; 3366 static int b; 3367 }; 3368 template <class T> 3369 class Z { 3370 void x() { this->m; } 3371 }; 3372memberExpr(isArrow()) 3373 matches this->x, x, y.x, a, this->b 3374cxxDependentScopeMemberExpr(isArrow()) 3375 matches this->m 3376unresolvedMemberExpr(isArrow()) 3377 matches this->f<T>, f<T> 3378</pre></td></tr> 3379 3380 3381<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>></td><td class="name" onclick="toggle('hasExternalFormalLinkage0')"><a name="hasExternalFormalLinkage0Anchor">hasExternalFormalLinkage</a></td><td></td></tr> 3382<tr><td colspan="4" class="doc" id="hasExternalFormalLinkage0"><pre>Matches a declaration that has external formal linkage. 3383 3384Example matches only z (matcher = varDecl(hasExternalFormalLinkage())) 3385void f() { 3386 int x; 3387 static int y; 3388} 3389int z; 3390 3391Example matches f() because it has external formal linkage despite being 3392unique to the translation unit as though it has internal likage 3393(matcher = functionDecl(hasExternalFormalLinkage())) 3394 3395namespace { 3396void f() {} 3397} 3398</pre></td></tr> 3399 3400 3401<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>></td><td class="name" onclick="toggle('hasName0')"><a name="hasName0Anchor">hasName</a></td><td>const std::string Name</td></tr> 3402<tr><td colspan="4" class="doc" id="hasName0"><pre>Matches NamedDecl nodes that have the specified name. 3403 3404Supports specifying enclosing namespaces or classes by prefixing the name 3405with '<enclosing>::'. 3406Does not match typedefs of an underlying type with the given name. 3407 3408Example matches X (Name == "X") 3409 class X; 3410 3411Example matches X (Name is one of "::a::b::X", "a::b::X", "b::X", "X") 3412 namespace a { namespace b { class X; } } 3413</pre></td></tr> 3414 3415 3416<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>></td><td class="name" onclick="toggle('matchesName0')"><a name="matchesName0Anchor">matchesName</a></td><td>std::string RegExp</td></tr> 3417<tr><td colspan="4" class="doc" id="matchesName0"><pre>Matches NamedDecl nodes whose fully qualified names contain 3418a substring matched by the given RegExp. 3419 3420Supports specifying enclosing namespaces or classes by 3421prefixing the name with '<enclosing>::'. Does not match typedefs 3422of an underlying type with the given name. 3423 3424Example matches X (regexp == "::X") 3425 class X; 3426 3427Example matches X (regexp is one of "::X", "^foo::.*X", among others) 3428 namespace foo { namespace bar { class X; } } 3429</pre></td></tr> 3430 3431 3432<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamespaceDecl.html">NamespaceDecl</a>></td><td class="name" onclick="toggle('isAnonymous0')"><a name="isAnonymous0Anchor">isAnonymous</a></td><td></td></tr> 3433<tr><td colspan="4" class="doc" id="isAnonymous0"><pre>Matches anonymous namespace declarations. 3434 3435Given 3436 namespace n { 3437 namespace {} // #1 3438 } 3439namespaceDecl(isAnonymous()) will match #1 but not ::n. 3440</pre></td></tr> 3441 3442 3443<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamespaceDecl.html">NamespaceDecl</a>></td><td class="name" onclick="toggle('isInline0')"><a name="isInline0Anchor">isInline</a></td><td></td></tr> 3444<tr><td colspan="4" class="doc" id="isInline0"><pre>Matches function and namespace declarations that are marked with 3445the inline keyword. 3446 3447Given 3448 inline void f(); 3449 void g(); 3450 namespace n { 3451 inline namespace m {} 3452 } 3453functionDecl(isInline()) will match ::f(). 3454namespaceDecl(isInline()) will match n::m. 3455</pre></td></tr> 3456 3457 3458<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPDefaultClause.html">OMPDefaultClause</a>></td><td class="name" onclick="toggle('isNoneKind0')"><a name="isNoneKind0Anchor">isNoneKind</a></td><td></td></tr> 3459<tr><td colspan="4" class="doc" id="isNoneKind0"><pre>Matches if the OpenMP ``default`` clause has ``none`` kind specified. 3460 3461Given 3462 3463 #pragma omp parallel 3464 #pragma omp parallel default(none) 3465 #pragma omp parallel default(shared) 3466 3467``ompDefaultClause(isNoneKind())`` matches only ``default(none)``. 3468</pre></td></tr> 3469 3470 3471<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPDefaultClause.html">OMPDefaultClause</a>></td><td class="name" onclick="toggle('isSharedKind0')"><a name="isSharedKind0Anchor">isSharedKind</a></td><td></td></tr> 3472<tr><td colspan="4" class="doc" id="isSharedKind0"><pre>Matches if the OpenMP ``default`` clause has ``shared`` kind specified. 3473 3474Given 3475 3476 #pragma omp parallel 3477 #pragma omp parallel default(none) 3478 #pragma omp parallel default(shared) 3479 3480``ompDefaultClause(isSharedKind())`` matches only ``default(shared)``. 3481</pre></td></tr> 3482 3483 3484<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPExecutableDirective.html">OMPExecutableDirective</a>></td><td class="name" onclick="toggle('isAllowedToContainClauseKind0')"><a name="isAllowedToContainClauseKind0Anchor">isAllowedToContainClauseKind</a></td><td>OpenMPClauseKind CKind</td></tr> 3485<tr><td colspan="4" class="doc" id="isAllowedToContainClauseKind0"><pre>Matches if the OpenMP directive is allowed to contain the specified OpenMP 3486clause kind. 3487 3488Given 3489 3490 #pragma omp parallel 3491 #pragma omp parallel for 3492 #pragma omp for 3493 3494`ompExecutableDirective(isAllowedToContainClause(OMPC_default))`` matches 3495``omp parallel`` and ``omp parallel for``. 3496 3497If the matcher is use from clang-query, ``OpenMPClauseKind`` parameter 3498should be passed as a quoted string. e.g., 3499``isAllowedToContainClauseKind("OMPC_default").`` 3500</pre></td></tr> 3501 3502 3503<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPExecutableDirective.html">OMPExecutableDirective</a>></td><td class="name" onclick="toggle('isStandaloneDirective0')"><a name="isStandaloneDirective0Anchor">isStandaloneDirective</a></td><td></td></tr> 3504<tr><td colspan="4" class="doc" id="isStandaloneDirective0"><pre>Matches standalone OpenMP directives, 3505i.e., directives that can't have a structured block. 3506 3507Given 3508 3509 #pragma omp parallel 3510 {} 3511 #pragma omp taskyield 3512 3513``ompExecutableDirective(isStandaloneDirective()))`` matches 3514``omp taskyield``. 3515</pre></td></tr> 3516 3517 3518<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>></td><td class="name" onclick="toggle('argumentCountIs2')"><a name="argumentCountIs2Anchor">argumentCountIs</a></td><td>unsigned N</td></tr> 3519<tr><td colspan="4" class="doc" id="argumentCountIs2"><pre>Checks that a call expression or a constructor call expression has 3520a specific number of arguments (including absent default arguments). 3521 3522Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2))) 3523 void f(int x, int y); 3524 f(0, 0); 3525</pre></td></tr> 3526 3527 3528<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>></td><td class="name" onclick="toggle('hasKeywordSelector0')"><a name="hasKeywordSelector0Anchor">hasKeywordSelector</a></td><td></td></tr> 3529<tr><td colspan="4" class="doc" id="hasKeywordSelector0"><pre>Matches when the selector is a keyword selector 3530 3531objCMessageExpr(hasKeywordSelector()) matches the generated setFrame 3532message expression in 3533 3534 UIWebView *webView = ...; 3535 CGRect bodyFrame = webView.frame; 3536 bodyFrame.size.height = self.bodyContentHeight; 3537 webView.frame = bodyFrame; 3538 // ^---- matches here 3539</pre></td></tr> 3540 3541 3542<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>></td><td class="name" onclick="toggle('hasNullSelector0')"><a name="hasNullSelector0Anchor">hasNullSelector</a></td><td></td></tr> 3543<tr><td colspan="4" class="doc" id="hasNullSelector0"><pre>Matches when the selector is the empty selector 3544 3545Matches only when the selector of the objCMessageExpr is NULL. This may 3546represent an error condition in the tree! 3547</pre></td></tr> 3548 3549 3550<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>></td><td class="name" onclick="toggle('hasSelector0')"><a name="hasSelector0Anchor">hasSelector</a></td><td>std::string BaseName</td></tr> 3551<tr><td colspan="4" class="doc" id="hasSelector0"><pre>Matches when BaseName == Selector.getAsString() 3552 3553 matcher = objCMessageExpr(hasSelector("loadHTMLString:baseURL:")); 3554 matches the outer message expr in the code below, but NOT the message 3555 invocation for self.bodyView. 3556 [self.bodyView loadHTMLString:html baseURL:NULL]; 3557</pre></td></tr> 3558 3559 3560<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>></td><td class="name" onclick="toggle('hasUnarySelector0')"><a name="hasUnarySelector0Anchor">hasUnarySelector</a></td><td></td></tr> 3561<tr><td colspan="4" class="doc" id="hasUnarySelector0"><pre>Matches when the selector is a Unary Selector 3562 3563 matcher = objCMessageExpr(matchesSelector(hasUnarySelector()); 3564 matches self.bodyView in the code below, but NOT the outer message 3565 invocation of "loadHTMLString:baseURL:". 3566 [self.bodyView loadHTMLString:html baseURL:NULL]; 3567</pre></td></tr> 3568 3569 3570<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>></td><td class="name" onclick="toggle('isClassMessage0')"><a name="isClassMessage0Anchor">isClassMessage</a></td><td></td></tr> 3571<tr><td colspan="4" class="doc" id="isClassMessage0"><pre>Returns true when the Objective-C message is sent to a class. 3572 3573Example 3574matcher = objcMessageExpr(isClassMessage()) 3575matches 3576 [NSString stringWithFormat:@"format"]; 3577but not 3578 NSString *x = @"hello"; 3579 [x containsString:@"h"]; 3580</pre></td></tr> 3581 3582 3583<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>></td><td class="name" onclick="toggle('isInstanceMessage0')"><a name="isInstanceMessage0Anchor">isInstanceMessage</a></td><td></td></tr> 3584<tr><td colspan="4" class="doc" id="isInstanceMessage0"><pre>Returns true when the Objective-C message is sent to an instance. 3585 3586Example 3587matcher = objcMessageExpr(isInstanceMessage()) 3588matches 3589 NSString *x = @"hello"; 3590 [x containsString:@"h"]; 3591but not 3592 [NSString stringWithFormat:@"format"]; 3593</pre></td></tr> 3594 3595 3596<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html">ObjCMethodDecl</a>></td><td class="name" onclick="toggle('isClassMethod0')"><a name="isClassMethod0Anchor">isClassMethod</a></td><td></td></tr> 3597<tr><td colspan="4" class="doc" id="isClassMethod0"><pre>Returns true when the Objective-C method declaration is a class method. 3598 3599Example 3600matcher = objcMethodDecl(isClassMethod()) 3601matches 3602 @interface I + (void)foo; @end 3603but not 3604 @interface I - (void)bar; @end 3605</pre></td></tr> 3606 3607 3608<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html">ObjCMethodDecl</a>></td><td class="name" onclick="toggle('isInstanceMessage0')"><a name="isInstanceMessage0Anchor">isInstanceMethod</a></td><td></td></tr> 3609<tr><td colspan="4" class="doc" id="isInstanceMethod0"><pre>Returns true when the Objective-C method declaration is an instance method. 3610 3611Example 3612matcher = objcMethodDecl(isInstanceMethod()) 3613matches 3614 @interface I - (void)bar; @end 3615but not 3616 @interface I + (void)foo; @end 3617</pre></td></tr> 3618 3619 3620<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> 3621<tr><td colspan="4" class="doc" id="matchesSelector0"><pre>Matches ObjC selectors whose name contains 3622a substring matched by the given RegExp. 3623 matcher = objCMessageExpr(matchesSelector("loadHTMLStringmatches the outer message expr in the code below, but NOT the message 3624 invocation for self.bodyView. 3625 [self.bodyView loadHTMLString:html baseURL:NULL]; 3626</pre></td></tr> 3627 3628 3629<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> 3630<tr><td colspan="4" class="doc" id="numSelectorArgs0"><pre>Matches when the selector has the specified number of arguments 3631 3632 matcher = objCMessageExpr(numSelectorArgs(0)); 3633 matches self.bodyView in the code below 3634 3635 matcher = objCMessageExpr(numSelectorArgs(2)); 3636 matches the invocation of "loadHTMLString:baseURL:" but not that 3637 of self.bodyView 3638 [self.bodyView loadHTMLString:html baseURL:NULL]; 3639</pre></td></tr> 3640 3641 3642<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> 3643<tr><td colspan="4" class="doc" id="isDefinition2"><pre>Matches if a declaration has a body attached. 3644 3645Example matches A, va, fa 3646 class A {}; 3647 class B; // Doesn't match, as it has no body. 3648 int va; 3649 extern int vb; // Doesn't match, as it doesn't define the variable. 3650 void fa() {} 3651 void fb(); // Doesn't match, as it has no body. 3652 @interface X 3653 - (void)ma; // Doesn't match, interface is declaration. 3654 @end 3655 @implementation X 3656 - (void)ma {} 3657 @end 3658 3659Usable 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>>, 3660 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html">ObjCMethodDecl</a>> 3661</pre></td></tr> 3662 3663 3664<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> 3665<tr><td colspan="4" class="doc" id="hasDefaultArgument0"><pre>Matches a declaration that has default arguments. 3666 3667Example matches y (matcher = parmVarDecl(hasDefaultArgument())) 3668void x(int val) {} 3669void y(int val = 0) {} 3670</pre></td></tr> 3671 3672 3673<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('asString0')"><a name="asString0Anchor">asString</a></td><td>std::string Name</td></tr> 3674<tr><td colspan="4" class="doc" id="asString0"><pre>Matches if the matched type is represented by the given string. 3675 3676Given 3677 class Y { public: void x(); }; 3678 void z() { Y* y; y->x(); } 3679cxxMemberCallExpr(on(hasType(asString("class Y *")))) 3680 matches y->x() 3681</pre></td></tr> 3682 3683 3684<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> 3685<tr><td colspan="4" class="doc" id="equalsBoundNode3"><pre>Matches if a node equals a previously bound node. 3686 3687Matches a node if it equals the node previously bound to ID. 3688 3689Given 3690 class X { int a; int b; }; 3691cxxRecordDecl( 3692 has(fieldDecl(hasName("a"), hasType(type().bind("t")))), 3693 has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t")))))) 3694 matches the class X, as a and b have the same type. 3695 3696Note that when multiple matches are involved via forEach* matchers, 3697equalsBoundNodes acts as a filter. 3698For example: 3699compoundStmt( 3700 forEachDescendant(varDecl().bind("d")), 3701 forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d")))))) 3702will trigger a match for each combination of variable declaration 3703and reference to that variable declaration within a compound statement. 3704</pre></td></tr> 3705 3706 3707<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> 3708<tr><td colspan="4" class="doc" id="hasLocalQualifiers0"><pre>Matches QualType nodes that have local CV-qualifiers attached to 3709the node, not hidden within a typedef. 3710 3711Given 3712 typedef const int const_int; 3713 const_int i; 3714 int *const j; 3715 int *volatile k; 3716 int m; 3717varDecl(hasType(hasLocalQualifiers())) matches only j and k. 3718i is const-qualified but the qualifier is not local. 3719</pre></td></tr> 3720 3721 3722<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> 3723<tr><td colspan="4" class="doc" id="isAnyCharacter0"><pre>Matches QualType nodes that are of character type. 3724 3725Given 3726 void a(char); 3727 void b(wchar_t); 3728 void c(double); 3729functionDecl(hasAnyParameter(hasType(isAnyCharacter()))) 3730matches "a(char)", "b(wchar_t)", but not "c(double)". 3731</pre></td></tr> 3732 3733 3734<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> 3735<tr><td colspan="4" class="doc" id="isAnyPointer0"><pre>Matches QualType nodes that are of any pointer type; this includes 3736the Objective-C object pointer type, which is different despite being 3737syntactically similar. 3738 3739Given 3740 int *i = nullptr; 3741 3742 @interface Foo 3743 @end 3744 Foo *f; 3745 3746 int j; 3747varDecl(hasType(isAnyPointer())) 3748 matches "int *i" and "Foo *f", but not "int j". 3749</pre></td></tr> 3750 3751 3752<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> 3753<tr><td colspan="4" class="doc" id="isConstQualified0"><pre>Matches QualType nodes that are const-qualified, i.e., that 3754include "top-level" const. 3755 3756Given 3757 void a(int); 3758 void b(int const); 3759 void c(const int); 3760 void d(const int*); 3761 void e(int const) {}; 3762functionDecl(hasAnyParameter(hasType(isConstQualified()))) 3763 matches "void b(int const)", "void c(const int)" and 3764 "void e(int const) {}". It does not match d as there 3765 is no top-level const on the parameter type "const int *". 3766</pre></td></tr> 3767 3768 3769<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> 3770<tr><td colspan="4" class="doc" id="isInteger0"><pre>Matches QualType nodes that are of integer type. 3771 3772Given 3773 void a(int); 3774 void b(long); 3775 void c(double); 3776functionDecl(hasAnyParameter(hasType(isInteger()))) 3777matches "a(int)", "b(long)", but not "c(double)". 3778</pre></td></tr> 3779 3780 3781<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> 3782<tr><td colspan="4" class="doc" id="isSignedInteger0"><pre>Matches QualType nodes that are of signed integer type. 3783 3784Given 3785 void a(int); 3786 void b(unsigned long); 3787 void c(double); 3788functionDecl(hasAnyParameter(hasType(isSignedInteger()))) 3789matches "a(int)", but not "b(unsigned long)" and "c(double)". 3790</pre></td></tr> 3791 3792 3793<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> 3794<tr><td colspan="4" class="doc" id="isUnsignedInteger0"><pre>Matches QualType nodes that are of unsigned integer type. 3795 3796Given 3797 void a(int); 3798 void b(unsigned long); 3799 void c(double); 3800functionDecl(hasAnyParameter(hasType(isUnsignedInteger()))) 3801matches "b(unsigned long)", but not "a(int)" and "c(double)". 3802</pre></td></tr> 3803 3804 3805<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> 3806<tr><td colspan="4" class="doc" id="isVolatileQualified0"><pre>Matches QualType nodes that are volatile-qualified, i.e., that 3807include "top-level" volatile. 3808 3809Given 3810 void a(int); 3811 void b(int volatile); 3812 void c(volatile int); 3813 void d(volatile int*); 3814 void e(int volatile) {}; 3815functionDecl(hasAnyParameter(hasType(isVolatileQualified()))) 3816 matches "void b(int volatile)", "void c(volatile int)" and 3817 "void e(int volatile) {}". It does not match d as there 3818 is no top-level volatile on the parameter type "volatile int *". 3819</pre></td></tr> 3820 3821 3822<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> 3823<tr><td colspan="4" class="doc" id="isClass0"><pre>Matches RecordDecl object that are spelled with "class." 3824 3825Example matches C, but not S or U. 3826 struct S {}; 3827 class C {}; 3828 union U {}; 3829</pre></td></tr> 3830 3831 3832<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> 3833<tr><td colspan="4" class="doc" id="isStruct0"><pre>Matches RecordDecl object that are spelled with "struct." 3834 3835Example matches S, but not C or U. 3836 struct S {}; 3837 class C {}; 3838 union U {}; 3839</pre></td></tr> 3840 3841 3842<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> 3843<tr><td colspan="4" class="doc" id="isUnion0"><pre>Matches RecordDecl object that are spelled with "union." 3844 3845Example matches U, but not C or S. 3846 struct S {}; 3847 class C {}; 3848 union U {}; 3849</pre></td></tr> 3850 3851 3852<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> 3853<tr><td colspan="4" class="doc" id="equalsBoundNode0"><pre>Matches if a node equals a previously bound node. 3854 3855Matches a node if it equals the node previously bound to ID. 3856 3857Given 3858 class X { int a; int b; }; 3859cxxRecordDecl( 3860 has(fieldDecl(hasName("a"), hasType(type().bind("t")))), 3861 has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t")))))) 3862 matches the class X, as a and b have the same type. 3863 3864Note that when multiple matches are involved via forEach* matchers, 3865equalsBoundNodes acts as a filter. 3866For example: 3867compoundStmt( 3868 forEachDescendant(varDecl().bind("d")), 3869 forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d")))))) 3870will trigger a match for each combination of variable declaration 3871and reference to that variable declaration within a compound statement. 3872</pre></td></tr> 3873 3874 3875<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> 3876<tr><td colspan="4" class="doc" id="equalsNode1"><pre>Matches if a node equals another node. 3877 3878Stmt has pointer identity in the AST. 3879</pre></td></tr> 3880 3881 3882<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> 3883<tr><td colspan="4" class="doc" id="isExpansionInFileMatching1"><pre>Matches AST nodes that were expanded within files whose name is 3884partially matching a given regex. 3885 3886Example matches Y but not X 3887 (matcher = cxxRecordDecl(isExpansionInFileMatching("AST.*")) 3888 #include "ASTMatcher.h" 3889 class X {}; 3890ASTMatcher.h: 3891 class Y {}; 3892 3893Usable 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>> 3894</pre></td></tr> 3895 3896 3897<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> 3898<tr><td colspan="4" class="doc" id="isExpansionInMainFile1"><pre>Matches AST nodes that were expanded within the main-file. 3899 3900Example matches X but not Y 3901 (matcher = cxxRecordDecl(isExpansionInMainFile()) 3902 #include <Y.h> 3903 class X {}; 3904Y.h: 3905 class Y {}; 3906 3907Usable 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>> 3908</pre></td></tr> 3909 3910 3911<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> 3912<tr><td colspan="4" class="doc" id="isExpansionInSystemHeader1"><pre>Matches AST nodes that were expanded within system-header-files. 3913 3914Example matches Y but not X 3915 (matcher = cxxRecordDecl(isExpansionInSystemHeader()) 3916 #include <SystemHeader.h> 3917 class X {}; 3918SystemHeader.h: 3919 class Y {}; 3920 3921Usable 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>> 3922</pre></td></tr> 3923 3924 3925<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('isOMPStructuredBlock0')"><a name="isOMPStructuredBlock0Anchor">isOMPStructuredBlock</a></td><td></td></tr> 3926<tr><td colspan="4" class="doc" id="isOMPStructuredBlock0"><pre>Matches the Stmt AST node that is marked as being the structured-block 3927of an OpenMP executable directive. 3928 3929Given 3930 3931 #pragma omp parallel 3932 {} 3933 3934``stmt(isOMPStructuredBlock()))`` matches ``{}``. 3935</pre></td></tr> 3936 3937 3938<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> 3939<tr><td colspan="4" class="doc" id="hasSize1"><pre>Matches nodes that have the specified size. 3940 3941Given 3942 int a[42]; 3943 int b[2 * 21]; 3944 int c[41], d[43]; 3945 char *s = "abcd"; 3946 wchar_t *ws = L"abcd"; 3947 char *w = "a"; 3948constantArrayType(hasSize(42)) 3949 matches "int a[42]" and "int b[2 * 21]" 3950stringLiteral(hasSize(4)) 3951 matches "abcd", L"abcd" 3952</pre></td></tr> 3953 3954 3955<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> 3956<tr><td colspan="4" class="doc" id="isDefinition0"><pre>Matches if a declaration has a body attached. 3957 3958Example matches A, va, fa 3959 class A {}; 3960 class B; // Doesn't match, as it has no body. 3961 int va; 3962 extern int vb; // Doesn't match, as it doesn't define the variable. 3963 void fa() {} 3964 void fb(); // Doesn't match, as it has no body. 3965 @interface X 3966 - (void)ma; // Doesn't match, interface is declaration. 3967 @end 3968 @implementation X 3969 - (void)ma {} 3970 @end 3971 3972Usable 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>>, 3973 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html">ObjCMethodDecl</a>> 3974</pre></td></tr> 3975 3976 3977<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> 3978<tr><td colspan="4" class="doc" id="equalsIntegralValue0"><pre>Matches a TemplateArgument of integral type with a given value. 3979 3980Note that 'Value' is a string as the template argument's value is 3981an arbitrary precision integer. 'Value' must be euqal to the canonical 3982representation of that integral value in base 10. 3983 3984Given 3985 template<int T> struct C {}; 3986 C<42> c; 3987classTemplateSpecializationDecl( 3988 hasAnyTemplateArgument(equalsIntegralValue("42"))) 3989 matches the implicit instantiation of C in C<42>. 3990</pre></td></tr> 3991 3992 3993<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> 3994<tr><td colspan="4" class="doc" id="isIntegral0"><pre>Matches a TemplateArgument that is an integral value. 3995 3996Given 3997 template<int T> struct C {}; 3998 C<42> c; 3999classTemplateSpecializationDecl( 4000 hasAnyTemplateArgument(isIntegral())) 4001 matches the implicit instantiation of C in C<42> 4002 with isIntegral() matching 42. 4003</pre></td></tr> 4004 4005 4006<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> 4007<tr><td colspan="4" class="doc" id="templateArgumentCountIs1"><pre>Matches if the number of template arguments equals N. 4008 4009Given 4010 template<typename T> struct C {}; 4011 C<int> c; 4012classTemplateSpecializationDecl(templateArgumentCountIs(1)) 4013 matches C<int>. 4014</pre></td></tr> 4015 4016 4017<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> 4018<tr><td colspan="4" class="doc" id="isExpansionInFileMatching2"><pre>Matches AST nodes that were expanded within files whose name is 4019partially matching a given regex. 4020 4021Example matches Y but not X 4022 (matcher = cxxRecordDecl(isExpansionInFileMatching("AST.*")) 4023 #include "ASTMatcher.h" 4024 class X {}; 4025ASTMatcher.h: 4026 class Y {}; 4027 4028Usable 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>> 4029</pre></td></tr> 4030 4031 4032<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> 4033<tr><td colspan="4" class="doc" id="isExpansionInMainFile2"><pre>Matches AST nodes that were expanded within the main-file. 4034 4035Example matches X but not Y 4036 (matcher = cxxRecordDecl(isExpansionInMainFile()) 4037 #include <Y.h> 4038 class X {}; 4039Y.h: 4040 class Y {}; 4041 4042Usable 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>> 4043</pre></td></tr> 4044 4045 4046<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> 4047<tr><td colspan="4" class="doc" id="isExpansionInSystemHeader2"><pre>Matches AST nodes that were expanded within system-header-files. 4048 4049Example matches Y but not X 4050 (matcher = cxxRecordDecl(isExpansionInSystemHeader()) 4051 #include <SystemHeader.h> 4052 class X {}; 4053SystemHeader.h: 4054 class Y {}; 4055 4056Usable 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>> 4057</pre></td></tr> 4058 4059 4060<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> 4061<tr><td colspan="4" class="doc" id="booleanType0"><pre>Matches type bool. 4062 4063Given 4064 struct S { bool func(); }; 4065functionDecl(returns(booleanType())) 4066 matches "bool func();" 4067</pre></td></tr> 4068 4069 4070<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> 4071<tr><td colspan="4" class="doc" id="equalsBoundNode2"><pre>Matches if a node equals a previously bound node. 4072 4073Matches a node if it equals the node previously bound to ID. 4074 4075Given 4076 class X { int a; int b; }; 4077cxxRecordDecl( 4078 has(fieldDecl(hasName("a"), hasType(type().bind("t")))), 4079 has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t")))))) 4080 matches the class X, as a and b have the same type. 4081 4082Note that when multiple matches are involved via forEach* matchers, 4083equalsBoundNodes acts as a filter. 4084For example: 4085compoundStmt( 4086 forEachDescendant(varDecl().bind("d")), 4087 forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d")))))) 4088will trigger a match for each combination of variable declaration 4089and reference to that variable declaration within a compound statement. 4090</pre></td></tr> 4091 4092 4093<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> 4094<tr><td colspan="4" class="doc" id="equalsNode2"><pre>Matches if a node equals another node. 4095 4096Type has pointer identity in the AST. 4097</pre></td></tr> 4098 4099 4100<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> 4101<tr><td colspan="4" class="doc" id="realFloatingPointType0"><pre>Matches any real floating-point type (float, double, long double). 4102 4103Given 4104 int i; 4105 float f; 4106realFloatingPointType() 4107 matches "float f" but not "int i" 4108</pre></td></tr> 4109 4110 4111<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> 4112<tr><td colspan="4" class="doc" id="voidType0"><pre>Matches type void. 4113 4114Given 4115 struct S { void func(); }; 4116functionDecl(returns(voidType())) 4117 matches "void func();" 4118</pre></td></tr> 4119 4120 4121<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> 4122<tr><td colspan="4" class="doc" id="ofKind0"><pre>Matches unary expressions of a certain kind. 4123 4124Given 4125 int x; 4126 int s = sizeof(x) + alignof(x) 4127unaryExprOrTypeTraitExpr(ofKind(UETT_SizeOf)) 4128 matches sizeof(x) 4129 4130If the matcher is use from clang-query, UnaryExprOrTypeTrait parameter 4131should be passed as a quoted string. e.g., ofKind("UETT_SizeOf"). 4132</pre></td></tr> 4133 4134 4135<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> 4136<tr><td colspan="4" class="doc" id="hasOperatorName1"><pre>Matches the operator Name of operator expressions (binary or 4137unary). 4138 4139Example matches a || b (matcher = binaryOperator(hasOperatorName("||"))) 4140 !(a || b) 4141</pre></td></tr> 4142 4143 4144<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> 4145<tr><td colspan="4" class="doc" id="isArrow1"><pre>Matches member expressions that are called with '->' as opposed 4146to '.'. 4147 4148Member calls on the implicit this pointer match as called with '->'. 4149 4150Given 4151 class Y { 4152 void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; } 4153 template <class T> void f() { this->f<T>(); f<T>(); } 4154 int a; 4155 static int b; 4156 }; 4157 template <class T> 4158 class Z { 4159 void x() { this->m; } 4160 }; 4161memberExpr(isArrow()) 4162 matches this->x, x, y.x, a, this->b 4163cxxDependentScopeMemberExpr(isArrow()) 4164 matches this->m 4165unresolvedMemberExpr(isArrow()) 4166 matches this->f<T>, f<T> 4167</pre></td></tr> 4168 4169 4170<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> 4171<tr><td colspan="4" class="doc" id="hasAutomaticStorageDuration0"><pre>Matches a variable declaration that has automatic storage duration. 4172 4173Example matches x, but not y, z, or a. 4174(matcher = varDecl(hasAutomaticStorageDuration()) 4175void f() { 4176 int x; 4177 static int y; 4178 thread_local int z; 4179} 4180int a; 4181</pre></td></tr> 4182 4183 4184<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> 4185<tr><td colspan="4" class="doc" id="hasGlobalStorage0"><pre>Matches a variable declaration that does not have local storage. 4186 4187Example matches y and z (matcher = varDecl(hasGlobalStorage()) 4188void f() { 4189 int x; 4190 static int y; 4191} 4192int z; 4193</pre></td></tr> 4194 4195 4196<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> 4197<tr><td colspan="4" class="doc" id="hasLocalStorage0"><pre>Matches a variable declaration that has function scope and is a 4198non-static local variable. 4199 4200Example matches x (matcher = varDecl(hasLocalStorage()) 4201void f() { 4202 int x; 4203 static int y; 4204} 4205int z; 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('hasStaticStorageDuration0')"><a name="hasStaticStorageDuration0Anchor">hasStaticStorageDuration</a></td><td></td></tr> 4210<tr><td colspan="4" class="doc" id="hasStaticStorageDuration0"><pre>Matches a variable declaration that has static storage duration. 4211It includes the variable declared at namespace scope and those declared 4212with "static" and "extern" storage class specifiers. 4213 4214void f() { 4215 int x; 4216 static int y; 4217 thread_local int z; 4218} 4219int a; 4220static int b; 4221extern int c; 4222varDecl(hasStaticStorageDuration()) 4223 matches the function declaration y, a, b and c. 4224</pre></td></tr> 4225 4226 4227<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> 4228<tr><td colspan="4" class="doc" id="hasThreadStorageDuration0"><pre>Matches a variable declaration that has thread storage duration. 4229 4230Example matches z, but not x, z, or a. 4231(matcher = varDecl(hasThreadStorageDuration()) 4232void f() { 4233 int x; 4234 static int y; 4235 thread_local int z; 4236} 4237int a; 4238</pre></td></tr> 4239 4240 4241<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> 4242<tr><td colspan="4" class="doc" id="isConstexpr0"><pre>Matches constexpr variable and function declarations, 4243 and if constexpr. 4244 4245Given: 4246 constexpr int foo = 42; 4247 constexpr int bar(); 4248 void baz() { if constexpr(1 > 0) {} } 4249varDecl(isConstexpr()) 4250 matches the declaration of foo. 4251functionDecl(isConstexpr()) 4252 matches the declaration of bar. 4253ifStmt(isConstexpr()) 4254 matches the if statement in baz. 4255</pre></td></tr> 4256 4257 4258<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> 4259<tr><td colspan="4" class="doc" id="isDefinition1"><pre>Matches if a declaration has a body attached. 4260 4261Example matches A, va, fa 4262 class A {}; 4263 class B; // Doesn't match, as it has no body. 4264 int va; 4265 extern int vb; // Doesn't match, as it doesn't define the variable. 4266 void fa() {} 4267 void fb(); // Doesn't match, as it has no body. 4268 @interface X 4269 - (void)ma; // Doesn't match, interface is declaration. 4270 @end 4271 @implementation X 4272 - (void)ma {} 4273 @end 4274 4275Usable 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>>, 4276 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html">ObjCMethodDecl</a>> 4277</pre></td></tr> 4278 4279 4280<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> 4281<tr><td colspan="4" class="doc" id="isExceptionVariable0"><pre>Matches a variable declaration that is an exception variable from 4282a C++ catch block, or an Objective-C statement. 4283 4284Example matches x (matcher = varDecl(isExceptionVariable()) 4285void f(int y) { 4286 try { 4287 } catch (int x) { 4288 } 4289} 4290</pre></td></tr> 4291 4292 4293<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> 4294<tr><td colspan="4" class="doc" id="isExplicitTemplateSpecialization1"><pre>Matches explicit template specializations of function, class, or 4295static member variable template instantiations. 4296 4297Given 4298 template<typename T> void A(T t) { } 4299 template<> void A(int N) { } 4300functionDecl(isExplicitTemplateSpecialization()) 4301 matches the specialization A<int>(). 4302 4303Usable 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>> 4304</pre></td></tr> 4305 4306 4307<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> 4308<tr><td colspan="4" class="doc" id="isExternC1"><pre>Matches extern "C" function or variable declarations. 4309 4310Given: 4311 extern "C" void f() {} 4312 extern "C" { void g() {} } 4313 void h() {} 4314 extern "C" int x = 1; 4315 extern "C" int y = 2; 4316 int z = 3; 4317functionDecl(isExternC()) 4318 matches the declaration of f and g, but not the declaration of h. 4319varDecl(isExternC()) 4320 matches the declaration of x and y, but not the declaration of z. 4321</pre></td></tr> 4322 4323 4324<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> 4325<tr><td colspan="4" class="doc" id="isStaticLocal0"><pre>Matches a static variable with local scope. 4326 4327Example matches y (matcher = varDecl(isStaticLocal())) 4328void f() { 4329 int x; 4330 static int y; 4331} 4332static int z; 4333</pre></td></tr> 4334 4335 4336<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> 4337<tr><td colspan="4" class="doc" id="isStaticStorageClass1"><pre>Matches variable/function declarations that have "static" storage 4338class specifier ("static" keyword) written in the source. 4339 4340Given: 4341 static void f() {} 4342 static int i = 0; 4343 extern int j; 4344 int k; 4345functionDecl(isStaticStorageClass()) 4346 matches the function declaration f. 4347varDecl(isStaticStorageClass()) 4348 matches the variable declaration i. 4349</pre></td></tr> 4350 4351 4352<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> 4353<tr><td colspan="4" class="doc" id="isTemplateInstantiation1"><pre>Matches template instantiations of function, class, or static 4354member variable template instantiations. 4355 4356Given 4357 template <typename T> class X {}; class A {}; X<A> x; 4358or 4359 template <typename T> class X {}; class A {}; template class X<A>; 4360or 4361 template <typename T> class X {}; class A {}; extern template class X<A>; 4362cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) 4363 matches the template instantiation of X<A>. 4364 4365But given 4366 template <typename T> class X {}; class A {}; 4367 template <> class X<A> {}; X<A> x; 4368cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) 4369 does not match, as X<A> is an explicit template specialization. 4370 4371Usable 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>> 4372</pre></td></tr> 4373 4374 4375<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> 4376<tr><td colspan="4" class="doc" id="isInstantiated0"><pre>Matches declarations that are template instantiations or are inside 4377template instantiations. 4378 4379Given 4380 template<typename T> void A(T t) { T i; } 4381 A(0); 4382 A(0U); 4383functionDecl(isInstantiated()) 4384 matches 'A(int) {...};' and 'A(unsigned) {...}'. 4385</pre></td></tr> 4386 4387 4388<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> 4389<tr><td colspan="4" class="doc" id="nullPointerConstant0"><pre>Matches expressions that resolve to a null pointer constant, such as 4390GNU's __null, C++11's nullptr, or C's NULL macro. 4391 4392Given: 4393 void *v1 = NULL; 4394 void *v2 = nullptr; 4395 void *v3 = __null; // GNU extension 4396 char *cp = (char *)0; 4397 int *ip = 0; 4398 int i = 0; 4399expr(nullPointerConstant()) 4400 matches the initializer for v1, v2, v3, cp, and ip. Does not match the 4401 initializer for i. 4402</pre></td></tr> 4403 4404 4405<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> 4406<tr><td colspan="4" class="doc" id="hasAnyName0"><pre>Matches NamedDecl nodes that have any of the specified names. 4407 4408This matcher is only provided as a performance optimization of hasName. 4409 hasAnyName(a, b, c) 4410 is equivalent to, but faster than 4411 anyOf(hasName(a), hasName(b), hasName(c)) 4412</pre></td></tr> 4413 4414 4415<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> 4416<tr><td colspan="4" class="doc" id="hasAnySelector0"><pre>Matches when at least one of the supplied string equals to the 4417Selector.getAsString() 4418 4419 matcher = objCMessageExpr(hasSelector("methodA:", "methodB:")); 4420 matches both of the expressions below: 4421 [myObj methodA:argA]; 4422 [myObj methodB:argB]; 4423</pre></td></tr> 4424 4425 4426<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> 4427<tr><td colspan="4" class="doc" id="isInTemplateInstantiation0"><pre>Matches statements inside of a template instantiation. 4428 4429Given 4430 int j; 4431 template<typename T> void A(T t) { T i; j += 42;} 4432 A(0); 4433 A(0U); 4434declStmt(isInTemplateInstantiation()) 4435 matches 'int i;' and 'unsigned i'. 4436unless(stmt(isInTemplateInstantiation())) 4437 will NOT match j += 42; as it's shared between the template definition and 4438 instantiation. 4439</pre></td></tr> 4440 4441<!--END_NARROWING_MATCHERS --> 4442</table> 4443 4444<!-- ======================================================================= --> 4445<h2 id="traversal-matchers">AST Traversal Matchers</h2> 4446<!-- ======================================================================= --> 4447 4448<p>Traversal matchers specify the relationship to other nodes that are 4449reachable from the current node.</p> 4450 4451<p>Note that there are special traversal matchers (has, hasDescendant, forEach and 4452forEachDescendant) which work on all nodes and allow users to write more generic 4453match expressions.</p> 4454 4455<table> 4456<tr style="text-align:left"><th>Return type</th><th>Name</th><th>Parameters</th></tr> 4457<!-- START_TRAVERSAL_MATCHERS --> 4458 4459<tr><td>Matcher<*></td><td class="name" onclick="toggle('eachOf0')"><a name="eachOf0Anchor">eachOf</a></td><td>Matcher<*>, ..., Matcher<*></td></tr> 4460<tr><td colspan="4" class="doc" id="eachOf0"><pre>Matches if any of the given matchers matches. 4461 4462Unlike anyOf, eachOf will generate a match result for each 4463matching submatcher. 4464 4465For example, in: 4466 class A { int a; int b; }; 4467The matcher: 4468 cxxRecordDecl(eachOf(has(fieldDecl(hasName("a")).bind("v")), 4469 has(fieldDecl(hasName("b")).bind("v")))) 4470will generate two results binding "v", the first of which binds 4471the field declaration of a, the second the field declaration of 4472b. 4473 4474Usable as: Any Matcher 4475</pre></td></tr> 4476 4477 4478<tr><td>Matcher<*></td><td class="name" onclick="toggle('forEachDescendant0')"><a name="forEachDescendant0Anchor">forEachDescendant</a></td><td>Matcher<*></td></tr> 4479<tr><td colspan="4" class="doc" id="forEachDescendant0"><pre>Matches AST nodes that have descendant AST nodes that match the 4480provided matcher. 4481 4482Example matches X, A, A::X, B, B::C, B::C::X 4483 (matcher = cxxRecordDecl(forEachDescendant(cxxRecordDecl(hasName("X"))))) 4484 class X {}; 4485 class A { class X {}; }; // Matches A, because A::X is a class of name 4486 // X inside A. 4487 class B { class C { class X {}; }; }; 4488 4489DescendantT must be an AST base type. 4490 4491As opposed to 'hasDescendant', 'forEachDescendant' will cause a match for 4492each result that matches instead of only on the first one. 4493 4494Note: Recursively combined ForEachDescendant can cause many matches: 4495 cxxRecordDecl(forEachDescendant(cxxRecordDecl( 4496 forEachDescendant(cxxRecordDecl()) 4497 ))) 4498will match 10 times (plus injected class name matches) on: 4499 class A { class B { class C { class D { class E {}; }; }; }; }; 4500 4501Usable as: Any Matcher 4502</pre></td></tr> 4503 4504 4505<tr><td>Matcher<*></td><td class="name" onclick="toggle('forEach0')"><a name="forEach0Anchor">forEach</a></td><td>Matcher<*></td></tr> 4506<tr><td colspan="4" class="doc" id="forEach0"><pre>Matches AST nodes that have child AST nodes that match the 4507provided matcher. 4508 4509Example matches X, Y, Y::X, Z::Y, Z::Y::X 4510 (matcher = cxxRecordDecl(forEach(cxxRecordDecl(hasName("X"))) 4511 class X {}; 4512 class Y { class X {}; }; // Matches Y, because Y::X is a class of name X 4513 // inside Y. 4514 class Z { class Y { class X {}; }; }; // Does not match Z. 4515 4516ChildT must be an AST base type. 4517 4518As opposed to 'has', 'forEach' will cause a match for each result that 4519matches instead of only on the first one. 4520 4521Usable as: Any Matcher 4522</pre></td></tr> 4523 4524 4525<tr><td>Matcher<*></td><td class="name" onclick="toggle('hasAncestor0')"><a name="hasAncestor0Anchor">hasAncestor</a></td><td>Matcher<*></td></tr> 4526<tr><td colspan="4" class="doc" id="hasAncestor0"><pre>Matches AST nodes that have an ancestor that matches the provided 4527matcher. 4528 4529Given 4530void f() { if (true) { int x = 42; } } 4531void g() { for (;;) { int x = 43; } } 4532expr(integerLiteral(hasAncestor(ifStmt()))) matches 42, but not 43. 4533 4534Usable as: Any Matcher 4535</pre></td></tr> 4536 4537 4538<tr><td>Matcher<*></td><td class="name" onclick="toggle('hasDescendant0')"><a name="hasDescendant0Anchor">hasDescendant</a></td><td>Matcher<*></td></tr> 4539<tr><td colspan="4" class="doc" id="hasDescendant0"><pre>Matches AST nodes that have descendant AST nodes that match the 4540provided matcher. 4541 4542Example matches X, Y, Z 4543 (matcher = cxxRecordDecl(hasDescendant(cxxRecordDecl(hasName("X"))))) 4544 class X {}; // Matches X, because X::X is a class of name X inside X. 4545 class Y { class X {}; }; 4546 class Z { class Y { class X {}; }; }; 4547 4548DescendantT must be an AST base type. 4549 4550Usable as: Any Matcher 4551</pre></td></tr> 4552 4553 4554<tr><td>Matcher<*></td><td class="name" onclick="toggle('has0')"><a name="has0Anchor">has</a></td><td>Matcher<*></td></tr> 4555<tr><td colspan="4" class="doc" id="has0"><pre>Matches AST nodes that have child AST nodes that match the 4556provided matcher. 4557 4558Example matches X, Y 4559 (matcher = cxxRecordDecl(has(cxxRecordDecl(hasName("X"))) 4560 class X {}; // Matches X, because X::X is a class of name X inside X. 4561 class Y { class X {}; }; 4562 class Z { class Y { class X {}; }; }; // Does not match Z. 4563 4564ChildT must be an AST base type. 4565 4566Usable as: Any Matcher 4567Note that has is direct matcher, so it also matches things like implicit 4568casts and paren casts. If you are matching with expr then you should 4569probably consider using ignoringParenImpCasts like: 4570has(ignoringParenImpCasts(expr())). 4571</pre></td></tr> 4572 4573 4574<tr><td>Matcher<*></td><td class="name" onclick="toggle('hasParent0')"><a name="hasParent0Anchor">hasParent</a></td><td>Matcher<*></td></tr> 4575<tr><td colspan="4" class="doc" id="hasParent0"><pre>Matches AST nodes that have a parent that matches the provided 4576matcher. 4577 4578Given 4579void f() { for (;;) { int x = 42; if (true) { int x = 43; } } } 4580compoundStmt(hasParent(ifStmt())) matches "{ int x = 43; }". 4581 4582Usable as: Any Matcher 4583</pre></td></tr> 4584 4585 4586<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> 4587<tr><td colspan="4" class="doc" id="hasCondition5"><pre>Matches the condition expression of an if statement, for loop, 4588switch statement or conditional operator. 4589 4590Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true)))) 4591 if (true) {} 4592</pre></td></tr> 4593 4594 4595<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> 4596<tr><td colspan="4" class="doc" id="hasFalseExpression0"><pre>Matches the false branch expression of a conditional operator 4597(binary or ternary). 4598 4599Example matches b 4600 condition ? a : b 4601 condition ?: b 4602</pre></td></tr> 4603 4604 4605<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> 4606<tr><td colspan="4" class="doc" id="hasTrueExpression0"><pre>Matches the true branch expression of a conditional operator. 4607 4608Example 1 (conditional ternary operator): matches a 4609 condition ? a : b 4610 4611Example 2 (conditional binary operator): matches opaqueValueExpr(condition) 4612 condition ?: b 4613</pre></td></tr> 4614 4615 4616<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> 4617<tr><td colspan="4" class="doc" id="hasDeclaration15"><pre>Matches a node if the declaration associated with that node 4618matches the given matcher. 4619 4620The associated declaration is: 4621- for type nodes, the declaration of the underlying type 4622- for CallExpr, the declaration of the callee 4623- for MemberExpr, the declaration of the referenced member 4624- for CXXConstructExpr, the declaration of the constructor 4625- for CXXNewExpr, the declaration of the operator new 4626- for ObjCIvarExpr, the declaration of the ivar 4627 4628For type nodes, hasDeclaration will generally match the declaration of the 4629sugared type. Given 4630 class X {}; 4631 typedef X Y; 4632 Y y; 4633in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 4634typedefDecl. A common use case is to match the underlying, desugared type. 4635This can be achieved by using the hasUnqualifiedDesugaredType matcher: 4636 varDecl(hasType(hasUnqualifiedDesugaredType( 4637 recordType(hasDeclaration(decl()))))) 4638In this matcher, the decl will match the CXXRecordDecl of class X. 4639 4640Usable 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>>, 4641 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>>, 4642 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>>, 4643 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>>, 4644 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>>, 4645 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>>, 4646 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 4647</pre></td></tr> 4648 4649 4650<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> 4651<tr><td colspan="4" class="doc" id="hasBase0"><pre>Matches the base expression of an array subscript expression. 4652 4653Given 4654 int i[5]; 4655 void f() { i[1] = 42; } 4656arraySubscriptExpression(hasBase(implicitCastExpr( 4657 hasSourceExpression(declRefExpr())))) 4658 matches i[1] with the declRefExpr() matching i 4659</pre></td></tr> 4660 4661 4662<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> 4663<tr><td colspan="4" class="doc" id="hasIndex0"><pre>Matches the index expression of an array subscript expression. 4664 4665Given 4666 int i[5]; 4667 void f() { i[1] = 42; } 4668arraySubscriptExpression(hasIndex(integerLiteral())) 4669 matches i[1] with the integerLiteral() matching 1 4670</pre></td></tr> 4671 4672 4673<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> 4674<tr><td colspan="4" class="doc" id="hasLHS1"><pre>Matches the left hand side of binary operator expressions. 4675 4676Example matches a (matcher = binaryOperator(hasLHS())) 4677 a || b 4678</pre></td></tr> 4679 4680 4681<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> 4682<tr><td colspan="4" class="doc" id="hasRHS1"><pre>Matches the right hand side of binary operator expressions. 4683 4684Example matches b (matcher = binaryOperator(hasRHS())) 4685 a || b 4686</pre></td></tr> 4687 4688 4689<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> 4690<tr><td colspan="4" class="doc" id="hasElementType0"><pre>Matches arrays and C99 complex types that have a specific element 4691type. 4692 4693Given 4694 struct A {}; 4695 A a[7]; 4696 int b[7]; 4697arrayType(hasElementType(builtinType())) 4698 matches "int b[7]" 4699 4700Usable 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>> 4701</pre></td></tr> 4702 4703 4704<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> 4705<tr><td colspan="4" class="doc" id="hasValueType0"><pre>Matches atomic types with a specific value type. 4706 4707Given 4708 _Atomic(int) i; 4709 _Atomic(float) f; 4710atomicType(hasValueType(isInteger())) 4711 matches "_Atomic(int) i" 4712 4713Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AtomicType.html">AtomicType</a>> 4714</pre></td></tr> 4715 4716 4717<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> 4718<tr><td colspan="4" class="doc" id="hasDeducedType0"><pre>Matches AutoType nodes where the deduced type is a specific type. 4719 4720Note: There is no TypeLoc for the deduced type and thus no 4721getDeducedLoc() matcher. 4722 4723Given 4724 auto a = 1; 4725 auto b = 2.0; 4726autoType(hasDeducedType(isInteger())) 4727 matches "auto a" 4728 4729Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AutoType.html">AutoType</a>> 4730</pre></td></tr> 4731 4732 4733<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> 4734<tr><td colspan="4" class="doc" id="hasEitherOperand0"><pre>Matches if either the left hand side or the right hand side of a 4735binary operator matches. 4736</pre></td></tr> 4737 4738 4739<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> 4740<tr><td colspan="4" class="doc" id="hasLHS0"><pre>Matches the left hand side of binary operator expressions. 4741 4742Example matches a (matcher = binaryOperator(hasLHS())) 4743 a || b 4744</pre></td></tr> 4745 4746 4747<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> 4748<tr><td colspan="4" class="doc" id="hasRHS0"><pre>Matches the right hand side of binary operator expressions. 4749 4750Example matches b (matcher = binaryOperator(hasRHS())) 4751 a || b 4752</pre></td></tr> 4753 4754 4755<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> 4756<tr><td colspan="4" class="doc" id="hasAnyParameter2"><pre>Matches any parameter of a function or an ObjC method declaration or a 4757block. 4758 4759Does not match the 'this' parameter of a method. 4760 4761Given 4762 class X { void f(int x, int y, int z) {} }; 4763cxxMethodDecl(hasAnyParameter(hasName("y"))) 4764 matches f(int x, int y, int z) {} 4765with hasAnyParameter(...) 4766 matching int y 4767 4768For ObjectiveC, given 4769 @interface I - (void) f:(int) y; @end 4770 4771the matcher objcMethodDecl(hasAnyParameter(hasName("y"))) 4772matches the declaration of method f with hasParameter 4773matching y. 4774 4775For blocks, given 4776 b = ^(int y) { printf("%d", y) }; 4777 4778the matcher blockDecl(hasAnyParameter(hasName("y"))) 4779matches the declaration of the block b with hasParameter 4780matching y. 4781</pre></td></tr> 4782 4783 4784<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> 4785<tr><td colspan="4" class="doc" id="hasParameter2"><pre>Matches the n'th parameter of a function or an ObjC method 4786declaration or a block. 4787 4788Given 4789 class X { void f(int x) {} }; 4790cxxMethodDecl(hasParameter(0, hasType(varDecl()))) 4791 matches f(int x) {} 4792with hasParameter(...) 4793 matching int x 4794 4795For ObjectiveC, given 4796 @interface I - (void) f:(int) y; @end 4797 4798the matcher objcMethodDecl(hasParameter(0, hasName("y"))) 4799matches the declaration of method f with hasParameter 4800matching y. 4801</pre></td></tr> 4802 4803 4804<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> 4805<tr><td colspan="4" class="doc" id="pointee0"><pre>Narrows PointerType (and similar) matchers to those where the 4806pointee matches a given matcher. 4807 4808Given 4809 int *a; 4810 int const *b; 4811 float const *f; 4812pointerType(pointee(isConstQualified(), isInteger())) 4813 matches "int const *b" 4814 4815Usable 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>>, 4816 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>> 4817</pre></td></tr> 4818 4819 4820<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> 4821<tr><td colspan="4" class="doc" id="forEachArgumentWithParam1"><pre>Matches all arguments and their respective ParmVarDecl. 4822 4823Given 4824 void f(int i); 4825 int y; 4826 f(y); 4827callExpr( 4828 forEachArgumentWithParam( 4829 declRefExpr(to(varDecl(hasName("y")))), 4830 parmVarDecl(hasType(isInteger())) 4831)) 4832 matches f(y); 4833with declRefExpr(...) 4834 matching int y 4835and parmVarDecl(...) 4836 matching int i 4837</pre></td></tr> 4838 4839 4840<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> 4841<tr><td colspan="4" class="doc" id="hasAnyArgument1"><pre>Matches any argument of a call expression or a constructor call 4842expression, or an ObjC-message-send expression. 4843 4844Given 4845 void x(int, int, int) { int y; x(1, y, 42); } 4846callExpr(hasAnyArgument(declRefExpr())) 4847 matches x(1, y, 42) 4848with hasAnyArgument(...) 4849 matching y 4850 4851For ObjectiveC, given 4852 @interface I - (void) f:(int) y; @end 4853 void foo(I *i) { [i f:12]; } 4854objcMessageExpr(hasAnyArgument(integerLiteral(equals(12)))) 4855 matches [i f:12] 4856</pre></td></tr> 4857 4858 4859<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> 4860<tr><td colspan="4" class="doc" id="hasArgument1"><pre>Matches the n'th argument of a call expression or a constructor 4861call expression. 4862 4863Example matches y in x(y) 4864 (matcher = callExpr(hasArgument(0, declRefExpr()))) 4865 void x(int) { int y; x(y); } 4866</pre></td></tr> 4867 4868 4869<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> 4870<tr><td colspan="4" class="doc" id="hasDeclaration13"><pre>Matches a node if the declaration associated with that node 4871matches the given matcher. 4872 4873The associated declaration is: 4874- for type nodes, the declaration of the underlying type 4875- for CallExpr, the declaration of the callee 4876- for MemberExpr, the declaration of the referenced member 4877- for CXXConstructExpr, the declaration of the constructor 4878- for CXXNewExpr, the declaration of the operator new 4879- for ObjCIvarExpr, the declaration of the ivar 4880 4881For type nodes, hasDeclaration will generally match the declaration of the 4882sugared type. Given 4883 class X {}; 4884 typedef X Y; 4885 Y y; 4886in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 4887typedefDecl. A common use case is to match the underlying, desugared type. 4888This can be achieved by using the hasUnqualifiedDesugaredType matcher: 4889 varDecl(hasType(hasUnqualifiedDesugaredType( 4890 recordType(hasDeclaration(decl()))))) 4891In this matcher, the decl will match the CXXRecordDecl of class X. 4892 4893Usable 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>>, 4894 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>>, 4895 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>>, 4896 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>>, 4897 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>>, 4898 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>>, 4899 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 4900</pre></td></tr> 4901 4902 4903<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> 4904<tr><td colspan="4" class="doc" id="forEachConstructorInitializer0"><pre>Matches each constructor initializer in a constructor definition. 4905 4906Given 4907 class A { A() : i(42), j(42) {} int i; int j; }; 4908cxxConstructorDecl(forEachConstructorInitializer( 4909 forField(decl().bind("x")) 4910)) 4911 will trigger two matches, binding for 'i' and 'j' respectively. 4912</pre></td></tr> 4913 4914 4915<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> 4916<tr><td colspan="4" class="doc" id="hasAnyConstructorInitializer0"><pre>Matches a constructor initializer. 4917 4918Given 4919 struct Foo { 4920 Foo() : foo_(1) { } 4921 int foo_; 4922 }; 4923cxxRecordDecl(has(cxxConstructorDecl( 4924 hasAnyConstructorInitializer(anything()) 4925))) 4926 record matches Foo, hasAnyConstructorInitializer matches foo_(1) 4927</pre></td></tr> 4928 4929 4930<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> 4931<tr><td colspan="4" class="doc" id="forField0"><pre>Matches the field declaration of a constructor initializer. 4932 4933Given 4934 struct Foo { 4935 Foo() : foo_(1) { } 4936 int foo_; 4937 }; 4938cxxRecordDecl(has(cxxConstructorDecl(hasAnyConstructorInitializer( 4939 forField(hasName("foo_")))))) 4940 matches Foo 4941with forField matching foo_ 4942</pre></td></tr> 4943 4944 4945<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> 4946<tr><td colspan="4" class="doc" id="withInitializer0"><pre>Matches the initializer expression of a constructor initializer. 4947 4948Given 4949 struct Foo { 4950 Foo() : foo_(1) { } 4951 int foo_; 4952 }; 4953cxxRecordDecl(has(cxxConstructorDecl(hasAnyConstructorInitializer( 4954 withInitializer(integerLiteral(equals(1))))))) 4955 matches Foo 4956with withInitializer matching (1) 4957</pre></td></tr> 4958 4959 4960<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> 4961<tr><td colspan="4" class="doc" id="hasObjectExpression2"><pre>Matches a member expression where the object expression is matched by a 4962given matcher. Implicit object expressions are included; that is, it matches 4963use of implicit `this`. 4964 4965Given 4966 struct X { 4967 int m; 4968 int f(X x) { x.m; return m; } 4969 }; 4970memberExpr(hasObjectExpression(hasType(cxxRecordDecl(hasName("X"))))) 4971 matches `x.m`, but not `m`; however, 4972memberExpr(hasObjectExpression(hasType(pointsTo( 4973 cxxRecordDecl(hasName("X")))))) 4974 matches `m` (aka. `this->m`), but not `x.m`. 4975</pre></td></tr> 4976 4977 4978<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> 4979<tr><td colspan="4" class="doc" id="hasBody3"><pre>Matches a 'for', 'while', 'do while' statement or a function 4980definition that has a given body. 4981 4982Given 4983 for (;;) {} 4984hasBody(compoundStmt()) 4985 matches 'for (;;) {}' 4986with compoundStmt() 4987 matching '{}' 4988</pre></td></tr> 4989 4990 4991<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> 4992<tr><td colspan="4" class="doc" id="hasLoopVariable0"><pre>Matches the initialization statement of a for loop. 4993 4994Example: 4995 forStmt(hasLoopVariable(anything())) 4996matches 'int x' in 4997 for (int x : a) { } 4998</pre></td></tr> 4999 5000 5001<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> 5002<tr><td colspan="4" class="doc" id="hasRangeInit0"><pre>Matches the range initialization statement of a for loop. 5003 5004Example: 5005 forStmt(hasRangeInit(anything())) 5006matches 'a' in 5007 for (int x : a) { } 5008</pre></td></tr> 5009 5010 5011<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> 5012<tr><td colspan="4" class="doc" id="onImplicitObjectArgument0"><pre>Matches on the implicit object argument of a member call expression. Unlike 5013`on`, matches the argument directly without stripping away anything. 5014 5015Given 5016 class Y { public: void m(); }; 5017 Y g(); 5018 class X : public Y { void g(); }; 5019 void z(Y y, X x) { y.m(); x.m(); x.g(); (g()).m(); } 5020cxxMemberCallExpr(onImplicitObjectArgument(hasType( 5021 cxxRecordDecl(hasName("Y"))))) 5022 matches `y.m()`, `x.m()` and (g()).m(), but not `x.g()`. 5023cxxMemberCallExpr(on(callExpr())) 5024 does not match `(g()).m()`, because the parens are not ignored. 5025 5026FIXME: Overload to allow directly matching types? 5027</pre></td></tr> 5028 5029 5030<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> 5031<tr><td colspan="4" class="doc" id="on0"><pre>Matches on the implicit object argument of a member call expression, after 5032stripping off any parentheses or implicit casts. 5033 5034Given 5035 class Y { public: void m(); }; 5036 Y g(); 5037 class X : public Y {}; 5038 void z(Y y, X x) { y.m(); (g()).m(); x.m(); } 5039cxxMemberCallExpr(on(hasType(cxxRecordDecl(hasName("Y"))))) 5040 matches `y.m()` and `(g()).m()`. 5041cxxMemberCallExpr(on(hasType(cxxRecordDecl(hasName("X"))))) 5042 matches `x.m()`. 5043cxxMemberCallExpr(on(callExpr())) 5044 matches `(g()).m()`. 5045 5046FIXME: Overload to allow directly matching types? 5047</pre></td></tr> 5048 5049 5050<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> 5051<tr><td colspan="4" class="doc" id="thisPointerType1"><pre>Overloaded to match the type's declaration. 5052</pre></td></tr> 5053 5054 5055<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> 5056<tr><td colspan="4" class="doc" id="thisPointerType0"><pre>Matches if the type of the expression's implicit object argument either 5057matches the InnerMatcher, or is a pointer to a type that matches the 5058InnerMatcher. 5059 5060Given 5061 class Y { public: void m(); }; 5062 class X : public Y { void g(); }; 5063 void z() { Y y; y.m(); Y *p; p->m(); X x; x.m(); x.g(); } 5064cxxMemberCallExpr(thisPointerType(hasDeclaration( 5065 cxxRecordDecl(hasName("Y"))))) 5066 matches `y.m()`, `p->m()` and `x.m()`. 5067cxxMemberCallExpr(thisPointerType(hasDeclaration( 5068 cxxRecordDecl(hasName("X"))))) 5069 matches `x.g()`. 5070</pre></td></tr> 5071 5072 5073<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> 5074<tr><td colspan="4" class="doc" id="forEachOverridden0"><pre>Matches each method overridden by the given method. This matcher may 5075produce multiple matches. 5076 5077Given 5078 class A { virtual void f(); }; 5079 class B : public A { void f(); }; 5080 class C : public B { void f(); }; 5081cxxMethodDecl(ofClass(hasName("C")), 5082 forEachOverridden(cxxMethodDecl().bind("b"))).bind("d") 5083 matches once, with "b" binding "A::f" and "d" binding "C::f" (Note 5084 that B::f is not overridden by C::f). 5085 5086The check can produce multiple matches in case of multiple inheritance, e.g. 5087 class A1 { virtual void f(); }; 5088 class A2 { virtual void f(); }; 5089 class C : public A1, public A2 { void f(); }; 5090cxxMethodDecl(ofClass(hasName("C")), 5091 forEachOverridden(cxxMethodDecl().bind("b"))).bind("d") 5092 matches twice, once with "b" binding "A1::f" and "d" binding "C::f", and 5093 once with "b" binding "A2::f" and "d" binding "C::f". 5094</pre></td></tr> 5095 5096 5097<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> 5098<tr><td colspan="4" class="doc" id="ofClass0"><pre>Matches the class declaration that the given method declaration 5099belongs to. 5100 5101FIXME: Generalize this for other kinds of declarations. 5102FIXME: What other kind of declarations would we need to generalize 5103this to? 5104 5105Example matches A() in the last line 5106 (matcher = cxxConstructExpr(hasDeclaration(cxxMethodDecl( 5107 ofClass(hasName("A")))))) 5108 class A { 5109 public: 5110 A(); 5111 }; 5112 A a = A(); 5113</pre></td></tr> 5114 5115 5116<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> 5117<tr><td colspan="4" class="doc" id="hasArraySize0"><pre>Matches array new expressions with a given array size. 5118 5119Given: 5120 MyClass *p1 = new MyClass[10]; 5121cxxNewExpr(hasArraySize(intgerLiteral(equals(10)))) 5122 matches the expression 'new MyClass[10]'. 5123</pre></td></tr> 5124 5125 5126<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> 5127<tr><td colspan="4" class="doc" id="hasDeclaration12"><pre>Matches a node if the declaration associated with that node 5128matches the given matcher. 5129 5130The associated declaration is: 5131- for type nodes, the declaration of the underlying type 5132- for CallExpr, the declaration of the callee 5133- for MemberExpr, the declaration of the referenced member 5134- for CXXConstructExpr, the declaration of the constructor 5135- for CXXNewExpr, the declaration of the operator new 5136- for ObjCIvarExpr, the declaration of the ivar 5137 5138For type nodes, hasDeclaration will generally match the declaration of the 5139sugared type. Given 5140 class X {}; 5141 typedef X Y; 5142 Y y; 5143in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 5144typedefDecl. A common use case is to match the underlying, desugared type. 5145This can be achieved by using the hasUnqualifiedDesugaredType matcher: 5146 varDecl(hasType(hasUnqualifiedDesugaredType( 5147 recordType(hasDeclaration(decl()))))) 5148In this matcher, the decl will match the CXXRecordDecl of class X. 5149 5150Usable 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>>, 5151 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>>, 5152 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>>, 5153 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>>, 5154 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>>, 5155 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>>, 5156 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 5157</pre></td></tr> 5158 5159 5160<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> 5161<tr><td colspan="4" class="doc" id="hasMethod0"><pre>Matches the first method of a class or struct that satisfies InnerMatcher. 5162 5163Given: 5164 class A { void func(); }; 5165 class B { void member(); }; 5166 5167cxxRecordDecl(hasMethod(hasName("func"))) matches the declaration of 5168A but not B. 5169</pre></td></tr> 5170 5171 5172<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> 5173<tr><td colspan="4" class="doc" id="isDerivedFrom0"><pre>Matches C++ classes that are directly or indirectly derived from 5174a class matching Base. 5175 5176Note that a class is not considered to be derived from itself. 5177 5178Example matches Y, Z, C (Base == hasName("X")) 5179 class X; 5180 class Y : public X {}; // directly derived 5181 class Z : public Y {}; // indirectly derived 5182 typedef X A; 5183 typedef A B; 5184 class C : public B {}; // derived from a typedef of X 5185 5186In the following example, Bar matches isDerivedFrom(hasName("X")): 5187 class Foo; 5188 typedef Foo X; 5189 class Bar : public Foo {}; // derived from a type that X is a typedef of 5190</pre></td></tr> 5191 5192 5193<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> 5194<tr><td colspan="4" class="doc" id="isSameOrDerivedFrom0"><pre>Similar to isDerivedFrom(), but also matches classes that directly 5195match Base. 5196</pre></td></tr> 5197 5198 5199<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> 5200<tr><td colspan="4" class="doc" id="hasAnyArgument2"><pre>Matches any argument of a call expression or a constructor call 5201expression, or an ObjC-message-send expression. 5202 5203Given 5204 void x(int, int, int) { int y; x(1, y, 42); } 5205callExpr(hasAnyArgument(declRefExpr())) 5206 matches x(1, y, 42) 5207with hasAnyArgument(...) 5208 matching y 5209 5210For ObjectiveC, given 5211 @interface I - (void) f:(int) y; @end 5212 void foo(I *i) { [i f:12]; } 5213objcMessageExpr(hasAnyArgument(integerLiteral(equals(12)))) 5214 matches [i f:12] 5215</pre></td></tr> 5216 5217 5218<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> 5219<tr><td colspan="4" class="doc" id="callee1"><pre>Matches if the call expression's callee's declaration matches the 5220given matcher. 5221 5222Example matches y.x() (matcher = callExpr(callee( 5223 cxxMethodDecl(hasName("x"))))) 5224 class Y { public: void x(); }; 5225 void z() { Y y; y.x(); } 5226</pre></td></tr> 5227 5228 5229<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> 5230<tr><td colspan="4" class="doc" id="callee0"><pre>Matches if the call expression's callee expression matches. 5231 5232Given 5233 class Y { void x() { this->x(); x(); Y y; y.x(); } }; 5234 void f() { f(); } 5235callExpr(callee(expr())) 5236 matches this->x(), x(), y.x(), f() 5237with callee(...) 5238 matching this->x, x, y.x, f respectively 5239 5240Note: Callee cannot take the more general internal::Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> 5241because this introduces ambiguous overloads with calls to Callee taking a 5242internal::Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, as the matcher hierarchy is purely 5243implemented in terms of implicit casts. 5244</pre></td></tr> 5245 5246 5247<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> 5248<tr><td colspan="4" class="doc" id="forEachArgumentWithParam0"><pre>Matches all arguments and their respective ParmVarDecl. 5249 5250Given 5251 void f(int i); 5252 int y; 5253 f(y); 5254callExpr( 5255 forEachArgumentWithParam( 5256 declRefExpr(to(varDecl(hasName("y")))), 5257 parmVarDecl(hasType(isInteger())) 5258)) 5259 matches f(y); 5260with declRefExpr(...) 5261 matching int y 5262and parmVarDecl(...) 5263 matching int i 5264</pre></td></tr> 5265 5266 5267<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> 5268<tr><td colspan="4" class="doc" id="hasAnyArgument0"><pre>Matches any argument of a call expression or a constructor call 5269expression, or an ObjC-message-send expression. 5270 5271Given 5272 void x(int, int, int) { int y; x(1, y, 42); } 5273callExpr(hasAnyArgument(declRefExpr())) 5274 matches x(1, y, 42) 5275with hasAnyArgument(...) 5276 matching y 5277 5278For ObjectiveC, given 5279 @interface I - (void) f:(int) y; @end 5280 void foo(I *i) { [i f:12]; } 5281objcMessageExpr(hasAnyArgument(integerLiteral(equals(12)))) 5282 matches [i f:12] 5283</pre></td></tr> 5284 5285 5286<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> 5287<tr><td colspan="4" class="doc" id="hasArgument0"><pre>Matches the n'th argument of a call expression or a constructor 5288call expression. 5289 5290Example matches y in x(y) 5291 (matcher = callExpr(hasArgument(0, declRefExpr()))) 5292 void x(int) { int y; x(y); } 5293</pre></td></tr> 5294 5295 5296<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> 5297<tr><td colspan="4" class="doc" id="hasDeclaration14"><pre>Matches a node if the declaration associated with that node 5298matches the given matcher. 5299 5300The associated declaration is: 5301- for type nodes, the declaration of the underlying type 5302- for CallExpr, the declaration of the callee 5303- for MemberExpr, the declaration of the referenced member 5304- for CXXConstructExpr, the declaration of the constructor 5305- for CXXNewExpr, the declaration of the operator new 5306- for ObjCIvarExpr, the declaration of the ivar 5307 5308For type nodes, hasDeclaration will generally match the declaration of the 5309sugared type. Given 5310 class X {}; 5311 typedef X Y; 5312 Y y; 5313in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 5314typedefDecl. A common use case is to match the underlying, desugared type. 5315This can be achieved by using the hasUnqualifiedDesugaredType matcher: 5316 varDecl(hasType(hasUnqualifiedDesugaredType( 5317 recordType(hasDeclaration(decl()))))) 5318In this matcher, the decl will match the CXXRecordDecl of class X. 5319 5320Usable 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>>, 5321 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>>, 5322 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>>, 5323 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>>, 5324 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>>, 5325 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>>, 5326 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 5327</pre></td></tr> 5328 5329 5330<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> 5331<tr><td colspan="4" class="doc" id="hasCaseConstant0"><pre>If the given case statement does not use the GNU case range 5332extension, matches the constant given in the statement. 5333 5334Given 5335 switch (1) { case 1: case 1+1: case 3 ... 4: ; } 5336caseStmt(hasCaseConstant(integerLiteral())) 5337 matches "case 1:" 5338</pre></td></tr> 5339 5340 5341<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> 5342<tr><td colspan="4" class="doc" id="hasSourceExpression0"><pre>Matches if the cast's source expression 5343or opaque value's source expression matches the given matcher. 5344 5345Example 1: matches "a string" 5346(matcher = castExpr(hasSourceExpression(cxxConstructExpr()))) 5347class URL { URL(string); }; 5348URL url = "a string"; 5349 5350Example 2: matches 'b' (matcher = 5351opaqueValueExpr(hasSourceExpression(implicitCastExpr(declRefExpr()))) 5352int a = b ?: 1; 5353</pre></td></tr> 5354 5355 5356<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> 5357<tr><td colspan="4" class="doc" id="hasAnyTemplateArgument0"><pre>Matches classTemplateSpecializations, templateSpecializationType and 5358functionDecl that have at least one TemplateArgument matching the given 5359InnerMatcher. 5360 5361Given 5362 template<typename T> class A {}; 5363 template<> class A<double> {}; 5364 A<int> a; 5365 5366 template<typename T> f() {}; 5367 void func() { f<int>(); }; 5368 5369classTemplateSpecializationDecl(hasAnyTemplateArgument( 5370 refersToType(asString("int")))) 5371 matches the specialization A<int> 5372 5373functionDecl(hasAnyTemplateArgument(refersToType(asString("int")))) 5374 matches the specialization f<int> 5375</pre></td></tr> 5376 5377 5378<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> 5379<tr><td colspan="4" class="doc" id="hasSpecializedTemplate0"><pre>Matches the specialized template of a specialization declaration. 5380 5381Given 5382 template<typename T> class A {}; #1 5383 template<> class A<int> {}; #2 5384classTemplateSpecializationDecl(hasSpecializedTemplate(classTemplateDecl())) 5385 matches '#2' with classTemplateDecl() matching the class template 5386 declaration of 'A' at #1. 5387</pre></td></tr> 5388 5389 5390<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> 5391<tr><td colspan="4" class="doc" id="hasTemplateArgument0"><pre>Matches classTemplateSpecializations, templateSpecializationType and 5392functionDecl where the n'th TemplateArgument matches the given InnerMatcher. 5393 5394Given 5395 template<typename T, typename U> class A {}; 5396 A<bool, int> b; 5397 A<int, bool> c; 5398 5399 template<typename T> void f() {} 5400 void func() { f<int>(); }; 5401classTemplateSpecializationDecl(hasTemplateArgument( 5402 1, refersToType(asString("int")))) 5403 matches the specialization A<bool, int> 5404 5405functionDecl(hasTemplateArgument(0, refersToType(asString("int")))) 5406 matches the specialization f<int> 5407</pre></td></tr> 5408 5409 5410<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> 5411<tr><td colspan="4" class="doc" id="hasElementType1"><pre>Matches arrays and C99 complex types that have a specific element 5412type. 5413 5414Given 5415 struct A {}; 5416 A a[7]; 5417 int b[7]; 5418arrayType(hasElementType(builtinType())) 5419 matches "int b[7]" 5420 5421Usable 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>> 5422</pre></td></tr> 5423 5424 5425<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> 5426<tr><td colspan="4" class="doc" id="hasAnySubstatement0"><pre>Matches compound statements where at least one substatement matches 5427a given matcher. Also matches StmtExprs that have CompoundStmt as children. 5428 5429Given 5430 { {}; 1+2; } 5431hasAnySubstatement(compoundStmt()) 5432 matches '{ {}; 1+2; }' 5433with compoundStmt() 5434 matching '{}' 5435</pre></td></tr> 5436 5437 5438<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> 5439<tr><td colspan="4" class="doc" id="hasDecayedType0"><pre>Matches the decayed type, whos decayed type matches InnerMatcher 5440</pre></td></tr> 5441 5442 5443<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> 5444<tr><td colspan="4" class="doc" id="hasDeclaration11"><pre>Matches a node if the declaration associated with that node 5445matches the given matcher. 5446 5447The associated declaration is: 5448- for type nodes, the declaration of the underlying type 5449- for CallExpr, the declaration of the callee 5450- for MemberExpr, the declaration of the referenced member 5451- for CXXConstructExpr, the declaration of the constructor 5452- for CXXNewExpr, the declaration of the operator new 5453- for ObjCIvarExpr, the declaration of the ivar 5454 5455For type nodes, hasDeclaration will generally match the declaration of the 5456sugared type. Given 5457 class X {}; 5458 typedef X Y; 5459 Y y; 5460in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 5461typedefDecl. A common use case is to match the underlying, desugared type. 5462This can be achieved by using the hasUnqualifiedDesugaredType matcher: 5463 varDecl(hasType(hasUnqualifiedDesugaredType( 5464 recordType(hasDeclaration(decl()))))) 5465In this matcher, the decl will match the CXXRecordDecl of class X. 5466 5467Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, 5468 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, 5469 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, 5470 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, 5471 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, 5472 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, 5473 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 5474</pre></td></tr> 5475 5476 5477<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_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> 5478<tr><td colspan="4" class="doc" id="throughUsingDecl0"><pre>Matches a DeclRefExpr that refers to a declaration through a 5479specific using shadow declaration. 5480 5481Given 5482 namespace a { void f() {} } 5483 using a::f; 5484 void g() { 5485 f(); // Matches this .. 5486 a::f(); // .. but not this. 5487 } 5488declRefExpr(throughUsingDecl(anything())) 5489 matches f() 5490</pre></td></tr> 5491 5492 5493<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> 5494<tr><td colspan="4" class="doc" id="to0"><pre>Matches a DeclRefExpr that refers to a declaration that matches the 5495specified matcher. 5496 5497Example matches x in if(x) 5498 (matcher = declRefExpr(to(varDecl(hasName("x"))))) 5499 bool x; 5500 if (x) {} 5501</pre></td></tr> 5502 5503 5504<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> 5505<tr><td colspan="4" class="doc" id="containsDeclaration0"><pre>Matches the n'th declaration of a declaration statement. 5506 5507Note that this does not work for global declarations because the AST 5508breaks up multiple-declaration DeclStmt's into multiple single-declaration 5509DeclStmt's. 5510Example: Given non-global declarations 5511 int a, b = 0; 5512 int c; 5513 int d = 2, e; 5514declStmt(containsDeclaration( 5515 0, varDecl(hasInitializer(anything())))) 5516 matches only 'int d = 2, e;', and 5517declStmt(containsDeclaration(1, varDecl())) 5518 matches 'int a, b = 0' as well as 'int d = 2, e;' 5519 but 'int c;' is not matched. 5520</pre></td></tr> 5521 5522 5523<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> 5524<tr><td colspan="4" class="doc" id="hasSingleDecl0"><pre>Matches the Decl of a DeclStmt which has a single declaration. 5525 5526Given 5527 int a, b; 5528 int c; 5529declStmt(hasSingleDecl(anything())) 5530 matches 'int c;' but not 'int a, b;'. 5531</pre></td></tr> 5532 5533 5534<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> 5535<tr><td colspan="4" class="doc" id="hasTypeLoc0"><pre>Matches if the type location of the declarator decl's type matches 5536the inner matcher. 5537 5538Given 5539 int x; 5540declaratorDecl(hasTypeLoc(loc(asString("int")))) 5541 matches int x 5542</pre></td></tr> 5543 5544 5545<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> 5546<tr><td colspan="4" class="doc" id="hasDeclContext0"><pre>Matches declarations whose declaration context, interpreted as a 5547Decl, matches InnerMatcher. 5548 5549Given 5550 namespace N { 5551 namespace M { 5552 class D {}; 5553 } 5554 } 5555 5556cxxRcordDecl(hasDeclContext(namedDecl(hasName("M")))) matches the 5557declaration of class D. 5558</pre></td></tr> 5559 5560 5561<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> 5562<tr><td colspan="4" class="doc" id="hasUnderlyingType0"><pre>Matches DecltypeType nodes to find out the underlying type. 5563 5564Given 5565 decltype(1) a = 1; 5566 decltype(2.0) b = 2.0; 5567decltypeType(hasUnderlyingType(isInteger())) 5568 matches the type of "a" 5569 5570Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DecltypeType.html">DecltypeType</a>> 5571</pre></td></tr> 5572 5573 5574<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> 5575<tr><td colspan="4" class="doc" id="hasBody0"><pre>Matches a 'for', 'while', 'do while' statement or a function 5576definition that has a given body. 5577 5578Given 5579 for (;;) {} 5580hasBody(compoundStmt()) 5581 matches 'for (;;) {}' 5582with compoundStmt() 5583 matching '{}' 5584</pre></td></tr> 5585 5586 5587<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> 5588<tr><td colspan="4" class="doc" id="hasCondition3"><pre>Matches the condition expression of an if statement, for loop, 5589switch statement or conditional operator. 5590 5591Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true)))) 5592 if (true) {} 5593</pre></td></tr> 5594 5595 5596<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> 5597<tr><td colspan="4" class="doc" id="hasQualifier0"><pre>Matches ElaboratedTypes whose qualifier, a NestedNameSpecifier, 5598matches InnerMatcher if the qualifier exists. 5599 5600Given 5601 namespace N { 5602 namespace M { 5603 class D {}; 5604 } 5605 } 5606 N::M::D d; 5607 5608elaboratedType(hasQualifier(hasPrefix(specifiesNamespace(hasName("N")))) 5609matches the type of the variable declaration of d. 5610</pre></td></tr> 5611 5612 5613<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> 5614<tr><td colspan="4" class="doc" id="namesType0"><pre>Matches ElaboratedTypes whose named type matches InnerMatcher. 5615 5616Given 5617 namespace N { 5618 namespace M { 5619 class D {}; 5620 } 5621 } 5622 N::M::D d; 5623 5624elaboratedType(namesType(recordType( 5625hasDeclaration(namedDecl(hasName("D")))))) matches the type of the variable 5626declaration of d. 5627</pre></td></tr> 5628 5629 5630<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> 5631<tr><td colspan="4" class="doc" id="hasDeclaration10"><pre>Matches a node if the declaration associated with that node 5632matches the given matcher. 5633 5634The associated declaration is: 5635- for type nodes, the declaration of the underlying type 5636- for CallExpr, the declaration of the callee 5637- for MemberExpr, the declaration of the referenced member 5638- for CXXConstructExpr, the declaration of the constructor 5639- for CXXNewExpr, the declaration of the operator new 5640- for ObjCIvarExpr, the declaration of the ivar 5641 5642For type nodes, hasDeclaration will generally match the declaration of the 5643sugared type. Given 5644 class X {}; 5645 typedef X Y; 5646 Y y; 5647in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 5648typedefDecl. A common use case is to match the underlying, desugared type. 5649This can be achieved by using the hasUnqualifiedDesugaredType matcher: 5650 varDecl(hasType(hasUnqualifiedDesugaredType( 5651 recordType(hasDeclaration(decl()))))) 5652In this matcher, the decl will match the CXXRecordDecl of class X. 5653 5654Usable 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>>, 5655 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>>, 5656 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>>, 5657 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>>, 5658 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>>, 5659 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>>, 5660 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 5661</pre></td></tr> 5662 5663 5664<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> 5665<tr><td colspan="4" class="doc" id="hasDestinationType0"><pre>Matches casts whose destination type matches a given matcher. 5666 5667(Note: Clang's AST refers to other conversions as "casts" too, and calls 5668actual casts "explicit" casts.) 5669</pre></td></tr> 5670 5671 5672<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> 5673<tr><td colspan="4" class="doc" id="hasType4"><pre>Overloaded to match the declaration of the expression's or value 5674declaration's type. 5675 5676In case of a value declaration (for example a variable declaration), 5677this resolves one layer of indirection. For example, in the value 5678declaration "X x;", cxxRecordDecl(hasName("X")) matches the declaration of 5679X, while varDecl(hasType(cxxRecordDecl(hasName("X")))) matches the 5680declaration of x. 5681 5682Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) 5683 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) 5684 and friend class X (matcher = friendDecl(hasType("X")) 5685 class X {}; 5686 void y(X &x) { x; X z; } 5687 class Y { friend class X; }; 5688 5689Usable 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>> 5690</pre></td></tr> 5691 5692 5693<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> 5694<tr><td colspan="4" class="doc" id="hasType0"><pre>Matches if the expression's or declaration's type matches a type 5695matcher. 5696 5697Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) 5698 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) 5699 and U (matcher = typedefDecl(hasType(asString("int"))) 5700 and friend class X (matcher = friendDecl(hasType("X")) 5701 class X {}; 5702 void y(X &x) { x; X z; } 5703 typedef int U; 5704 class Y { friend class X; }; 5705</pre></td></tr> 5706 5707 5708<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> 5709<tr><td colspan="4" class="doc" id="ignoringImpCasts0"><pre>Matches expressions that match InnerMatcher after any implicit casts 5710are stripped off. 5711 5712Parentheses and explicit casts are not discarded. 5713Given 5714 int arr[5]; 5715 int a = 0; 5716 char b = 0; 5717 const int c = a; 5718 int *d = arr; 5719 long e = (long) 0l; 5720The matchers 5721 varDecl(hasInitializer(ignoringImpCasts(integerLiteral()))) 5722 varDecl(hasInitializer(ignoringImpCasts(declRefExpr()))) 5723would match the declarations for a, b, c, and d, but not e. 5724While 5725 varDecl(hasInitializer(integerLiteral())) 5726 varDecl(hasInitializer(declRefExpr())) 5727only match the declarations for b, c, and d. 5728</pre></td></tr> 5729 5730 5731<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> 5732<tr><td colspan="4" class="doc" id="ignoringImplicit0"><pre>Matches expressions that match InnerMatcher after any implicit AST 5733nodes are stripped off. 5734 5735Parentheses and explicit casts are not discarded. 5736Given 5737 class C {}; 5738 C a = C(); 5739 C b; 5740 C c = b; 5741The matchers 5742 varDecl(hasInitializer(ignoringImplicit(cxxConstructExpr()))) 5743would match the declarations for a, b, and c. 5744While 5745 varDecl(hasInitializer(cxxConstructExpr())) 5746only match the declarations for b and c. 5747</pre></td></tr> 5748 5749 5750<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> 5751<tr><td colspan="4" class="doc" id="ignoringParenCasts0"><pre>Matches expressions that match InnerMatcher after parentheses and 5752casts are stripped off. 5753 5754Implicit and non-C Style casts are also discarded. 5755Given 5756 int a = 0; 5757 char b = (0); 5758 void* c = reinterpret_cast<char*>(0); 5759 char d = char(0); 5760The matcher 5761 varDecl(hasInitializer(ignoringParenCasts(integerLiteral()))) 5762would match the declarations for a, b, c, and d. 5763while 5764 varDecl(hasInitializer(integerLiteral())) 5765only match the declaration for a. 5766</pre></td></tr> 5767 5768 5769<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> 5770<tr><td colspan="4" class="doc" id="ignoringParenImpCasts0"><pre>Matches expressions that match InnerMatcher after implicit casts and 5771parentheses are stripped off. 5772 5773Explicit casts are not discarded. 5774Given 5775 int arr[5]; 5776 int a = 0; 5777 char b = (0); 5778 const int c = a; 5779 int *d = (arr); 5780 long e = ((long) 0l); 5781The matchers 5782 varDecl(hasInitializer(ignoringParenImpCasts(integerLiteral()))) 5783 varDecl(hasInitializer(ignoringParenImpCasts(declRefExpr()))) 5784would match the declarations for a, b, c, and d, but not e. 5785while 5786 varDecl(hasInitializer(integerLiteral())) 5787 varDecl(hasInitializer(declRefExpr())) 5788would only match the declaration for a. 5789</pre></td></tr> 5790 5791 5792<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> 5793<tr><td colspan="4" class="doc" id="ignoringParens1"><pre>Overload ignoringParens for Expr. 5794 5795Given 5796 const char* str = ("my-string"); 5797The matcher 5798 implicitCastExpr(hasSourceExpression(ignoringParens(stringLiteral()))) 5799would match the implicit cast resulting from the assignment. 5800</pre></td></tr> 5801 5802 5803<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> 5804<tr><td colspan="4" class="doc" id="hasInClassInitializer0"><pre>Matches non-static data members that have an in-class initializer. 5805 5806Given 5807 class C { 5808 int a = 2; 5809 int b = 3; 5810 int c; 5811 }; 5812fieldDecl(hasInClassInitializer(integerLiteral(equals(2)))) 5813 matches 'int a;' but not 'int b;'. 5814fieldDecl(hasInClassInitializer(anything())) 5815 matches 'int a;' and 'int b;' but not 'int c;'. 5816</pre></td></tr> 5817 5818 5819<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> 5820<tr><td colspan="4" class="doc" id="hasBody1"><pre>Matches a 'for', 'while', 'do while' statement or a function 5821definition that has a given body. 5822 5823Given 5824 for (;;) {} 5825hasBody(compoundStmt()) 5826 matches 'for (;;) {}' 5827with compoundStmt() 5828 matching '{}' 5829</pre></td></tr> 5830 5831 5832<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> 5833<tr><td colspan="4" class="doc" id="hasCondition1"><pre>Matches the condition expression of an if statement, for loop, 5834switch statement or conditional operator. 5835 5836Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true)))) 5837 if (true) {} 5838</pre></td></tr> 5839 5840 5841<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> 5842<tr><td colspan="4" class="doc" id="hasIncrement0"><pre>Matches the increment statement of a for loop. 5843 5844Example: 5845 forStmt(hasIncrement(unaryOperator(hasOperatorName("++")))) 5846matches '++x' in 5847 for (x; x < N; ++x) { } 5848</pre></td></tr> 5849 5850 5851<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> 5852<tr><td colspan="4" class="doc" id="hasLoopInit0"><pre>Matches the initialization statement of a for loop. 5853 5854Example: 5855 forStmt(hasLoopInit(declStmt())) 5856matches 'int x = 0' in 5857 for (int x = 0; x < N; ++x) { } 5858</pre></td></tr> 5859 5860 5861<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> 5862<tr><td colspan="4" class="doc" id="hasType5"><pre>Overloaded to match the declaration of the expression's or value 5863declaration's type. 5864 5865In case of a value declaration (for example a variable declaration), 5866this resolves one layer of indirection. For example, in the value 5867declaration "X x;", cxxRecordDecl(hasName("X")) matches the declaration of 5868X, while varDecl(hasType(cxxRecordDecl(hasName("X")))) matches the 5869declaration of x. 5870 5871Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) 5872 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) 5873 and friend class X (matcher = friendDecl(hasType("X")) 5874 class X {}; 5875 void y(X &x) { x; X z; } 5876 class Y { friend class X; }; 5877 5878Usable 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>> 5879</pre></td></tr> 5880 5881 5882<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> 5883<tr><td colspan="4" class="doc" id="hasType1"><pre>Matches if the expression's or declaration's type matches a type 5884matcher. 5885 5886Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) 5887 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) 5888 and U (matcher = typedefDecl(hasType(asString("int"))) 5889 and friend class X (matcher = friendDecl(hasType("X")) 5890 class X {}; 5891 void y(X &x) { x; X z; } 5892 typedef int U; 5893 class Y { friend class X; }; 5894</pre></td></tr> 5895 5896 5897<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> 5898<tr><td colspan="4" class="doc" id="hasAnyParameter0"><pre>Matches any parameter of a function or an ObjC method declaration or a 5899block. 5900 5901Does not match the 'this' parameter of a method. 5902 5903Given 5904 class X { void f(int x, int y, int z) {} }; 5905cxxMethodDecl(hasAnyParameter(hasName("y"))) 5906 matches f(int x, int y, int z) {} 5907with hasAnyParameter(...) 5908 matching int y 5909 5910For ObjectiveC, given 5911 @interface I - (void) f:(int) y; @end 5912 5913the matcher objcMethodDecl(hasAnyParameter(hasName("y"))) 5914matches the declaration of method f with hasParameter 5915matching y. 5916 5917For blocks, given 5918 b = ^(int y) { printf("%d", y) }; 5919 5920the matcher blockDecl(hasAnyParameter(hasName("y"))) 5921matches the declaration of the block b with hasParameter 5922matching y. 5923</pre></td></tr> 5924 5925 5926<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> 5927<tr><td colspan="4" class="doc" id="hasAnyTemplateArgument2"><pre>Matches classTemplateSpecializations, templateSpecializationType and 5928functionDecl that have at least one TemplateArgument matching the given 5929InnerMatcher. 5930 5931Given 5932 template<typename T> class A {}; 5933 template<> class A<double> {}; 5934 A<int> a; 5935 5936 template<typename T> f() {}; 5937 void func() { f<int>(); }; 5938 5939classTemplateSpecializationDecl(hasAnyTemplateArgument( 5940 refersToType(asString("int")))) 5941 matches the specialization A<int> 5942 5943functionDecl(hasAnyTemplateArgument(refersToType(asString("int")))) 5944 matches the specialization f<int> 5945</pre></td></tr> 5946 5947 5948<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> 5949<tr><td colspan="4" class="doc" id="hasBody4"><pre>Matches a 'for', 'while', 'do while' statement or a function 5950definition that has a given body. 5951 5952Given 5953 for (;;) {} 5954hasBody(compoundStmt()) 5955 matches 'for (;;) {}' 5956with compoundStmt() 5957 matching '{}' 5958</pre></td></tr> 5959 5960 5961<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> 5962<tr><td colspan="4" class="doc" id="hasParameter0"><pre>Matches the n'th parameter of a function or an ObjC method 5963declaration or a block. 5964 5965Given 5966 class X { void f(int x) {} }; 5967cxxMethodDecl(hasParameter(0, hasType(varDecl()))) 5968 matches f(int x) {} 5969with hasParameter(...) 5970 matching int x 5971 5972For ObjectiveC, given 5973 @interface I - (void) f:(int) y; @end 5974 5975the matcher objcMethodDecl(hasParameter(0, hasName("y"))) 5976matches the declaration of method f with hasParameter 5977matching y. 5978</pre></td></tr> 5979 5980 5981<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> 5982<tr><td colspan="4" class="doc" id="hasTemplateArgument2"><pre>Matches classTemplateSpecializations, templateSpecializationType and 5983functionDecl where the n'th TemplateArgument matches the given InnerMatcher. 5984 5985Given 5986 template<typename T, typename U> class A {}; 5987 A<bool, int> b; 5988 A<int, bool> c; 5989 5990 template<typename T> void f() {} 5991 void func() { f<int>(); }; 5992classTemplateSpecializationDecl(hasTemplateArgument( 5993 1, refersToType(asString("int")))) 5994 matches the specialization A<bool, int> 5995 5996functionDecl(hasTemplateArgument(0, refersToType(asString("int")))) 5997 matches the specialization f<int> 5998</pre></td></tr> 5999 6000 6001<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> 6002<tr><td colspan="4" class="doc" id="returns0"><pre>Matches the return type of a function declaration. 6003 6004Given: 6005 class X { int f() { return 1; } }; 6006cxxMethodDecl(returns(asString("int"))) 6007 matches int f() { return 1; } 6008</pre></td></tr> 6009 6010 6011<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> 6012<tr><td colspan="4" class="doc" id="hasCondition0"><pre>Matches the condition expression of an if statement, for loop, 6013switch statement or conditional operator. 6014 6015Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true)))) 6016 if (true) {} 6017</pre></td></tr> 6018 6019 6020<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> 6021<tr><td colspan="4" class="doc" id="hasConditionVariableStatement0"><pre>Matches the condition variable statement in an if statement. 6022 6023Given 6024 if (A* a = GetAPointer()) {} 6025hasConditionVariableStatement(...) 6026 matches 'A* a = GetAPointer()'. 6027</pre></td></tr> 6028 6029 6030<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> 6031<tr><td colspan="4" class="doc" id="hasElse0"><pre>Matches the else-statement of an if statement. 6032 6033Examples matches the if statement 6034 (matcher = ifStmt(hasElse(cxxBoolLiteral(equals(true))))) 6035 if (false) false; else true; 6036</pre></td></tr> 6037 6038 6039<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> 6040<tr><td colspan="4" class="doc" id="hasThen0"><pre>Matches the then-statement of an if statement. 6041 6042Examples matches the if statement 6043 (matcher = ifStmt(hasThen(cxxBoolLiteral(equals(true))))) 6044 if (false) true; else false; 6045</pre></td></tr> 6046 6047 6048<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> 6049<tr><td colspan="4" class="doc" id="hasImplicitDestinationType0"><pre>Matches implicit casts whose destination type matches a given 6050matcher. 6051 6052FIXME: Unit test this matcher 6053</pre></td></tr> 6054 6055 6056<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> 6057<tr><td colspan="4" class="doc" id="hasInit0"><pre>Matches the n'th item of an initializer list expression. 6058 6059Example matches y. 6060 (matcher = initListExpr(hasInit(0, expr()))) 6061 int x{y}. 6062</pre></td></tr> 6063 6064 6065<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> 6066<tr><td colspan="4" class="doc" id="hasSyntacticForm0"><pre>Matches the syntactic form of init list expressions 6067(if expression have it). 6068</pre></td></tr> 6069 6070 6071<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> 6072<tr><td colspan="4" class="doc" id="hasDeclaration9"><pre>Matches a node if the declaration associated with that node 6073matches the given matcher. 6074 6075The associated declaration is: 6076- for type nodes, the declaration of the underlying type 6077- for CallExpr, the declaration of the callee 6078- for MemberExpr, the declaration of the referenced member 6079- for CXXConstructExpr, the declaration of the constructor 6080- for CXXNewExpr, the declaration of the operator new 6081- for ObjCIvarExpr, the declaration of the ivar 6082 6083For type nodes, hasDeclaration will generally match the declaration of the 6084sugared type. Given 6085 class X {}; 6086 typedef X Y; 6087 Y y; 6088in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 6089typedefDecl. A common use case is to match the underlying, desugared type. 6090This can be achieved by using the hasUnqualifiedDesugaredType matcher: 6091 varDecl(hasType(hasUnqualifiedDesugaredType( 6092 recordType(hasDeclaration(decl()))))) 6093In this matcher, the decl will match the CXXRecordDecl of class X. 6094 6095Usable 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>>, 6096 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>>, 6097 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>>, 6098 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>>, 6099 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>>, 6100 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>>, 6101 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 6102</pre></td></tr> 6103 6104 6105<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> 6106<tr><td colspan="4" class="doc" id="hasDeclaration8"><pre>Matches a node if the declaration associated with that node 6107matches the given matcher. 6108 6109The associated declaration is: 6110- for type nodes, the declaration of the underlying type 6111- for CallExpr, the declaration of the callee 6112- for MemberExpr, the declaration of the referenced member 6113- for CXXConstructExpr, the declaration of the constructor 6114- for CXXNewExpr, the declaration of the operator new 6115- for ObjCIvarExpr, the declaration of the ivar 6116 6117For type nodes, hasDeclaration will generally match the declaration of the 6118sugared type. Given 6119 class X {}; 6120 typedef X Y; 6121 Y y; 6122in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 6123typedefDecl. A common use case is to match the underlying, desugared type. 6124This can be achieved by using the hasUnqualifiedDesugaredType matcher: 6125 varDecl(hasType(hasUnqualifiedDesugaredType( 6126 recordType(hasDeclaration(decl()))))) 6127In this matcher, the decl will match the CXXRecordDecl of class X. 6128 6129Usable 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>>, 6130 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>>, 6131 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>>, 6132 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>>, 6133 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>>, 6134 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>>, 6135 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 6136</pre></td></tr> 6137 6138 6139<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> 6140<tr><td colspan="4" class="doc" id="hasDeclaration7"><pre>Matches a node if the declaration associated with that node 6141matches the given matcher. 6142 6143The associated declaration is: 6144- for type nodes, the declaration of the underlying type 6145- for CallExpr, the declaration of the callee 6146- for MemberExpr, the declaration of the referenced member 6147- for CXXConstructExpr, the declaration of the constructor 6148- for CXXNewExpr, the declaration of the operator new 6149- for ObjCIvarExpr, the declaration of the ivar 6150 6151For type nodes, hasDeclaration will generally match the declaration of the 6152sugared type. Given 6153 class X {}; 6154 typedef X Y; 6155 Y y; 6156in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 6157typedefDecl. A common use case is to match the underlying, desugared type. 6158This can be achieved by using the hasUnqualifiedDesugaredType matcher: 6159 varDecl(hasType(hasUnqualifiedDesugaredType( 6160 recordType(hasDeclaration(decl()))))) 6161In this matcher, the decl will match the CXXRecordDecl of class X. 6162 6163Usable 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>>, 6164 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>>, 6165 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>>, 6166 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>>, 6167 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>>, 6168 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>>, 6169 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 6170</pre></td></tr> 6171 6172 6173<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> 6174<tr><td colspan="4" class="doc" id="hasObjectExpression0"><pre>Matches a member expression where the object expression is matched by a 6175given matcher. Implicit object expressions are included; that is, it matches 6176use of implicit `this`. 6177 6178Given 6179 struct X { 6180 int m; 6181 int f(X x) { x.m; return m; } 6182 }; 6183memberExpr(hasObjectExpression(hasType(cxxRecordDecl(hasName("X"))))) 6184 matches `x.m`, but not `m`; however, 6185memberExpr(hasObjectExpression(hasType(pointsTo( 6186 cxxRecordDecl(hasName("X")))))) 6187 matches `m` (aka. `this->m`), but not `x.m`. 6188</pre></td></tr> 6189 6190 6191<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> 6192<tr><td colspan="4" class="doc" id="member0"><pre>Matches a member expression where the member is matched by a 6193given matcher. 6194 6195Given 6196 struct { int first, second; } first, second; 6197 int i(second.first); 6198 int j(first.second); 6199memberExpr(member(hasName("first"))) 6200 matches second.first 6201 but not first.second (because the member name there is "second"). 6202</pre></td></tr> 6203 6204 6205<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> 6206<tr><td colspan="4" class="doc" id="pointee1"><pre>Narrows PointerType (and similar) matchers to those where the 6207pointee matches a given matcher. 6208 6209Given 6210 int *a; 6211 int const *b; 6212 float const *f; 6213pointerType(pointee(isConstQualified(), isInteger())) 6214 matches "int const *b" 6215 6216Usable 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>>, 6217 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>> 6218</pre></td></tr> 6219 6220 6221<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> 6222<tr><td colspan="4" class="doc" id="hasUnderlyingDecl0"><pre>Matches a NamedDecl whose underlying declaration matches the given 6223matcher. 6224 6225Given 6226 namespace N { template<class T> void f(T t); } 6227 template <class T> void g() { using N::f; f(T()); } 6228unresolvedLookupExpr(hasAnyDeclaration( 6229 namedDecl(hasUnderlyingDecl(hasName("::N::f"))))) 6230 matches the use of f in g() . 6231</pre></td></tr> 6232 6233 6234<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> 6235<tr><td colspan="4" class="doc" id="hasPrefix1"><pre>Matches on the prefix of a NestedNameSpecifierLoc. 6236 6237Given 6238 struct A { struct B { struct C {}; }; }; 6239 A::B::C c; 6240nestedNameSpecifierLoc(hasPrefix(loc(specifiesType(asString("struct A"))))) 6241 matches "A::" 6242</pre></td></tr> 6243 6244 6245<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> 6246<tr><td colspan="4" class="doc" id="specifiesTypeLoc0"><pre>Matches nested name specifier locs that specify a type matching the 6247given TypeLoc. 6248 6249Given 6250 struct A { struct B { struct C {}; }; }; 6251 A::B::C c; 6252nestedNameSpecifierLoc(specifiesTypeLoc(loc(type( 6253 hasDeclaration(cxxRecordDecl(hasName("A"))))))) 6254 matches "A::" 6255</pre></td></tr> 6256 6257 6258<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> 6259<tr><td colspan="4" class="doc" id="hasPrefix0"><pre>Matches on the prefix of a NestedNameSpecifier. 6260 6261Given 6262 struct A { struct B { struct C {}; }; }; 6263 A::B::C c; 6264nestedNameSpecifier(hasPrefix(specifiesType(asString("struct A")))) and 6265 matches "A::" 6266</pre></td></tr> 6267 6268 6269<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> 6270<tr><td colspan="4" class="doc" id="specifiesNamespace0"><pre>Matches nested name specifiers that specify a namespace matching the 6271given namespace matcher. 6272 6273Given 6274 namespace ns { struct A {}; } 6275 ns::A a; 6276nestedNameSpecifier(specifiesNamespace(hasName("ns"))) 6277 matches "ns::" 6278</pre></td></tr> 6279 6280 6281<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> 6282<tr><td colspan="4" class="doc" id="specifiesType0"><pre>Matches nested name specifiers that specify a type matching the 6283given QualType matcher without qualifiers. 6284 6285Given 6286 struct A { struct B { struct C {}; }; }; 6287 A::B::C c; 6288nestedNameSpecifier(specifiesType( 6289 hasDeclaration(cxxRecordDecl(hasName("A"))) 6290)) 6291 matches "A::" 6292</pre></td></tr> 6293 6294 6295<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPExecutableDirective.html">OMPExecutableDirective</a>></td><td class="name" onclick="toggle('hasAnyClause0')"><a name="hasAnyClause0Anchor">hasAnyClause</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPClause.html">OMPClause</a>> InnerMatcher</td></tr> 6296<tr><td colspan="4" class="doc" id="hasAnyClause0"><pre>Matches any clause in an OpenMP directive. 6297 6298Given 6299 6300 #pragma omp parallel 6301 #pragma omp parallel default(none) 6302 6303``ompExecutableDirective(hasAnyClause(anything()))`` matches 6304``omp parallel default(none)``. 6305</pre></td></tr> 6306 6307 6308<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1OMPExecutableDirective.html">OMPExecutableDirective</a>></td><td class="name" onclick="toggle('hasStructuredBlock0')"><a name="hasStructuredBlock0Anchor">hasStructuredBlock</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr> 6309<tr><td colspan="4" class="doc" id="hasStructuredBlock0"><pre>Matches the structured-block of the OpenMP executable directive 6310 6311Prerequisite: the executable directive must not be standalone directive. 6312If it is, it will never match. 6313 6314Given 6315 6316 #pragma omp parallel 6317 ; 6318 #pragma omp parallel 6319 {} 6320 6321``ompExecutableDirective(hasStructuredBlock(nullStmt()))`` will match ``;`` 6322</pre></td></tr> 6323 6324 6325<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> 6326<tr><td colspan="4" class="doc" id="hasAnyArgument3"><pre>Matches any argument of a call expression or a constructor call 6327expression, or an ObjC-message-send expression. 6328 6329Given 6330 void x(int, int, int) { int y; x(1, y, 42); } 6331callExpr(hasAnyArgument(declRefExpr())) 6332 matches x(1, y, 42) 6333with hasAnyArgument(...) 6334 matching y 6335 6336For ObjectiveC, given 6337 @interface I - (void) f:(int) y; @end 6338 void foo(I *i) { [i f:12]; } 6339objcMessageExpr(hasAnyArgument(integerLiteral(equals(12)))) 6340 matches [i f:12] 6341</pre></td></tr> 6342 6343 6344<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> 6345<tr><td colspan="4" class="doc" id="hasArgument2"><pre>Matches the n'th argument of a call expression or a constructor 6346call expression. 6347 6348Example matches y in x(y) 6349 (matcher = callExpr(hasArgument(0, declRefExpr()))) 6350 void x(int) { int y; x(y); } 6351</pre></td></tr> 6352 6353 6354<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> 6355<tr><td colspan="4" class="doc" id="hasReceiver0"><pre>Matches if the Objective-C message is sent to an instance, 6356and the inner matcher matches on that instance. 6357 6358For example the method call in 6359 NSString *x = @"hello"; 6360 [x containsString:@"h"]; 6361is matched by 6362objcMessageExpr(hasReceiver(declRefExpr(to(varDecl(hasName("x")))))) 6363</pre></td></tr> 6364 6365 6366<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> 6367<tr><td colspan="4" class="doc" id="hasReceiverType0"><pre>Matches on the receiver of an ObjectiveC Message expression. 6368 6369Example 6370matcher = objCMessageExpr(hasReceiverType(asString("UIWebView *"))); 6371matches the [webView ...] message invocation. 6372 NSString *webViewJavaScript = ... 6373 UIWebView *webView = ... 6374 [webView stringByEvaluatingJavaScriptFromString:webViewJavascript]; 6375</pre></td></tr> 6376 6377 6378<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> 6379<tr><td colspan="4" class="doc" id="hasAnyParameter1"><pre>Matches any parameter of a function or an ObjC method declaration or a 6380block. 6381 6382Does not match the 'this' parameter of a method. 6383 6384Given 6385 class X { void f(int x, int y, int z) {} }; 6386cxxMethodDecl(hasAnyParameter(hasName("y"))) 6387 matches f(int x, int y, int z) {} 6388with hasAnyParameter(...) 6389 matching int y 6390 6391For ObjectiveC, given 6392 @interface I - (void) f:(int) y; @end 6393 6394the matcher objcMethodDecl(hasAnyParameter(hasName("y"))) 6395matches the declaration of method f with hasParameter 6396matching y. 6397 6398For blocks, given 6399 b = ^(int y) { printf("%d", y) }; 6400 6401the matcher blockDecl(hasAnyParameter(hasName("y"))) 6402matches the declaration of the block b with hasParameter 6403matching y. 6404</pre></td></tr> 6405 6406 6407<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> 6408<tr><td colspan="4" class="doc" id="hasParameter1"><pre>Matches the n'th parameter of a function or an ObjC method 6409declaration or a block. 6410 6411Given 6412 class X { void f(int x) {} }; 6413cxxMethodDecl(hasParameter(0, hasType(varDecl()))) 6414 matches f(int x) {} 6415with hasParameter(...) 6416 matching int x 6417 6418For ObjectiveC, given 6419 @interface I - (void) f:(int) y; @end 6420 6421the matcher objcMethodDecl(hasParameter(0, hasName("y"))) 6422matches the declaration of method f with hasParameter 6423matching y. 6424</pre></td></tr> 6425 6426 6427<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> 6428<tr><td colspan="4" class="doc" id="hasSourceExpression1"><pre>Matches if the cast's source expression 6429or opaque value's source expression matches the given matcher. 6430 6431Example 1: matches "a string" 6432(matcher = castExpr(hasSourceExpression(cxxConstructExpr()))) 6433class URL { URL(string); }; 6434URL url = "a string"; 6435 6436Example 2: matches 'b' (matcher = 6437opaqueValueExpr(hasSourceExpression(implicitCastExpr(declRefExpr()))) 6438int a = b ?: 1; 6439</pre></td></tr> 6440 6441 6442<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> 6443<tr><td colspan="4" class="doc" id="hasAnyDeclaration0"><pre>Matches an OverloadExpr if any of the declarations in the set of 6444overloads matches the given matcher. 6445 6446Given 6447 template <typename T> void foo(T); 6448 template <typename T> void bar(T); 6449 template <typename T> void baz(T t) { 6450 foo(t); 6451 bar(t); 6452 } 6453unresolvedLookupExpr(hasAnyDeclaration( 6454 functionTemplateDecl(hasName("foo")))) 6455 matches foo in foo(t); but not bar in bar(t); 6456</pre></td></tr> 6457 6458 6459<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> 6460<tr><td colspan="4" class="doc" id="innerType0"><pre>Matches ParenType nodes where the inner type is a specific type. 6461 6462Given 6463 int (*ptr_to_array)[4]; 6464 int (*ptr_to_func)(int); 6465 6466varDecl(hasType(pointsTo(parenType(innerType(functionType()))))) matches 6467ptr_to_func but not ptr_to_array. 6468 6469Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ParenType.html">ParenType</a>> 6470</pre></td></tr> 6471 6472 6473<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> 6474<tr><td colspan="4" class="doc" id="pointee2"><pre>Narrows PointerType (and similar) matchers to those where the 6475pointee matches a given matcher. 6476 6477Given 6478 int *a; 6479 int const *b; 6480 float const *f; 6481pointerType(pointee(isConstQualified(), isInteger())) 6482 matches "int const *b" 6483 6484Usable 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>>, 6485 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>> 6486</pre></td></tr> 6487 6488 6489<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> 6490<tr><td colspan="4" class="doc" id="hasCanonicalType0"><pre>Matches QualTypes whose canonical type matches InnerMatcher. 6491 6492Given: 6493 typedef int &int_ref; 6494 int a; 6495 int_ref b = a; 6496 6497varDecl(hasType(qualType(referenceType()))))) will not match the 6498declaration of b but varDecl(hasType(qualType(hasCanonicalType(referenceType())))))) does. 6499</pre></td></tr> 6500 6501 6502<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> 6503<tr><td colspan="4" class="doc" id="hasDeclaration6"><pre>Matches a node if the declaration associated with that node 6504matches the given matcher. 6505 6506The associated declaration is: 6507- for type nodes, the declaration of the underlying type 6508- for CallExpr, the declaration of the callee 6509- for MemberExpr, the declaration of the referenced member 6510- for CXXConstructExpr, the declaration of the constructor 6511- for CXXNewExpr, the declaration of the operator new 6512- for ObjCIvarExpr, the declaration of the ivar 6513 6514For type nodes, hasDeclaration will generally match the declaration of the 6515sugared type. Given 6516 class X {}; 6517 typedef X Y; 6518 Y y; 6519in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 6520typedefDecl. A common use case is to match the underlying, desugared type. 6521This can be achieved by using the hasUnqualifiedDesugaredType matcher: 6522 varDecl(hasType(hasUnqualifiedDesugaredType( 6523 recordType(hasDeclaration(decl()))))) 6524In this matcher, the decl will match the CXXRecordDecl of class X. 6525 6526Usable 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>>, 6527 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>>, 6528 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>>, 6529 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>>, 6530 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>>, 6531 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>>, 6532 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 6533</pre></td></tr> 6534 6535 6536<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> 6537<tr><td colspan="4" class="doc" id="ignoringParens0"><pre>Matches types that match InnerMatcher after any parens are stripped. 6538 6539Given 6540 void (*fp)(void); 6541The matcher 6542 varDecl(hasType(pointerType(pointee(ignoringParens(functionType()))))) 6543would match the declaration for fp. 6544</pre></td></tr> 6545 6546 6547<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> 6548<tr><td colspan="4" class="doc" id="pointsTo1"><pre>Overloaded to match the pointee type's declaration. 6549</pre></td></tr> 6550 6551 6552<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> 6553<tr><td colspan="4" class="doc" id="pointsTo0"><pre>Matches if the matched type is a pointer type and the pointee type 6554matches the specified matcher. 6555 6556Example matches y->x() 6557 (matcher = cxxMemberCallExpr(on(hasType(pointsTo 6558 cxxRecordDecl(hasName("Y"))))))) 6559 class Y { public: void x(); }; 6560 void z() { Y *y; y->x(); } 6561</pre></td></tr> 6562 6563 6564<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> 6565<tr><td colspan="4" class="doc" id="references1"><pre>Overloaded to match the referenced type's declaration. 6566</pre></td></tr> 6567 6568 6569<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> 6570<tr><td colspan="4" class="doc" id="references0"><pre>Matches if the matched type is a reference type and the referenced 6571type matches the specified matcher. 6572 6573Example matches X &x and const X &y 6574 (matcher = varDecl(hasType(references(cxxRecordDecl(hasName("X")))))) 6575 class X { 6576 void a(X b) { 6577 X &x = b; 6578 const X &y = b; 6579 } 6580 }; 6581</pre></td></tr> 6582 6583 6584<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> 6585<tr><td colspan="4" class="doc" id="hasDeclaration5"><pre>Matches a node if the declaration associated with that node 6586matches the given matcher. 6587 6588The associated declaration is: 6589- for type nodes, the declaration of the underlying type 6590- for CallExpr, the declaration of the callee 6591- for MemberExpr, the declaration of the referenced member 6592- for CXXConstructExpr, the declaration of the constructor 6593- for CXXNewExpr, the declaration of the operator new 6594- for ObjCIvarExpr, the declaration of the ivar 6595 6596For type nodes, hasDeclaration will generally match the declaration of the 6597sugared type. Given 6598 class X {}; 6599 typedef X Y; 6600 Y y; 6601in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 6602typedefDecl. A common use case is to match the underlying, desugared type. 6603This can be achieved by using the hasUnqualifiedDesugaredType matcher: 6604 varDecl(hasType(hasUnqualifiedDesugaredType( 6605 recordType(hasDeclaration(decl()))))) 6606In this matcher, the decl will match the CXXRecordDecl of class X. 6607 6608Usable 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>>, 6609 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>>, 6610 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>>, 6611 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>>, 6612 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>>, 6613 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>>, 6614 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 6615</pre></td></tr> 6616 6617 6618<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> 6619<tr><td colspan="4" class="doc" id="pointee3"><pre>Narrows PointerType (and similar) matchers to those where the 6620pointee matches a given matcher. 6621 6622Given 6623 int *a; 6624 int const *b; 6625 float const *f; 6626pointerType(pointee(isConstQualified(), isInteger())) 6627 matches "int const *b" 6628 6629Usable 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>>, 6630 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>> 6631</pre></td></tr> 6632 6633 6634<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> 6635<tr><td colspan="4" class="doc" id="hasReturnValue0"><pre>Matches the return value expression of a return statement 6636 6637Given 6638 return a + b; 6639hasReturnValue(binaryOperator()) 6640 matches 'return a + b' 6641with binaryOperator() 6642 matching 'a + b' 6643</pre></td></tr> 6644 6645 6646<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> 6647<tr><td colspan="4" class="doc" id="hasAnySubstatement1"><pre>Matches compound statements where at least one substatement matches 6648a given matcher. Also matches StmtExprs that have CompoundStmt as children. 6649 6650Given 6651 { {}; 1+2; } 6652hasAnySubstatement(compoundStmt()) 6653 matches '{ {}; 1+2; }' 6654with compoundStmt() 6655 matching '{}' 6656</pre></td></tr> 6657 6658 6659<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> 6660<tr><td colspan="4" class="doc" id="alignOfExpr0"><pre>Same as unaryExprOrTypeTraitExpr, but only matching 6661alignof. 6662</pre></td></tr> 6663 6664 6665<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> 6666<tr><td colspan="4" class="doc" id="forFunction0"><pre>Matches declaration of the function the statement belongs to 6667 6668Given: 6669F& operator=(const F& o) { 6670 std::copy_if(o.begin(), o.end(), begin(), [](V v) { return v > 0; }); 6671 return *this; 6672} 6673returnStmt(forFunction(hasName("operator="))) 6674 matches 'return *this' 6675 but does match 'return > 0' 6676</pre></td></tr> 6677 6678 6679<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> 6680<tr><td colspan="4" class="doc" id="sizeOfExpr0"><pre>Same as unaryExprOrTypeTraitExpr, but only matching 6681sizeof. 6682</pre></td></tr> 6683 6684 6685<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> 6686<tr><td colspan="4" class="doc" id="hasReplacementType0"><pre>Matches template type parameter substitutions that have a replacement 6687type that matches the provided matcher. 6688 6689Given 6690 template <typename T> 6691 double F(T t); 6692 int i; 6693 double j = F(i); 6694 6695substTemplateTypeParmType(hasReplacementType(type())) matches int 6696</pre></td></tr> 6697 6698 6699<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> 6700<tr><td colspan="4" class="doc" id="forEachSwitchCase0"><pre>Matches each case or default statement belonging to the given switch 6701statement. This matcher may produce multiple matches. 6702 6703Given 6704 switch (1) { case 1: case 2: default: switch (2) { case 3: case 4: ; } } 6705switchStmt(forEachSwitchCase(caseStmt().bind("c"))).bind("s") 6706 matches four times, with "c" binding each of "case 1:", "case 2:", 6707"case 3:" and "case 4:", and "s" respectively binding "switch (1)", 6708"switch (1)", "switch (2)" and "switch (2)". 6709</pre></td></tr> 6710 6711 6712<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> 6713<tr><td colspan="4" class="doc" id="hasCondition4"><pre>Matches the condition expression of an if statement, for loop, 6714switch statement or conditional operator. 6715 6716Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true)))) 6717 if (true) {} 6718</pre></td></tr> 6719 6720 6721<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> 6722<tr><td colspan="4" class="doc" id="hasDeclaration4"><pre>Matches a node if the declaration associated with that node 6723matches the given matcher. 6724 6725The associated declaration is: 6726- for type nodes, the declaration of the underlying type 6727- for CallExpr, the declaration of the callee 6728- for MemberExpr, the declaration of the referenced member 6729- for CXXConstructExpr, the declaration of the constructor 6730- for CXXNewExpr, the declaration of the operator new 6731- for ObjCIvarExpr, the declaration of the ivar 6732 6733For type nodes, hasDeclaration will generally match the declaration of the 6734sugared type. Given 6735 class X {}; 6736 typedef X Y; 6737 Y y; 6738in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 6739typedefDecl. A common use case is to match the underlying, desugared type. 6740This can be achieved by using the hasUnqualifiedDesugaredType matcher: 6741 varDecl(hasType(hasUnqualifiedDesugaredType( 6742 recordType(hasDeclaration(decl()))))) 6743In this matcher, the decl will match the CXXRecordDecl of class X. 6744 6745Usable 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>>, 6746 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>>, 6747 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>>, 6748 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>>, 6749 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>>, 6750 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>>, 6751 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 6752</pre></td></tr> 6753 6754 6755<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> 6756<tr><td colspan="4" class="doc" id="isExpr0"><pre>Matches a sugar TemplateArgument that refers to a certain expression. 6757 6758Given 6759 struct B { int next; }; 6760 template<int(B::*next_ptr)> struct A {}; 6761 A<&B::next> a; 6762templateSpecializationType(hasAnyTemplateArgument( 6763 isExpr(hasDescendant(declRefExpr(to(fieldDecl(hasName("next")))))))) 6764 matches the specialization A<&B::next> with fieldDecl(...) matching 6765 B::next 6766</pre></td></tr> 6767 6768 6769<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> 6770<tr><td colspan="4" class="doc" id="refersToDeclaration0"><pre>Matches a canonical TemplateArgument that refers to a certain 6771declaration. 6772 6773Given 6774 struct B { int next; }; 6775 template<int(B::*next_ptr)> struct A {}; 6776 A<&B::next> a; 6777classTemplateSpecializationDecl(hasAnyTemplateArgument( 6778 refersToDeclaration(fieldDecl(hasName("next"))))) 6779 matches the specialization A<&B::next> with fieldDecl(...) matching 6780 B::next 6781</pre></td></tr> 6782 6783 6784<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> 6785<tr><td colspan="4" class="doc" id="refersToIntegralType0"><pre>Matches a TemplateArgument that referes to an integral type. 6786 6787Given 6788 template<int T> struct C {}; 6789 C<42> c; 6790classTemplateSpecializationDecl( 6791 hasAnyTemplateArgument(refersToIntegralType(asString("int")))) 6792 matches the implicit instantiation of C in C<42>. 6793</pre></td></tr> 6794 6795 6796<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> 6797<tr><td colspan="4" class="doc" id="refersToTemplate0"><pre>Matches a TemplateArgument that refers to a certain template. 6798 6799Given 6800 template<template <typename> class S> class X {}; 6801 template<typename T> class Y {}; 6802 X<Y> xi; 6803classTemplateSpecializationDecl(hasAnyTemplateArgument( 6804 refersToTemplate(templateName()))) 6805 matches the specialization X<Y> 6806</pre></td></tr> 6807 6808 6809<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> 6810<tr><td colspan="4" class="doc" id="refersToType0"><pre>Matches a TemplateArgument that refers to a certain type. 6811 6812Given 6813 struct X {}; 6814 template<typename T> struct A {}; 6815 A<X> a; 6816classTemplateSpecializationDecl(hasAnyTemplateArgument( 6817 refersToType(class(hasName("X"))))) 6818 matches the specialization A<X> 6819</pre></td></tr> 6820 6821 6822<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> 6823<tr><td colspan="4" class="doc" id="hasAnyTemplateArgument1"><pre>Matches classTemplateSpecializations, templateSpecializationType and 6824functionDecl that have at least one TemplateArgument matching the given 6825InnerMatcher. 6826 6827Given 6828 template<typename T> class A {}; 6829 template<> class A<double> {}; 6830 A<int> a; 6831 6832 template<typename T> f() {}; 6833 void func() { f<int>(); }; 6834 6835classTemplateSpecializationDecl(hasAnyTemplateArgument( 6836 refersToType(asString("int")))) 6837 matches the specialization A<int> 6838 6839functionDecl(hasAnyTemplateArgument(refersToType(asString("int")))) 6840 matches the specialization f<int> 6841</pre></td></tr> 6842 6843 6844<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> 6845<tr><td colspan="4" class="doc" id="hasDeclaration3"><pre>Matches a node if the declaration associated with that node 6846matches the given matcher. 6847 6848The associated declaration is: 6849- for type nodes, the declaration of the underlying type 6850- for CallExpr, the declaration of the callee 6851- for MemberExpr, the declaration of the referenced member 6852- for CXXConstructExpr, the declaration of the constructor 6853- for CXXNewExpr, the declaration of the operator new 6854- for ObjCIvarExpr, the declaration of the ivar 6855 6856For type nodes, hasDeclaration will generally match the declaration of the 6857sugared type. Given 6858 class X {}; 6859 typedef X Y; 6860 Y y; 6861in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 6862typedefDecl. A common use case is to match the underlying, desugared type. 6863This can be achieved by using the hasUnqualifiedDesugaredType matcher: 6864 varDecl(hasType(hasUnqualifiedDesugaredType( 6865 recordType(hasDeclaration(decl()))))) 6866In this matcher, the decl will match the CXXRecordDecl of class X. 6867 6868Usable 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>>, 6869 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>>, 6870 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>>, 6871 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>>, 6872 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>>, 6873 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>>, 6874 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 6875</pre></td></tr> 6876 6877 6878<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> 6879<tr><td colspan="4" class="doc" id="hasTemplateArgument1"><pre>Matches classTemplateSpecializations, templateSpecializationType and 6880functionDecl where the n'th TemplateArgument matches the given InnerMatcher. 6881 6882Given 6883 template<typename T, typename U> class A {}; 6884 A<bool, int> b; 6885 A<int, bool> c; 6886 6887 template<typename T> void f() {} 6888 void func() { f<int>(); }; 6889classTemplateSpecializationDecl(hasTemplateArgument( 6890 1, refersToType(asString("int")))) 6891 matches the specialization A<bool, int> 6892 6893functionDecl(hasTemplateArgument(0, refersToType(asString("int")))) 6894 matches the specialization f<int> 6895</pre></td></tr> 6896 6897 6898<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> 6899<tr><td colspan="4" class="doc" id="hasDeclaration2"><pre>Matches a node if the declaration associated with that node 6900matches the given matcher. 6901 6902The associated declaration is: 6903- for type nodes, the declaration of the underlying type 6904- for CallExpr, the declaration of the callee 6905- for MemberExpr, the declaration of the referenced member 6906- for CXXConstructExpr, the declaration of the constructor 6907- for CXXNewExpr, the declaration of the operator new 6908- for ObjCIvarExpr, the declaration of the ivar 6909 6910For type nodes, hasDeclaration will generally match the declaration of the 6911sugared type. Given 6912 class X {}; 6913 typedef X Y; 6914 Y y; 6915in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 6916typedefDecl. A common use case is to match the underlying, desugared type. 6917This can be achieved by using the hasUnqualifiedDesugaredType matcher: 6918 varDecl(hasType(hasUnqualifiedDesugaredType( 6919 recordType(hasDeclaration(decl()))))) 6920In this matcher, the decl will match the CXXRecordDecl of class X. 6921 6922Usable 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>>, 6923 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>>, 6924 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>>, 6925 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>>, 6926 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>>, 6927 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>>, 6928 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 6929</pre></td></tr> 6930 6931 6932<tr><td>Matcher<T></td><td class="name" onclick="toggle('findAll0')"><a name="findAll0Anchor">findAll</a></td><td>const Matcher<T> Matcher</td></tr> 6933<tr><td colspan="4" class="doc" id="findAll0"><pre>Matches if the node or any descendant matches. 6934 6935Generates results for each match. 6936 6937For example, in: 6938 class A { class B {}; class C {}; }; 6939The matcher: 6940 cxxRecordDecl(hasName("::A"), 6941 findAll(cxxRecordDecl(isDefinition()).bind("m"))) 6942will generate results for A, B and C. 6943 6944Usable as: Any Matcher 6945</pre></td></tr> 6946 6947 6948<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> 6949<tr><td colspan="4" class="doc" id="hasType2"><pre>Matches if the expression's or declaration's type matches a type 6950matcher. 6951 6952Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) 6953 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) 6954 and U (matcher = typedefDecl(hasType(asString("int"))) 6955 and friend class X (matcher = friendDecl(hasType("X")) 6956 class X {}; 6957 void y(X &x) { x; X z; } 6958 typedef int U; 6959 class Y { friend class X; }; 6960</pre></td></tr> 6961 6962 6963<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> 6964<tr><td colspan="4" class="doc" id="hasDeclaration1"><pre>Matches a node if the declaration associated with that node 6965matches the given matcher. 6966 6967The associated declaration is: 6968- for type nodes, the declaration of the underlying type 6969- for CallExpr, the declaration of the callee 6970- for MemberExpr, the declaration of the referenced member 6971- for CXXConstructExpr, the declaration of the constructor 6972- for CXXNewExpr, the declaration of the operator new 6973- for ObjCIvarExpr, the declaration of the ivar 6974 6975For type nodes, hasDeclaration will generally match the declaration of the 6976sugared type. Given 6977 class X {}; 6978 typedef X Y; 6979 Y y; 6980in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 6981typedefDecl. A common use case is to match the underlying, desugared type. 6982This can be achieved by using the hasUnqualifiedDesugaredType matcher: 6983 varDecl(hasType(hasUnqualifiedDesugaredType( 6984 recordType(hasDeclaration(decl()))))) 6985In this matcher, the decl will match the CXXRecordDecl of class X. 6986 6987Usable 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>>, 6988 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>>, 6989 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>>, 6990 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>>, 6991 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>>, 6992 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>>, 6993 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 6994</pre></td></tr> 6995 6996 6997<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> 6998<tr><td colspan="4" class="doc" id="hasUnqualifiedDesugaredType0"><pre>Matches if the matched type matches the unqualified desugared 6999type of the matched node. 7000 7001For example, in: 7002 class A {}; 7003 using B = A; 7004The matcher type(hasUnqualifiedDesugaredType(recordType())) matches 7005both B and A. 7006</pre></td></tr> 7007 7008 7009<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> 7010<tr><td colspan="4" class="doc" id="hasArgumentOfType0"><pre>Matches unary expressions that have a specific type of argument. 7011 7012Given 7013 int a, c; float b; int s = sizeof(a) + sizeof(b) + alignof(c); 7014unaryExprOrTypeTraitExpr(hasArgumentOfType(asString("int")) 7015 matches sizeof(a) and alignof(c) 7016</pre></td></tr> 7017 7018 7019<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> 7020<tr><td colspan="4" class="doc" id="hasUnaryOperand0"><pre>Matches if the operand of a unary operator matches. 7021 7022Example matches true (matcher = hasUnaryOperand( 7023 cxxBoolLiteral(equals(true)))) 7024 !true 7025</pre></td></tr> 7026 7027 7028<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> 7029<tr><td colspan="4" class="doc" id="hasObjectExpression1"><pre>Matches a member expression where the object expression is matched by a 7030given matcher. Implicit object expressions are included; that is, it matches 7031use of implicit `this`. 7032 7033Given 7034 struct X { 7035 int m; 7036 int f(X x) { x.m; return m; } 7037 }; 7038memberExpr(hasObjectExpression(hasType(cxxRecordDecl(hasName("X"))))) 7039 matches `x.m`, but not `m`; however, 7040memberExpr(hasObjectExpression(hasType(pointsTo( 7041 cxxRecordDecl(hasName("X")))))) 7042 matches `m` (aka. `this->m`), but not `x.m`. 7043</pre></td></tr> 7044 7045 7046<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> 7047<tr><td colspan="4" class="doc" id="hasDeclaration0"><pre>Matches a node if the declaration associated with that node 7048matches the given matcher. 7049 7050The associated declaration is: 7051- for type nodes, the declaration of the underlying type 7052- for CallExpr, the declaration of the callee 7053- for MemberExpr, the declaration of the referenced member 7054- for CXXConstructExpr, the declaration of the constructor 7055- for CXXNewExpr, the declaration of the operator new 7056- for ObjCIvarExpr, the declaration of the ivar 7057 7058For type nodes, hasDeclaration will generally match the declaration of the 7059sugared type. Given 7060 class X {}; 7061 typedef X Y; 7062 Y y; 7063in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 7064typedefDecl. A common use case is to match the underlying, desugared type. 7065This can be achieved by using the hasUnqualifiedDesugaredType matcher: 7066 varDecl(hasType(hasUnqualifiedDesugaredType( 7067 recordType(hasDeclaration(decl()))))) 7068In this matcher, the decl will match the CXXRecordDecl of class X. 7069 7070Usable 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>>, 7071 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>>, 7072 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>>, 7073 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>>, 7074 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>>, 7075 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>>, 7076 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 7077</pre></td></tr> 7078 7079 7080<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> 7081<tr><td colspan="4" class="doc" id="hasAnyUsingShadowDecl0"><pre>Matches any using shadow declaration. 7082 7083Given 7084 namespace X { void b(); } 7085 using X::b; 7086usingDecl(hasAnyUsingShadowDecl(hasName("b")))) 7087 matches using X::b </pre></td></tr> 7088 7089 7090<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> 7091<tr><td colspan="4" class="doc" id="hasTargetDecl0"><pre>Matches a using shadow declaration where the target declaration is 7092matched by the given matcher. 7093 7094Given 7095 namespace X { int a; void b(); } 7096 using X::a; 7097 using X::b; 7098usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(functionDecl()))) 7099 matches using X::b but not using X::a </pre></td></tr> 7100 7101 7102<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> 7103<tr><td colspan="4" class="doc" id="hasType6"><pre>Overloaded to match the declaration of the expression's or value 7104declaration's type. 7105 7106In case of a value declaration (for example a variable declaration), 7107this resolves one layer of indirection. For example, in the value 7108declaration "X x;", cxxRecordDecl(hasName("X")) matches the declaration of 7109X, while varDecl(hasType(cxxRecordDecl(hasName("X")))) matches the 7110declaration of x. 7111 7112Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) 7113 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) 7114 and friend class X (matcher = friendDecl(hasType("X")) 7115 class X {}; 7116 void y(X &x) { x; X z; } 7117 class Y { friend class X; }; 7118 7119Usable 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>> 7120</pre></td></tr> 7121 7122 7123<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> 7124<tr><td colspan="4" class="doc" id="hasType3"><pre>Matches if the expression's or declaration's type matches a type 7125matcher. 7126 7127Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) 7128 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) 7129 and U (matcher = typedefDecl(hasType(asString("int"))) 7130 and friend class X (matcher = friendDecl(hasType("X")) 7131 class X {}; 7132 void y(X &x) { x; X z; } 7133 typedef int U; 7134 class Y { friend class X; }; 7135</pre></td></tr> 7136 7137 7138<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> 7139<tr><td colspan="4" class="doc" id="hasInitializer0"><pre>Matches a variable declaration that has an initializer expression 7140that matches the given matcher. 7141 7142Example matches x (matcher = varDecl(hasInitializer(callExpr()))) 7143 bool y() { return true; } 7144 bool x = y(); 7145</pre></td></tr> 7146 7147 7148<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> 7149<tr><td colspan="4" class="doc" id="hasSizeExpr0"><pre>Matches VariableArrayType nodes that have a specific size 7150expression. 7151 7152Given 7153 void f(int b) { 7154 int a[b]; 7155 } 7156variableArrayType(hasSizeExpr(ignoringImpCasts(declRefExpr(to( 7157 varDecl(hasName("b"))))))) 7158 matches "int a[b]" 7159</pre></td></tr> 7160 7161 7162<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> 7163<tr><td colspan="4" class="doc" id="hasBody2"><pre>Matches a 'for', 'while', 'do while' statement or a function 7164definition that has a given body. 7165 7166Given 7167 for (;;) {} 7168hasBody(compoundStmt()) 7169 matches 'for (;;) {}' 7170with compoundStmt() 7171 matching '{}' 7172</pre></td></tr> 7173 7174 7175<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> 7176<tr><td colspan="4" class="doc" id="hasCondition2"><pre>Matches the condition expression of an if statement, for loop, 7177switch statement or conditional operator. 7178 7179Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true)))) 7180 if (true) {} 7181</pre></td></tr> 7182 7183 7184<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> 7185<tr><td colspan="4" class="doc" id="loc1"><pre>Matches NestedNameSpecifierLocs for which the given inner 7186NestedNameSpecifier-matcher matches. 7187</pre></td></tr> 7188 7189 7190<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> 7191<tr><td colspan="4" class="doc" id="loc0"><pre>Matches TypeLocs for which the given inner 7192QualType-matcher matches. 7193</pre></td></tr> 7194 7195<!--END_TRAVERSAL_MATCHERS --> 7196</table> 7197 7198</div> 7199</body> 7200</html> 7201 7202 7203