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('isInStdNamespace0')"><a name="isInStdNamespace0Anchor">isInStdNamespace</a></td><td></td></tr> 2831<tr><td colspan="4" class="doc" id="isInStdNamespace0"><pre>Matches declarations in the namespace `std`, but not in nested namespaces. 2832 2833Given 2834 class vector {}; 2835 namespace foo { 2836 class vector {}; 2837 namespace std { 2838 class vector {}; 2839 } 2840 } 2841 namespace std { 2842 inline namespace __1 { 2843 class vector {}; // #1 2844 namespace experimental { 2845 class vector {}; 2846 } 2847 } 2848 } 2849cxxRecordDecl(hasName("vector"), isInStdNamespace()) will match only #1. 2850</pre></td></tr> 2851 2852 2853<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> 2854<tr><td colspan="4" class="doc" id="isPrivate0"><pre>Matches private C++ declarations. 2855 2856Given 2857 class C { 2858 public: int a; 2859 protected: int b; 2860 private: int c; 2861 }; 2862fieldDecl(isPrivate()) 2863 matches 'int c;' 2864</pre></td></tr> 2865 2866 2867<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> 2868<tr><td colspan="4" class="doc" id="isProtected0"><pre>Matches protected C++ declarations. 2869 2870Given 2871 class C { 2872 public: int a; 2873 protected: int b; 2874 private: int c; 2875 }; 2876fieldDecl(isProtected()) 2877 matches 'int b;' 2878</pre></td></tr> 2879 2880 2881<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> 2882<tr><td colspan="4" class="doc" id="isPublic0"><pre>Matches public C++ declarations. 2883 2884Given 2885 class C { 2886 public: int a; 2887 protected: int b; 2888 private: int c; 2889 }; 2890fieldDecl(isPublic()) 2891 matches 'int a;' 2892</pre></td></tr> 2893 2894 2895<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> 2896<tr><td colspan="4" class="doc" id="designatorCountIs0"><pre>Matches designated initializer expressions that contain 2897a specific number of designators. 2898 2899Example: Given 2900 point ptarray[10] = { [2].y = 1.0, [0].x = 1.0 }; 2901 point ptarray2[10] = { [2].y = 1.0, [2].x = 0.0, [0].x = 1.0 }; 2902designatorCountIs(2) 2903 matches '{ [2].y = 1.0, [0].x = 1.0 }', 2904 but not '{ [2].y = 1.0, [2].x = 0.0, [0].x = 1.0 }'. 2905</pre></td></tr> 2906 2907 2908<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> 2909<tr><td colspan="4" class="doc" id="isScoped0"><pre>Matches C++11 scoped enum declaration. 2910 2911Example matches Y (matcher = enumDecl(isScoped())) 2912enum X {}; 2913enum class Y {}; 2914</pre></td></tr> 2915 2916 2917<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> 2918<tr><td colspan="4" class="doc" id="isInstantiationDependent0"><pre>Matches expressions that are instantiation-dependent even if it is 2919neither type- nor value-dependent. 2920 2921In the following example, the expression sizeof(sizeof(T() + T())) 2922is instantiation-dependent (since it involves a template parameter T), 2923but is neither type- nor value-dependent, since the type of the inner 2924sizeof is known (std::size_t) and therefore the size of the outer 2925sizeof is known. 2926 template<typename T> 2927 void f(T x, T y) { sizeof(sizeof(T() + T()); } 2928expr(isInstantiationDependent()) matches sizeof(sizeof(T() + T()) 2929</pre></td></tr> 2930 2931 2932<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> 2933<tr><td colspan="4" class="doc" id="isTypeDependent0"><pre>Matches expressions that are type-dependent because the template type 2934is not yet instantiated. 2935 2936For example, the expressions "x" and "x + y" are type-dependent in 2937the following code, but "y" is not type-dependent: 2938 template<typename T> 2939 void add(T x, int y) { 2940 x + y; 2941 } 2942expr(isTypeDependent()) matches x + y 2943</pre></td></tr> 2944 2945 2946<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> 2947<tr><td colspan="4" class="doc" id="isValueDependent0"><pre>Matches expression that are value-dependent because they contain a 2948non-type template parameter. 2949 2950For example, the array bound of "Chars" in the following example is 2951value-dependent. 2952 template<int Size> int f() { return Size; } 2953expr(isValueDependent()) matches return Size 2954</pre></td></tr> 2955 2956 2957<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> 2958<tr><td colspan="4" class="doc" id="hasBitWidth0"><pre>Matches non-static data members that are bit-fields of the specified 2959bit width. 2960 2961Given 2962 class C { 2963 int a : 2; 2964 int b : 4; 2965 int c : 2; 2966 }; 2967fieldDecl(hasBitWidth(2)) 2968 matches 'int a;' and 'int c;' but not 'int b;'. 2969</pre></td></tr> 2970 2971 2972<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> 2973<tr><td colspan="4" class="doc" id="isBitField0"><pre>Matches non-static data members that are bit-fields. 2974 2975Given 2976 class C { 2977 int a : 2; 2978 int b; 2979 }; 2980fieldDecl(isBitField()) 2981 matches 'int a;' but not 'int b;'. 2982</pre></td></tr> 2983 2984 2985<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> 2986<tr><td colspan="4" class="doc" id="equals1"><pre>Matches literals that are equal to the given value of type ValueT. 2987 2988Given 2989 f('false, 3.14, 42); 2990characterLiteral(equals(0)) 2991 matches 'cxxBoolLiteral(equals(false)) and cxxBoolLiteral(equals(0)) 2992 match false 2993floatLiteral(equals(3.14)) and floatLiteral(equals(314e-2)) 2994 match 3.14 2995integerLiteral(equals(42)) 2996 matches 42 2997 2998Note that you cannot directly match a negative numeric literal because the 2999minus sign is not part of the literal: It is a unary operator whose operand 3000is the positive numeric literal. Instead, you must use a unaryOperator() 3001matcher to match the minus sign: 3002 3003unaryOperator(hasOperatorName("-"), 3004 hasUnaryOperand(integerLiteral(equals(13)))) 3005 3006Usable 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>>, 3007 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>> 3008</pre></td></tr> 3009 3010 3011<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> 3012<tr><td colspan="4" class="doc" id="equals12"><pre></pre></td></tr> 3013 3014 3015<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> 3016<tr><td colspan="4" class="doc" id="hasDynamicExceptionSpec0"><pre>Matches functions that have a dynamic exception specification. 3017 3018Given: 3019 void f(); 3020 void g() noexcept; 3021 void h() noexcept(true); 3022 void i() noexcept(false); 3023 void j() throw(); 3024 void k() throw(int); 3025 void l() throw(...); 3026functionDecl(hasDynamicExceptionSpec()) and 3027 functionProtoType(hasDynamicExceptionSpec()) 3028 match the declarations of j, k, and l, but not f, g, h, or i. 3029</pre></td></tr> 3030 3031 3032<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('hasOverloadedOperatorName0')"><a name="hasOverloadedOperatorName0Anchor">hasOverloadedOperatorName</a></td><td>StringRef Name</td></tr> 3033<tr><td colspan="4" class="doc" id="hasOverloadedOperatorName0"><pre>Matches overloaded operator names. 3034 3035Matches overloaded operator names specified in strings without the 3036"operator" prefix: e.g. "<<". 3037 3038Given: 3039 class A { int operator*(); }; 3040 const A &operator<<(const A &a, const A &b); 3041 A a; 3042 a << a; // <-- This matches 3043 3044cxxOperatorCallExpr(hasOverloadedOperatorName("<<"))) matches the 3045specified line and 3046cxxRecordDecl(hasMethod(hasOverloadedOperatorName("*"))) 3047matches the declaration of A. 3048 3049Usable 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>> 3050</pre></td></tr> 3051 3052 3053<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> 3054<tr><td colspan="4" class="doc" id="hasTrailingReturn0"><pre>Matches a function declared with a trailing return type. 3055 3056Example matches Y (matcher = functionDecl(hasTrailingReturn())) 3057int X() {} 3058auto Y() -> int {} 3059</pre></td></tr> 3060 3061 3062<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> 3063<tr><td colspan="4" class="doc" id="isConstexpr1"><pre>Matches constexpr variable and function declarations, 3064 and if constexpr. 3065 3066Given: 3067 constexpr int foo = 42; 3068 constexpr int bar(); 3069 void baz() { if constexpr(1 > 0) {} } 3070varDecl(isConstexpr()) 3071 matches the declaration of foo. 3072functionDecl(isConstexpr()) 3073 matches the declaration of bar. 3074ifStmt(isConstexpr()) 3075 matches the if statement in baz. 3076</pre></td></tr> 3077 3078 3079<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isDefaulted0')"><a name="isDefaulted0Anchor">isDefaulted</a></td><td></td></tr> 3080<tr><td colspan="4" class="doc" id="isDefaulted0"><pre>Matches defaulted function declarations. 3081 3082Given: 3083 class A { ~A(); }; 3084 class B { ~B() = default; }; 3085functionDecl(isDefaulted()) 3086 matches the declaration of ~B, but not ~A. 3087</pre></td></tr> 3088 3089 3090<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> 3091<tr><td colspan="4" class="doc" id="isDefinition3"><pre>Matches if a declaration has a body attached. 3092 3093Example matches A, va, fa 3094 class A {}; 3095 class B; // Doesn't match, as it has no body. 3096 int va; 3097 extern int vb; // Doesn't match, as it doesn't define the variable. 3098 void fa() {} 3099 void fb(); // Doesn't match, as it has no body. 3100 @interface X 3101 - (void)ma; // Doesn't match, interface is declaration. 3102 @end 3103 @implementation X 3104 - (void)ma {} 3105 @end 3106 3107Usable 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>>, 3108 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html">ObjCMethodDecl</a>> 3109</pre></td></tr> 3110 3111 3112<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> 3113<tr><td colspan="4" class="doc" id="isDeleted0"><pre>Matches deleted function declarations. 3114 3115Given: 3116 void Func(); 3117 void DeletedFunc() = delete; 3118functionDecl(isDeleted()) 3119 matches the declaration of DeletedFunc, but not Func. 3120</pre></td></tr> 3121 3122 3123<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> 3124<tr><td colspan="4" class="doc" id="isExplicitTemplateSpecialization0"><pre>Matches explicit template specializations of function, class, or 3125static member variable template instantiations. 3126 3127Given 3128 template<typename T> void A(T t) { } 3129 template<> void A(int N) { } 3130functionDecl(isExplicitTemplateSpecialization()) 3131 matches the specialization A<int>(). 3132 3133Usable 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>> 3134</pre></td></tr> 3135 3136 3137<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> 3138<tr><td colspan="4" class="doc" id="isExternC0"><pre>Matches extern "C" function or variable declarations. 3139 3140Given: 3141 extern "C" void f() {} 3142 extern "C" { void g() {} } 3143 void h() {} 3144 extern "C" int x = 1; 3145 extern "C" int y = 2; 3146 int z = 3; 3147functionDecl(isExternC()) 3148 matches the declaration of f and g, but not the declaration of h. 3149varDecl(isExternC()) 3150 matches the declaration of x and y, but not the declaration of z. 3151</pre></td></tr> 3152 3153 3154<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> 3155<tr><td colspan="4" class="doc" id="isInline1"><pre>Matches function and namespace declarations that are marked with 3156the inline keyword. 3157 3158Given 3159 inline void f(); 3160 void g(); 3161 namespace n { 3162 inline namespace m {} 3163 } 3164functionDecl(isInline()) will match ::f(). 3165namespaceDecl(isInline()) will match n::m. 3166</pre></td></tr> 3167 3168 3169<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> 3170<tr><td colspan="4" class="doc" id="isMain0"><pre>Determines whether the function is "main", which is the entry point 3171into an executable program. 3172</pre></td></tr> 3173 3174 3175<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> 3176<tr><td colspan="4" class="doc" id="isNoReturn0"><pre>Matches FunctionDecls that have a noreturn attribute. 3177 3178Given 3179 void nope(); 3180 [[noreturn]] void a(); 3181 __attribute__((noreturn)) void b(); 3182 struct c { [[noreturn]] c(); }; 3183functionDecl(isNoReturn()) 3184 matches all of those except 3185 void nope(); 3186</pre></td></tr> 3187 3188 3189<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isNoThrow0')"><a name="isNoThrow0Anchor">isNoThrow</a></td><td></td></tr> 3190<tr><td colspan="4" class="doc" id="isNoThrow0"><pre>Matches functions that have a non-throwing exception specification. 3191 3192Given: 3193 void f(); 3194 void g() noexcept; 3195 void h() throw(); 3196 void i() throw(int); 3197 void j() noexcept(false); 3198functionDecl(isNoThrow()) and functionProtoType(isNoThrow()) 3199 match the declarations of g, and h, but not f, i or j. 3200</pre></td></tr> 3201 3202 3203<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> 3204<tr><td colspan="4" class="doc" id="isStaticStorageClass0"><pre>Matches variable/function declarations that have "static" storage 3205class specifier ("static" keyword) written in the source. 3206 3207Given: 3208 static void f() {} 3209 static int i = 0; 3210 extern int j; 3211 int k; 3212functionDecl(isStaticStorageClass()) 3213 matches the function declaration f. 3214varDecl(isStaticStorageClass()) 3215 matches the variable declaration i. 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('isTemplateInstantiation0')"><a name="isTemplateInstantiation0Anchor">isTemplateInstantiation</a></td><td></td></tr> 3220<tr><td colspan="4" class="doc" id="isTemplateInstantiation0"><pre>Matches template instantiations of function, class, or static 3221member variable template instantiations. 3222 3223Given 3224 template <typename T> class X {}; class A {}; X<A> x; 3225or 3226 template <typename T> class X {}; class A {}; template class X<A>; 3227or 3228 template <typename T> class X {}; class A {}; extern template class X<A>; 3229cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) 3230 matches the template instantiation of X<A>. 3231 3232But given 3233 template <typename T> class X {}; class A {}; 3234 template <> class X<A> {}; X<A> x; 3235cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) 3236 does not match, as X<A> is an explicit template specialization. 3237 3238Usable 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>> 3239</pre></td></tr> 3240 3241 3242<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> 3243<tr><td colspan="4" class="doc" id="isVariadic0"><pre>Matches if a function declaration is variadic. 3244 3245Example matches f, but not g or h. The function i will not match, even when 3246compiled in C mode. 3247 void f(...); 3248 void g(int); 3249 template <typename... Ts> void h(Ts...); 3250 void i(); 3251</pre></td></tr> 3252 3253 3254<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> 3255<tr><td colspan="4" class="doc" id="parameterCountIs0"><pre>Matches FunctionDecls and FunctionProtoTypes that have a 3256specific parameter count. 3257 3258Given 3259 void f(int i) {} 3260 void g(int i, int j) {} 3261 void h(int i, int j); 3262 void j(int i); 3263 void k(int x, int y, int z, ...); 3264functionDecl(parameterCountIs(2)) 3265 matches g and h 3266functionProtoType(parameterCountIs(2)) 3267 matches g and h 3268functionProtoType(parameterCountIs(3)) 3269 matches k 3270</pre></td></tr> 3271 3272 3273<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> 3274<tr><td colspan="4" class="doc" id="hasDynamicExceptionSpec1"><pre>Matches functions that have a dynamic exception specification. 3275 3276Given: 3277 void f(); 3278 void g() noexcept; 3279 void h() noexcept(true); 3280 void i() noexcept(false); 3281 void j() throw(); 3282 void k() throw(int); 3283 void l() throw(...); 3284functionDecl(hasDynamicExceptionSpec()) and 3285 functionProtoType(hasDynamicExceptionSpec()) 3286 match the declarations of j, k, and l, but not f, g, h, or i. 3287</pre></td></tr> 3288 3289 3290<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> 3291<tr><td colspan="4" class="doc" id="isNoThrow1"><pre>Matches functions that have a non-throwing exception specification. 3292 3293Given: 3294 void f(); 3295 void g() noexcept; 3296 void h() throw(); 3297 void i() throw(int); 3298 void j() noexcept(false); 3299functionDecl(isNoThrow()) and functionProtoType(isNoThrow()) 3300 match the declarations of g, and h, but not f, i or j. 3301</pre></td></tr> 3302 3303 3304<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> 3305<tr><td colspan="4" class="doc" id="parameterCountIs1"><pre>Matches FunctionDecls and FunctionProtoTypes that have a 3306specific parameter count. 3307 3308Given 3309 void f(int i) {} 3310 void g(int i, int j) {} 3311 void h(int i, int j); 3312 void j(int i); 3313 void k(int x, int y, int z, ...); 3314functionDecl(parameterCountIs(2)) 3315 matches g and h 3316functionProtoType(parameterCountIs(2)) 3317 matches g and h 3318functionProtoType(parameterCountIs(3)) 3319 matches k 3320</pre></td></tr> 3321 3322 3323<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> 3324<tr><td colspan="4" class="doc" id="isConstexpr2"><pre>Matches constexpr variable and function declarations, 3325 and if constexpr. 3326 3327Given: 3328 constexpr int foo = 42; 3329 constexpr int bar(); 3330 void baz() { if constexpr(1 > 0) {} } 3331varDecl(isConstexpr()) 3332 matches the declaration of foo. 3333functionDecl(isConstexpr()) 3334 matches the declaration of bar. 3335ifStmt(isConstexpr()) 3336 matches the if statement in baz. 3337</pre></td></tr> 3338 3339 3340<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> 3341<tr><td colspan="4" class="doc" id="equals6"><pre></pre></td></tr> 3342 3343 3344<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> 3345<tr><td colspan="4" class="doc" id="equals0"><pre>Matches literals that are equal to the given value of type ValueT. 3346 3347Given 3348 f('false, 3.14, 42); 3349characterLiteral(equals(0)) 3350 matches 'cxxBoolLiteral(equals(false)) and cxxBoolLiteral(equals(0)) 3351 match false 3352floatLiteral(equals(3.14)) and floatLiteral(equals(314e-2)) 3353 match 3.14 3354integerLiteral(equals(42)) 3355 matches 42 3356 3357Note that you cannot directly match a negative numeric literal because the 3358minus sign is not part of the literal: It is a unary operator whose operand 3359is the positive numeric literal. Instead, you must use a unaryOperator() 3360matcher to match the minus sign: 3361 3362unaryOperator(hasOperatorName("-"), 3363 hasUnaryOperand(integerLiteral(equals(13)))) 3364 3365Usable 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>>, 3366 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>> 3367</pre></td></tr> 3368 3369 3370<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> 3371<tr><td colspan="4" class="doc" id="equals13"><pre></pre></td></tr> 3372 3373 3374<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> 3375<tr><td colspan="4" class="doc" id="equals9"><pre></pre></td></tr> 3376 3377 3378<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> 3379<tr><td colspan="4" class="doc" id="isArrow0"><pre>Matches member expressions that are called with '->' as opposed 3380to '.'. 3381 3382Member calls on the implicit this pointer match as called with '->'. 3383 3384Given 3385 class Y { 3386 void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; } 3387 template <class T> void f() { this->f<T>(); f<T>(); } 3388 int a; 3389 static int b; 3390 }; 3391 template <class T> 3392 class Z { 3393 void x() { this->m; } 3394 }; 3395memberExpr(isArrow()) 3396 matches this->x, x, y.x, a, this->b 3397cxxDependentScopeMemberExpr(isArrow()) 3398 matches this->m 3399unresolvedMemberExpr(isArrow()) 3400 matches this->f<T>, f<T> 3401</pre></td></tr> 3402 3403 3404<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> 3405<tr><td colspan="4" class="doc" id="hasExternalFormalLinkage0"><pre>Matches a declaration that has external formal linkage. 3406 3407Example matches only z (matcher = varDecl(hasExternalFormalLinkage())) 3408void f() { 3409 int x; 3410 static int y; 3411} 3412int z; 3413 3414Example matches f() because it has external formal linkage despite being 3415unique to the translation unit as though it has internal likage 3416(matcher = functionDecl(hasExternalFormalLinkage())) 3417 3418namespace { 3419void f() {} 3420} 3421</pre></td></tr> 3422 3423 3424<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> 3425<tr><td colspan="4" class="doc" id="hasName0"><pre>Matches NamedDecl nodes that have the specified name. 3426 3427Supports specifying enclosing namespaces or classes by prefixing the name 3428with '<enclosing>::'. 3429Does not match typedefs of an underlying type with the given name. 3430 3431Example matches X (Name == "X") 3432 class X; 3433 3434Example matches X (Name is one of "::a::b::X", "a::b::X", "b::X", "X") 3435 namespace a { namespace b { class X; } } 3436</pre></td></tr> 3437 3438 3439<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> 3440<tr><td colspan="4" class="doc" id="matchesName0"><pre>Matches NamedDecl nodes whose fully qualified names contain 3441a substring matched by the given RegExp. 3442 3443Supports specifying enclosing namespaces or classes by 3444prefixing the name with '<enclosing>::'. Does not match typedefs 3445of an underlying type with the given name. 3446 3447Example matches X (regexp == "::X") 3448 class X; 3449 3450Example matches X (regexp is one of "::X", "^foo::.*X", among others) 3451 namespace foo { namespace bar { class X; } } 3452</pre></td></tr> 3453 3454 3455<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> 3456<tr><td colspan="4" class="doc" id="isAnonymous0"><pre>Matches anonymous namespace declarations. 3457 3458Given 3459 namespace n { 3460 namespace {} // #1 3461 } 3462namespaceDecl(isAnonymous()) will match #1 but not ::n. 3463</pre></td></tr> 3464 3465 3466<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> 3467<tr><td colspan="4" class="doc" id="isInline0"><pre>Matches function and namespace declarations that are marked with 3468the inline keyword. 3469 3470Given 3471 inline void f(); 3472 void g(); 3473 namespace n { 3474 inline namespace m {} 3475 } 3476functionDecl(isInline()) will match ::f(). 3477namespaceDecl(isInline()) will match n::m. 3478</pre></td></tr> 3479 3480 3481<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> 3482<tr><td colspan="4" class="doc" id="isNoneKind0"><pre>Matches if the OpenMP ``default`` clause has ``none`` kind specified. 3483 3484Given 3485 3486 #pragma omp parallel 3487 #pragma omp parallel default(none) 3488 #pragma omp parallel default(shared) 3489 3490``ompDefaultClause(isNoneKind())`` matches only ``default(none)``. 3491</pre></td></tr> 3492 3493 3494<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> 3495<tr><td colspan="4" class="doc" id="isSharedKind0"><pre>Matches if the OpenMP ``default`` clause has ``shared`` kind specified. 3496 3497Given 3498 3499 #pragma omp parallel 3500 #pragma omp parallel default(none) 3501 #pragma omp parallel default(shared) 3502 3503``ompDefaultClause(isSharedKind())`` matches only ``default(shared)``. 3504</pre></td></tr> 3505 3506 3507<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> 3508<tr><td colspan="4" class="doc" id="isAllowedToContainClauseKind0"><pre>Matches if the OpenMP directive is allowed to contain the specified OpenMP 3509clause kind. 3510 3511Given 3512 3513 #pragma omp parallel 3514 #pragma omp parallel for 3515 #pragma omp for 3516 3517`ompExecutableDirective(isAllowedToContainClause(OMPC_default))`` matches 3518``omp parallel`` and ``omp parallel for``. 3519 3520If the matcher is use from clang-query, ``OpenMPClauseKind`` parameter 3521should be passed as a quoted string. e.g., 3522``isAllowedToContainClauseKind("OMPC_default").`` 3523</pre></td></tr> 3524 3525 3526<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> 3527<tr><td colspan="4" class="doc" id="isStandaloneDirective0"><pre>Matches standalone OpenMP directives, 3528i.e., directives that can't have a structured block. 3529 3530Given 3531 3532 #pragma omp parallel 3533 {} 3534 #pragma omp taskyield 3535 3536``ompExecutableDirective(isStandaloneDirective()))`` matches 3537``omp taskyield``. 3538</pre></td></tr> 3539 3540 3541<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> 3542<tr><td colspan="4" class="doc" id="argumentCountIs2"><pre>Checks that a call expression or a constructor call expression has 3543a specific number of arguments (including absent default arguments). 3544 3545Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2))) 3546 void f(int x, int y); 3547 f(0, 0); 3548</pre></td></tr> 3549 3550 3551<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> 3552<tr><td colspan="4" class="doc" id="hasKeywordSelector0"><pre>Matches when the selector is a keyword selector 3553 3554objCMessageExpr(hasKeywordSelector()) matches the generated setFrame 3555message expression in 3556 3557 UIWebView *webView = ...; 3558 CGRect bodyFrame = webView.frame; 3559 bodyFrame.size.height = self.bodyContentHeight; 3560 webView.frame = bodyFrame; 3561 // ^---- matches here 3562</pre></td></tr> 3563 3564 3565<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> 3566<tr><td colspan="4" class="doc" id="hasNullSelector0"><pre>Matches when the selector is the empty selector 3567 3568Matches only when the selector of the objCMessageExpr is NULL. This may 3569represent an error condition in the tree! 3570</pre></td></tr> 3571 3572 3573<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> 3574<tr><td colspan="4" class="doc" id="hasSelector0"><pre>Matches when BaseName == Selector.getAsString() 3575 3576 matcher = objCMessageExpr(hasSelector("loadHTMLString:baseURL:")); 3577 matches the outer message expr in the code below, but NOT the message 3578 invocation for self.bodyView. 3579 [self.bodyView loadHTMLString:html baseURL:NULL]; 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('hasUnarySelector0')"><a name="hasUnarySelector0Anchor">hasUnarySelector</a></td><td></td></tr> 3584<tr><td colspan="4" class="doc" id="hasUnarySelector0"><pre>Matches when the selector is a Unary Selector 3585 3586 matcher = objCMessageExpr(matchesSelector(hasUnarySelector()); 3587 matches self.bodyView in the code below, but NOT the outer message 3588 invocation of "loadHTMLString:baseURL:". 3589 [self.bodyView loadHTMLString:html baseURL:NULL]; 3590</pre></td></tr> 3591 3592 3593<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> 3594<tr><td colspan="4" class="doc" id="isClassMessage0"><pre>Returns true when the Objective-C message is sent to a class. 3595 3596Example 3597matcher = objcMessageExpr(isClassMessage()) 3598matches 3599 [NSString stringWithFormat:@"format"]; 3600but not 3601 NSString *x = @"hello"; 3602 [x containsString:@"h"]; 3603</pre></td></tr> 3604 3605 3606<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> 3607<tr><td colspan="4" class="doc" id="isInstanceMessage0"><pre>Returns true when the Objective-C message is sent to an instance. 3608 3609Example 3610matcher = objcMessageExpr(isInstanceMessage()) 3611matches 3612 NSString *x = @"hello"; 3613 [x containsString:@"h"]; 3614but not 3615 [NSString stringWithFormat:@"format"]; 3616</pre></td></tr> 3617 3618 3619<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> 3620<tr><td colspan="4" class="doc" id="matchesSelector0"><pre>Matches ObjC selectors whose name contains 3621a substring matched by the given RegExp. 3622 matcher = objCMessageExpr(matchesSelector("loadHTMLStringmatches the outer message expr in the code below, but NOT the message 3623 invocation for self.bodyView. 3624 [self.bodyView loadHTMLString:html baseURL:NULL]; 3625</pre></td></tr> 3626 3627 3628<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> 3629<tr><td colspan="4" class="doc" id="numSelectorArgs0"><pre>Matches when the selector has the specified number of arguments 3630 3631 matcher = objCMessageExpr(numSelectorArgs(0)); 3632 matches self.bodyView in the code below 3633 3634 matcher = objCMessageExpr(numSelectorArgs(2)); 3635 matches the invocation of "loadHTMLString:baseURL:" but not that 3636 of self.bodyView 3637 [self.bodyView loadHTMLString:html baseURL:NULL]; 3638</pre></td></tr> 3639 3640 3641<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> 3642<tr><td colspan="4" class="doc" id="isClassMethod0"><pre>Returns true when the Objective-C method declaration is a class method. 3643 3644Example 3645matcher = objcMethodDecl(isClassMethod()) 3646matches 3647@interface I + (void)foo; @end 3648but not 3649@interface I - (void)bar; @end 3650</pre></td></tr> 3651 3652 3653<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> 3654<tr><td colspan="4" class="doc" id="isDefinition2"><pre>Matches if a declaration has a body attached. 3655 3656Example matches A, va, fa 3657 class A {}; 3658 class B; // Doesn't match, as it has no body. 3659 int va; 3660 extern int vb; // Doesn't match, as it doesn't define the variable. 3661 void fa() {} 3662 void fb(); // Doesn't match, as it has no body. 3663 @interface X 3664 - (void)ma; // Doesn't match, interface is declaration. 3665 @end 3666 @implementation X 3667 - (void)ma {} 3668 @end 3669 3670Usable 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>>, 3671 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html">ObjCMethodDecl</a>> 3672</pre></td></tr> 3673 3674 3675<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html">ObjCMethodDecl</a>></td><td class="name" onclick="toggle('isInstanceMethod0')"><a name="isInstanceMethod0Anchor">isInstanceMethod</a></td><td></td></tr> 3676<tr><td colspan="4" class="doc" id="isInstanceMethod0"><pre>Returns true when the Objective-C method declaration is an instance method. 3677 3678Example 3679matcher = objcMethodDecl(isInstanceMethod()) 3680matches 3681@interface I - (void)bar; @end 3682but not 3683@interface I + (void)foo; @end 3684</pre></td></tr> 3685 3686 3687<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> 3688<tr><td colspan="4" class="doc" id="hasDefaultArgument0"><pre>Matches a declaration that has default arguments. 3689 3690Example matches y (matcher = parmVarDecl(hasDefaultArgument())) 3691void x(int val) {} 3692void y(int val = 0) {} 3693</pre></td></tr> 3694 3695 3696<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> 3697<tr><td colspan="4" class="doc" id="asString0"><pre>Matches if the matched type is represented by the given string. 3698 3699Given 3700 class Y { public: void x(); }; 3701 void z() { Y* y; y->x(); } 3702cxxMemberCallExpr(on(hasType(asString("class Y *")))) 3703 matches y->x() 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('equalsBoundNode3')"><a name="equalsBoundNode3Anchor">equalsBoundNode</a></td><td>std::string ID</td></tr> 3708<tr><td colspan="4" class="doc" id="equalsBoundNode3"><pre>Matches if a node equals a previously bound node. 3709 3710Matches a node if it equals the node previously bound to ID. 3711 3712Given 3713 class X { int a; int b; }; 3714cxxRecordDecl( 3715 has(fieldDecl(hasName("a"), hasType(type().bind("t")))), 3716 has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t")))))) 3717 matches the class X, as a and b have the same type. 3718 3719Note that when multiple matches are involved via forEach* matchers, 3720equalsBoundNodes acts as a filter. 3721For example: 3722compoundStmt( 3723 forEachDescendant(varDecl().bind("d")), 3724 forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d")))))) 3725will trigger a match for each combination of variable declaration 3726and reference to that variable declaration within a compound statement. 3727</pre></td></tr> 3728 3729 3730<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> 3731<tr><td colspan="4" class="doc" id="hasLocalQualifiers0"><pre>Matches QualType nodes that have local CV-qualifiers attached to 3732the node, not hidden within a typedef. 3733 3734Given 3735 typedef const int const_int; 3736 const_int i; 3737 int *const j; 3738 int *volatile k; 3739 int m; 3740varDecl(hasType(hasLocalQualifiers())) matches only j and k. 3741i is const-qualified but the qualifier is not local. 3742</pre></td></tr> 3743 3744 3745<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> 3746<tr><td colspan="4" class="doc" id="isAnyCharacter0"><pre>Matches QualType nodes that are of character type. 3747 3748Given 3749 void a(char); 3750 void b(wchar_t); 3751 void c(double); 3752functionDecl(hasAnyParameter(hasType(isAnyCharacter()))) 3753matches "a(char)", "b(wchar_t)", but not "c(double)". 3754</pre></td></tr> 3755 3756 3757<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> 3758<tr><td colspan="4" class="doc" id="isAnyPointer0"><pre>Matches QualType nodes that are of any pointer type; this includes 3759the Objective-C object pointer type, which is different despite being 3760syntactically similar. 3761 3762Given 3763 int *i = nullptr; 3764 3765 @interface Foo 3766 @end 3767 Foo *f; 3768 3769 int j; 3770varDecl(hasType(isAnyPointer())) 3771 matches "int *i" and "Foo *f", but not "int j". 3772</pre></td></tr> 3773 3774 3775<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> 3776<tr><td colspan="4" class="doc" id="isConstQualified0"><pre>Matches QualType nodes that are const-qualified, i.e., that 3777include "top-level" const. 3778 3779Given 3780 void a(int); 3781 void b(int const); 3782 void c(const int); 3783 void d(const int*); 3784 void e(int const) {}; 3785functionDecl(hasAnyParameter(hasType(isConstQualified()))) 3786 matches "void b(int const)", "void c(const int)" and 3787 "void e(int const) {}". It does not match d as there 3788 is no top-level const on the parameter type "const int *". 3789</pre></td></tr> 3790 3791 3792<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> 3793<tr><td colspan="4" class="doc" id="isInteger0"><pre>Matches QualType nodes that are of integer type. 3794 3795Given 3796 void a(int); 3797 void b(long); 3798 void c(double); 3799functionDecl(hasAnyParameter(hasType(isInteger()))) 3800matches "a(int)", "b(long)", but not "c(double)". 3801</pre></td></tr> 3802 3803 3804<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> 3805<tr><td colspan="4" class="doc" id="isSignedInteger0"><pre>Matches QualType nodes that are of signed integer type. 3806 3807Given 3808 void a(int); 3809 void b(unsigned long); 3810 void c(double); 3811functionDecl(hasAnyParameter(hasType(isSignedInteger()))) 3812matches "a(int)", but not "b(unsigned long)" and "c(double)". 3813</pre></td></tr> 3814 3815 3816<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> 3817<tr><td colspan="4" class="doc" id="isUnsignedInteger0"><pre>Matches QualType nodes that are of unsigned integer type. 3818 3819Given 3820 void a(int); 3821 void b(unsigned long); 3822 void c(double); 3823functionDecl(hasAnyParameter(hasType(isUnsignedInteger()))) 3824matches "b(unsigned long)", but not "a(int)" and "c(double)". 3825</pre></td></tr> 3826 3827 3828<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> 3829<tr><td colspan="4" class="doc" id="isVolatileQualified0"><pre>Matches QualType nodes that are volatile-qualified, i.e., that 3830include "top-level" volatile. 3831 3832Given 3833 void a(int); 3834 void b(int volatile); 3835 void c(volatile int); 3836 void d(volatile int*); 3837 void e(int volatile) {}; 3838functionDecl(hasAnyParameter(hasType(isVolatileQualified()))) 3839 matches "void b(int volatile)", "void c(volatile int)" and 3840 "void e(int volatile) {}". It does not match d as there 3841 is no top-level volatile on the parameter type "volatile int *". 3842</pre></td></tr> 3843 3844 3845<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> 3846<tr><td colspan="4" class="doc" id="isClass0"><pre>Matches RecordDecl object that are spelled with "class." 3847 3848Example matches C, but not S or U. 3849 struct S {}; 3850 class C {}; 3851 union U {}; 3852</pre></td></tr> 3853 3854 3855<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> 3856<tr><td colspan="4" class="doc" id="isStruct0"><pre>Matches RecordDecl object that are spelled with "struct." 3857 3858Example matches S, but not C or U. 3859 struct S {}; 3860 class C {}; 3861 union U {}; 3862</pre></td></tr> 3863 3864 3865<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> 3866<tr><td colspan="4" class="doc" id="isUnion0"><pre>Matches RecordDecl object that are spelled with "union." 3867 3868Example matches U, but not C or S. 3869 struct S {}; 3870 class C {}; 3871 union U {}; 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('equalsBoundNode0')"><a name="equalsBoundNode0Anchor">equalsBoundNode</a></td><td>std::string ID</td></tr> 3876<tr><td colspan="4" class="doc" id="equalsBoundNode0"><pre>Matches if a node equals a previously bound node. 3877 3878Matches a node if it equals the node previously bound to ID. 3879 3880Given 3881 class X { int a; int b; }; 3882cxxRecordDecl( 3883 has(fieldDecl(hasName("a"), hasType(type().bind("t")))), 3884 has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t")))))) 3885 matches the class X, as a and b have the same type. 3886 3887Note that when multiple matches are involved via forEach* matchers, 3888equalsBoundNodes acts as a filter. 3889For example: 3890compoundStmt( 3891 forEachDescendant(varDecl().bind("d")), 3892 forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d")))))) 3893will trigger a match for each combination of variable declaration 3894and reference to that variable declaration within a compound statement. 3895</pre></td></tr> 3896 3897 3898<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> 3899<tr><td colspan="4" class="doc" id="equalsNode1"><pre>Matches if a node equals another node. 3900 3901Stmt has pointer identity in the AST. 3902</pre></td></tr> 3903 3904 3905<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> 3906<tr><td colspan="4" class="doc" id="isExpansionInFileMatching1"><pre>Matches AST nodes that were expanded within files whose name is 3907partially matching a given regex. 3908 3909Example matches Y but not X 3910 (matcher = cxxRecordDecl(isExpansionInFileMatching("AST.*")) 3911 #include "ASTMatcher.h" 3912 class X {}; 3913ASTMatcher.h: 3914 class Y {}; 3915 3916Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> 3917</pre></td></tr> 3918 3919 3920<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('isExpansionInMainFile1')"><a name="isExpansionInMainFile1Anchor">isExpansionInMainFile</a></td><td></td></tr> 3921<tr><td colspan="4" class="doc" id="isExpansionInMainFile1"><pre>Matches AST nodes that were expanded within the main-file. 3922 3923Example matches X but not Y 3924 (matcher = cxxRecordDecl(isExpansionInMainFile()) 3925 #include <Y.h> 3926 class X {}; 3927Y.h: 3928 class Y {}; 3929 3930Usable 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>> 3931</pre></td></tr> 3932 3933 3934<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> 3935<tr><td colspan="4" class="doc" id="isExpansionInSystemHeader1"><pre>Matches AST nodes that were expanded within system-header-files. 3936 3937Example matches Y but not X 3938 (matcher = cxxRecordDecl(isExpansionInSystemHeader()) 3939 #include <SystemHeader.h> 3940 class X {}; 3941SystemHeader.h: 3942 class Y {}; 3943 3944Usable 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>> 3945</pre></td></tr> 3946 3947 3948<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> 3949<tr><td colspan="4" class="doc" id="isOMPStructuredBlock0"><pre>Matches the Stmt AST node that is marked as being the structured-block 3950of an OpenMP executable directive. 3951 3952Given 3953 3954 #pragma omp parallel 3955 {} 3956 3957``stmt(isOMPStructuredBlock()))`` matches ``{}``. 3958</pre></td></tr> 3959 3960 3961<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> 3962<tr><td colspan="4" class="doc" id="hasSize1"><pre>Matches nodes that have the specified size. 3963 3964Given 3965 int a[42]; 3966 int b[2 * 21]; 3967 int c[41], d[43]; 3968 char *s = "abcd"; 3969 wchar_t *ws = L"abcd"; 3970 char *w = "a"; 3971constantArrayType(hasSize(42)) 3972 matches "int a[42]" and "int b[2 * 21]" 3973stringLiteral(hasSize(4)) 3974 matches "abcd", L"abcd" 3975</pre></td></tr> 3976 3977 3978<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> 3979<tr><td colspan="4" class="doc" id="isDefinition0"><pre>Matches if a declaration has a body attached. 3980 3981Example matches A, va, fa 3982 class A {}; 3983 class B; // Doesn't match, as it has no body. 3984 int va; 3985 extern int vb; // Doesn't match, as it doesn't define the variable. 3986 void fa() {} 3987 void fb(); // Doesn't match, as it has no body. 3988 @interface X 3989 - (void)ma; // Doesn't match, interface is declaration. 3990 @end 3991 @implementation X 3992 - (void)ma {} 3993 @end 3994 3995Usable 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>>, 3996 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html">ObjCMethodDecl</a>> 3997</pre></td></tr> 3998 3999 4000<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> 4001<tr><td colspan="4" class="doc" id="equalsIntegralValue0"><pre>Matches a TemplateArgument of integral type with a given value. 4002 4003Note that 'Value' is a string as the template argument's value is 4004an arbitrary precision integer. 'Value' must be euqal to the canonical 4005representation of that integral value in base 10. 4006 4007Given 4008 template<int T> struct C {}; 4009 C<42> c; 4010classTemplateSpecializationDecl( 4011 hasAnyTemplateArgument(equalsIntegralValue("42"))) 4012 matches the implicit instantiation of C in C<42>. 4013</pre></td></tr> 4014 4015 4016<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> 4017<tr><td colspan="4" class="doc" id="isIntegral0"><pre>Matches a TemplateArgument that is an integral value. 4018 4019Given 4020 template<int T> struct C {}; 4021 C<42> c; 4022classTemplateSpecializationDecl( 4023 hasAnyTemplateArgument(isIntegral())) 4024 matches the implicit instantiation of C in C<42> 4025 with isIntegral() matching 42. 4026</pre></td></tr> 4027 4028 4029<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> 4030<tr><td colspan="4" class="doc" id="templateArgumentCountIs1"><pre>Matches if the number of template arguments equals N. 4031 4032Given 4033 template<typename T> struct C {}; 4034 C<int> c; 4035classTemplateSpecializationDecl(templateArgumentCountIs(1)) 4036 matches C<int>. 4037</pre></td></tr> 4038 4039 4040<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> 4041<tr><td colspan="4" class="doc" id="isExpansionInFileMatching2"><pre>Matches AST nodes that were expanded within files whose name is 4042partially matching a given regex. 4043 4044Example matches Y but not X 4045 (matcher = cxxRecordDecl(isExpansionInFileMatching("AST.*")) 4046 #include "ASTMatcher.h" 4047 class X {}; 4048ASTMatcher.h: 4049 class Y {}; 4050 4051Usable 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>> 4052</pre></td></tr> 4053 4054 4055<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> 4056<tr><td colspan="4" class="doc" id="isExpansionInMainFile2"><pre>Matches AST nodes that were expanded within the main-file. 4057 4058Example matches X but not Y 4059 (matcher = cxxRecordDecl(isExpansionInMainFile()) 4060 #include <Y.h> 4061 class X {}; 4062Y.h: 4063 class Y {}; 4064 4065Usable 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>> 4066</pre></td></tr> 4067 4068 4069<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> 4070<tr><td colspan="4" class="doc" id="isExpansionInSystemHeader2"><pre>Matches AST nodes that were expanded within system-header-files. 4071 4072Example matches Y but not X 4073 (matcher = cxxRecordDecl(isExpansionInSystemHeader()) 4074 #include <SystemHeader.h> 4075 class X {}; 4076SystemHeader.h: 4077 class Y {}; 4078 4079Usable 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>> 4080</pre></td></tr> 4081 4082 4083<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> 4084<tr><td colspan="4" class="doc" id="booleanType0"><pre>Matches type bool. 4085 4086Given 4087 struct S { bool func(); }; 4088functionDecl(returns(booleanType())) 4089 matches "bool func();" 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('equalsBoundNode2')"><a name="equalsBoundNode2Anchor">equalsBoundNode</a></td><td>std::string ID</td></tr> 4094<tr><td colspan="4" class="doc" id="equalsBoundNode2"><pre>Matches if a node equals a previously bound node. 4095 4096Matches a node if it equals the node previously bound to ID. 4097 4098Given 4099 class X { int a; int b; }; 4100cxxRecordDecl( 4101 has(fieldDecl(hasName("a"), hasType(type().bind("t")))), 4102 has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t")))))) 4103 matches the class X, as a and b have the same type. 4104 4105Note that when multiple matches are involved via forEach* matchers, 4106equalsBoundNodes acts as a filter. 4107For example: 4108compoundStmt( 4109 forEachDescendant(varDecl().bind("d")), 4110 forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d")))))) 4111will trigger a match for each combination of variable declaration 4112and reference to that variable declaration within a compound statement. 4113</pre></td></tr> 4114 4115 4116<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> 4117<tr><td colspan="4" class="doc" id="equalsNode2"><pre>Matches if a node equals another node. 4118 4119Type has pointer identity in the AST. 4120</pre></td></tr> 4121 4122 4123<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> 4124<tr><td colspan="4" class="doc" id="realFloatingPointType0"><pre>Matches any real floating-point type (float, double, long double). 4125 4126Given 4127 int i; 4128 float f; 4129realFloatingPointType() 4130 matches "float f" but not "int i" 4131</pre></td></tr> 4132 4133 4134<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> 4135<tr><td colspan="4" class="doc" id="voidType0"><pre>Matches type void. 4136 4137Given 4138 struct S { void func(); }; 4139functionDecl(returns(voidType())) 4140 matches "void func();" 4141</pre></td></tr> 4142 4143 4144<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> 4145<tr><td colspan="4" class="doc" id="ofKind0"><pre>Matches unary expressions of a certain kind. 4146 4147Given 4148 int x; 4149 int s = sizeof(x) + alignof(x) 4150unaryExprOrTypeTraitExpr(ofKind(UETT_SizeOf)) 4151 matches sizeof(x) 4152 4153If the matcher is use from clang-query, UnaryExprOrTypeTrait parameter 4154should be passed as a quoted string. e.g., ofKind("UETT_SizeOf"). 4155</pre></td></tr> 4156 4157 4158<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> 4159<tr><td colspan="4" class="doc" id="hasOperatorName1"><pre>Matches the operator Name of operator expressions (binary or 4160unary). 4161 4162Example matches a || b (matcher = binaryOperator(hasOperatorName("||"))) 4163 !(a || b) 4164</pre></td></tr> 4165 4166 4167<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> 4168<tr><td colspan="4" class="doc" id="isArrow1"><pre>Matches member expressions that are called with '->' as opposed 4169to '.'. 4170 4171Member calls on the implicit this pointer match as called with '->'. 4172 4173Given 4174 class Y { 4175 void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; } 4176 template <class T> void f() { this->f<T>(); f<T>(); } 4177 int a; 4178 static int b; 4179 }; 4180 template <class T> 4181 class Z { 4182 void x() { this->m; } 4183 }; 4184memberExpr(isArrow()) 4185 matches this->x, x, y.x, a, this->b 4186cxxDependentScopeMemberExpr(isArrow()) 4187 matches this->m 4188unresolvedMemberExpr(isArrow()) 4189 matches this->f<T>, f<T> 4190</pre></td></tr> 4191 4192 4193<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>></td><td class="name" onclick="toggle('hasAutomaticStorageDuration0')"><a name="hasAutomaticStorageDuration0Anchor">hasAutomaticStorageDuration</a></td><td></td></tr> 4194<tr><td colspan="4" class="doc" id="hasAutomaticStorageDuration0"><pre>Matches a variable declaration that has automatic storage duration. 4195 4196Example matches x, but not y, z, or a. 4197(matcher = varDecl(hasAutomaticStorageDuration()) 4198void f() { 4199 int x; 4200 static int y; 4201 thread_local int z; 4202} 4203int a; 4204</pre></td></tr> 4205 4206 4207<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> 4208<tr><td colspan="4" class="doc" id="hasGlobalStorage0"><pre>Matches a variable declaration that does not have local storage. 4209 4210Example matches y and z (matcher = varDecl(hasGlobalStorage()) 4211void f() { 4212 int x; 4213 static int y; 4214} 4215int z; 4216</pre></td></tr> 4217 4218 4219<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> 4220<tr><td colspan="4" class="doc" id="hasLocalStorage0"><pre>Matches a variable declaration that has function scope and is a 4221non-static local variable. 4222 4223Example matches x (matcher = varDecl(hasLocalStorage()) 4224void f() { 4225 int x; 4226 static int y; 4227} 4228int z; 4229</pre></td></tr> 4230 4231 4232<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> 4233<tr><td colspan="4" class="doc" id="hasStaticStorageDuration0"><pre>Matches a variable declaration that has static storage duration. 4234It includes the variable declared at namespace scope and those declared 4235with "static" and "extern" storage class specifiers. 4236 4237void f() { 4238 int x; 4239 static int y; 4240 thread_local int z; 4241} 4242int a; 4243static int b; 4244extern int c; 4245varDecl(hasStaticStorageDuration()) 4246 matches the function declaration y, a, b and c. 4247</pre></td></tr> 4248 4249 4250<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> 4251<tr><td colspan="4" class="doc" id="hasThreadStorageDuration0"><pre>Matches a variable declaration that has thread storage duration. 4252 4253Example matches z, but not x, z, or a. 4254(matcher = varDecl(hasThreadStorageDuration()) 4255void f() { 4256 int x; 4257 static int y; 4258 thread_local int z; 4259} 4260int a; 4261</pre></td></tr> 4262 4263 4264<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> 4265<tr><td colspan="4" class="doc" id="isConstexpr0"><pre>Matches constexpr variable and function declarations, 4266 and if constexpr. 4267 4268Given: 4269 constexpr int foo = 42; 4270 constexpr int bar(); 4271 void baz() { if constexpr(1 > 0) {} } 4272varDecl(isConstexpr()) 4273 matches the declaration of foo. 4274functionDecl(isConstexpr()) 4275 matches the declaration of bar. 4276ifStmt(isConstexpr()) 4277 matches the if statement in baz. 4278</pre></td></tr> 4279 4280 4281<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> 4282<tr><td colspan="4" class="doc" id="isDefinition1"><pre>Matches if a declaration has a body attached. 4283 4284Example matches A, va, fa 4285 class A {}; 4286 class B; // Doesn't match, as it has no body. 4287 int va; 4288 extern int vb; // Doesn't match, as it doesn't define the variable. 4289 void fa() {} 4290 void fb(); // Doesn't match, as it has no body. 4291 @interface X 4292 - (void)ma; // Doesn't match, interface is declaration. 4293 @end 4294 @implementation X 4295 - (void)ma {} 4296 @end 4297 4298Usable 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>>, 4299 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html">ObjCMethodDecl</a>> 4300</pre></td></tr> 4301 4302 4303<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> 4304<tr><td colspan="4" class="doc" id="isExceptionVariable0"><pre>Matches a variable declaration that is an exception variable from 4305a C++ catch block, or an Objective-C statement. 4306 4307Example matches x (matcher = varDecl(isExceptionVariable()) 4308void f(int y) { 4309 try { 4310 } catch (int x) { 4311 } 4312} 4313</pre></td></tr> 4314 4315 4316<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> 4317<tr><td colspan="4" class="doc" id="isExplicitTemplateSpecialization1"><pre>Matches explicit template specializations of function, class, or 4318static member variable template instantiations. 4319 4320Given 4321 template<typename T> void A(T t) { } 4322 template<> void A(int N) { } 4323functionDecl(isExplicitTemplateSpecialization()) 4324 matches the specialization A<int>(). 4325 4326Usable 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>> 4327</pre></td></tr> 4328 4329 4330<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> 4331<tr><td colspan="4" class="doc" id="isExternC1"><pre>Matches extern "C" function or variable declarations. 4332 4333Given: 4334 extern "C" void f() {} 4335 extern "C" { void g() {} } 4336 void h() {} 4337 extern "C" int x = 1; 4338 extern "C" int y = 2; 4339 int z = 3; 4340functionDecl(isExternC()) 4341 matches the declaration of f and g, but not the declaration of h. 4342varDecl(isExternC()) 4343 matches the declaration of x and y, but not the declaration of z. 4344</pre></td></tr> 4345 4346 4347<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> 4348<tr><td colspan="4" class="doc" id="isStaticLocal0"><pre>Matches a static variable with local scope. 4349 4350Example matches y (matcher = varDecl(isStaticLocal())) 4351void f() { 4352 int x; 4353 static int y; 4354} 4355static int z; 4356</pre></td></tr> 4357 4358 4359<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> 4360<tr><td colspan="4" class="doc" id="isStaticStorageClass1"><pre>Matches variable/function declarations that have "static" storage 4361class specifier ("static" keyword) written in the source. 4362 4363Given: 4364 static void f() {} 4365 static int i = 0; 4366 extern int j; 4367 int k; 4368functionDecl(isStaticStorageClass()) 4369 matches the function declaration f. 4370varDecl(isStaticStorageClass()) 4371 matches the variable declaration i. 4372</pre></td></tr> 4373 4374 4375<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> 4376<tr><td colspan="4" class="doc" id="isTemplateInstantiation1"><pre>Matches template instantiations of function, class, or static 4377member variable template instantiations. 4378 4379Given 4380 template <typename T> class X {}; class A {}; X<A> x; 4381or 4382 template <typename T> class X {}; class A {}; template class X<A>; 4383or 4384 template <typename T> class X {}; class A {}; extern template class X<A>; 4385cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) 4386 matches the template instantiation of X<A>. 4387 4388But given 4389 template <typename T> class X {}; class A {}; 4390 template <> class X<A> {}; X<A> x; 4391cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) 4392 does not match, as X<A> is an explicit template specialization. 4393 4394Usable 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>> 4395</pre></td></tr> 4396 4397 4398<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> 4399<tr><td colspan="4" class="doc" id="isInstantiated0"><pre>Matches declarations that are template instantiations or are inside 4400template instantiations. 4401 4402Given 4403 template<typename T> void A(T t) { T i; } 4404 A(0); 4405 A(0U); 4406functionDecl(isInstantiated()) 4407 matches 'A(int) {...};' and 'A(unsigned) {...}'. 4408</pre></td></tr> 4409 4410 4411<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> 4412<tr><td colspan="4" class="doc" id="nullPointerConstant0"><pre>Matches expressions that resolve to a null pointer constant, such as 4413GNU's __null, C++11's nullptr, or C's NULL macro. 4414 4415Given: 4416 void *v1 = NULL; 4417 void *v2 = nullptr; 4418 void *v3 = __null; // GNU extension 4419 char *cp = (char *)0; 4420 int *ip = 0; 4421 int i = 0; 4422expr(nullPointerConstant()) 4423 matches the initializer for v1, v2, v3, cp, and ip. Does not match the 4424 initializer for i. 4425</pre></td></tr> 4426 4427 4428<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> 4429<tr><td colspan="4" class="doc" id="hasAnyName0"><pre>Matches NamedDecl nodes that have any of the specified names. 4430 4431This matcher is only provided as a performance optimization of hasName. 4432 hasAnyName(a, b, c) 4433 is equivalent to, but faster than 4434 anyOf(hasName(a), hasName(b), hasName(c)) 4435</pre></td></tr> 4436 4437 4438<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> 4439<tr><td colspan="4" class="doc" id="hasAnySelector0"><pre>Matches when at least one of the supplied string equals to the 4440Selector.getAsString() 4441 4442 matcher = objCMessageExpr(hasSelector("methodA:", "methodB:")); 4443 matches both of the expressions below: 4444 [myObj methodA:argA]; 4445 [myObj methodB:argB]; 4446</pre></td></tr> 4447 4448 4449<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> 4450<tr><td colspan="4" class="doc" id="isInTemplateInstantiation0"><pre>Matches statements inside of a template instantiation. 4451 4452Given 4453 int j; 4454 template<typename T> void A(T t) { T i; j += 42;} 4455 A(0); 4456 A(0U); 4457declStmt(isInTemplateInstantiation()) 4458 matches 'int i;' and 'unsigned i'. 4459unless(stmt(isInTemplateInstantiation())) 4460 will NOT match j += 42; as it's shared between the template definition and 4461 instantiation. 4462</pre></td></tr> 4463 4464<!--END_NARROWING_MATCHERS --> 4465</table> 4466 4467<!-- ======================================================================= --> 4468<h2 id="traversal-matchers">AST Traversal Matchers</h2> 4469<!-- ======================================================================= --> 4470 4471<p>Traversal matchers specify the relationship to other nodes that are 4472reachable from the current node.</p> 4473 4474<p>Note that there are special traversal matchers (has, hasDescendant, forEach and 4475forEachDescendant) which work on all nodes and allow users to write more generic 4476match expressions.</p> 4477 4478<table> 4479<tr style="text-align:left"><th>Return type</th><th>Name</th><th>Parameters</th></tr> 4480<!-- START_TRAVERSAL_MATCHERS --> 4481 4482<tr><td>Matcher<*></td><td class="name" onclick="toggle('eachOf0')"><a name="eachOf0Anchor">eachOf</a></td><td>Matcher<*>, ..., Matcher<*></td></tr> 4483<tr><td colspan="4" class="doc" id="eachOf0"><pre>Matches if any of the given matchers matches. 4484 4485Unlike anyOf, eachOf will generate a match result for each 4486matching submatcher. 4487 4488For example, in: 4489 class A { int a; int b; }; 4490The matcher: 4491 cxxRecordDecl(eachOf(has(fieldDecl(hasName("a")).bind("v")), 4492 has(fieldDecl(hasName("b")).bind("v")))) 4493will generate two results binding "v", the first of which binds 4494the field declaration of a, the second the field declaration of 4495b. 4496 4497Usable as: Any Matcher 4498</pre></td></tr> 4499 4500 4501<tr><td>Matcher<*></td><td class="name" onclick="toggle('forEachDescendant0')"><a name="forEachDescendant0Anchor">forEachDescendant</a></td><td>Matcher<*></td></tr> 4502<tr><td colspan="4" class="doc" id="forEachDescendant0"><pre>Matches AST nodes that have descendant AST nodes that match the 4503provided matcher. 4504 4505Example matches X, A, A::X, B, B::C, B::C::X 4506 (matcher = cxxRecordDecl(forEachDescendant(cxxRecordDecl(hasName("X"))))) 4507 class X {}; 4508 class A { class X {}; }; // Matches A, because A::X is a class of name 4509 // X inside A. 4510 class B { class C { class X {}; }; }; 4511 4512DescendantT must be an AST base type. 4513 4514As opposed to 'hasDescendant', 'forEachDescendant' will cause a match for 4515each result that matches instead of only on the first one. 4516 4517Note: Recursively combined ForEachDescendant can cause many matches: 4518 cxxRecordDecl(forEachDescendant(cxxRecordDecl( 4519 forEachDescendant(cxxRecordDecl()) 4520 ))) 4521will match 10 times (plus injected class name matches) on: 4522 class A { class B { class C { class D { class E {}; }; }; }; }; 4523 4524Usable as: Any Matcher 4525</pre></td></tr> 4526 4527 4528<tr><td>Matcher<*></td><td class="name" onclick="toggle('forEach0')"><a name="forEach0Anchor">forEach</a></td><td>Matcher<*></td></tr> 4529<tr><td colspan="4" class="doc" id="forEach0"><pre>Matches AST nodes that have child AST nodes that match the 4530provided matcher. 4531 4532Example matches X, Y, Y::X, Z::Y, Z::Y::X 4533 (matcher = cxxRecordDecl(forEach(cxxRecordDecl(hasName("X"))) 4534 class X {}; 4535 class Y { class X {}; }; // Matches Y, because Y::X is a class of name X 4536 // inside Y. 4537 class Z { class Y { class X {}; }; }; // Does not match Z. 4538 4539ChildT must be an AST base type. 4540 4541As opposed to 'has', 'forEach' will cause a match for each result that 4542matches instead of only on the first one. 4543 4544Usable as: Any Matcher 4545</pre></td></tr> 4546 4547 4548<tr><td>Matcher<*></td><td class="name" onclick="toggle('hasAncestor0')"><a name="hasAncestor0Anchor">hasAncestor</a></td><td>Matcher<*></td></tr> 4549<tr><td colspan="4" class="doc" id="hasAncestor0"><pre>Matches AST nodes that have an ancestor that matches the provided 4550matcher. 4551 4552Given 4553void f() { if (true) { int x = 42; } } 4554void g() { for (;;) { int x = 43; } } 4555expr(integerLiteral(hasAncestor(ifStmt()))) matches 42, but not 43. 4556 4557Usable as: Any Matcher 4558</pre></td></tr> 4559 4560 4561<tr><td>Matcher<*></td><td class="name" onclick="toggle('hasDescendant0')"><a name="hasDescendant0Anchor">hasDescendant</a></td><td>Matcher<*></td></tr> 4562<tr><td colspan="4" class="doc" id="hasDescendant0"><pre>Matches AST nodes that have descendant AST nodes that match the 4563provided matcher. 4564 4565Example matches X, Y, Z 4566 (matcher = cxxRecordDecl(hasDescendant(cxxRecordDecl(hasName("X"))))) 4567 class X {}; // Matches X, because X::X is a class of name X inside X. 4568 class Y { class X {}; }; 4569 class Z { class Y { class X {}; }; }; 4570 4571DescendantT must be an AST base type. 4572 4573Usable as: Any Matcher 4574</pre></td></tr> 4575 4576 4577<tr><td>Matcher<*></td><td class="name" onclick="toggle('has0')"><a name="has0Anchor">has</a></td><td>Matcher<*></td></tr> 4578<tr><td colspan="4" class="doc" id="has0"><pre>Matches AST nodes that have child AST nodes that match the 4579provided matcher. 4580 4581Example matches X, Y 4582 (matcher = cxxRecordDecl(has(cxxRecordDecl(hasName("X"))) 4583 class X {}; // Matches X, because X::X is a class of name X inside X. 4584 class Y { class X {}; }; 4585 class Z { class Y { class X {}; }; }; // Does not match Z. 4586 4587ChildT must be an AST base type. 4588 4589Usable as: Any Matcher 4590Note that has is direct matcher, so it also matches things like implicit 4591casts and paren casts. If you are matching with expr then you should 4592probably consider using ignoringParenImpCasts like: 4593has(ignoringParenImpCasts(expr())). 4594</pre></td></tr> 4595 4596 4597<tr><td>Matcher<*></td><td class="name" onclick="toggle('hasParent0')"><a name="hasParent0Anchor">hasParent</a></td><td>Matcher<*></td></tr> 4598<tr><td colspan="4" class="doc" id="hasParent0"><pre>Matches AST nodes that have a parent that matches the provided 4599matcher. 4600 4601Given 4602void f() { for (;;) { int x = 42; if (true) { int x = 43; } } } 4603compoundStmt(hasParent(ifStmt())) matches "{ int x = 43; }". 4604 4605Usable as: Any Matcher 4606</pre></td></tr> 4607 4608 4609<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> 4610<tr><td colspan="4" class="doc" id="hasCondition5"><pre>Matches the condition expression of an if statement, for loop, 4611switch statement or conditional operator. 4612 4613Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true)))) 4614 if (true) {} 4615</pre></td></tr> 4616 4617 4618<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> 4619<tr><td colspan="4" class="doc" id="hasFalseExpression0"><pre>Matches the false branch expression of a conditional operator 4620(binary or ternary). 4621 4622Example matches b 4623 condition ? a : b 4624 condition ?: b 4625</pre></td></tr> 4626 4627 4628<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> 4629<tr><td colspan="4" class="doc" id="hasTrueExpression0"><pre>Matches the true branch expression of a conditional operator. 4630 4631Example 1 (conditional ternary operator): matches a 4632 condition ? a : b 4633 4634Example 2 (conditional binary operator): matches opaqueValueExpr(condition) 4635 condition ?: b 4636</pre></td></tr> 4637 4638 4639<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> 4640<tr><td colspan="4" class="doc" id="hasDeclaration15"><pre>Matches a node if the declaration associated with that node 4641matches the given matcher. 4642 4643The associated declaration is: 4644- for type nodes, the declaration of the underlying type 4645- for CallExpr, the declaration of the callee 4646- for MemberExpr, the declaration of the referenced member 4647- for CXXConstructExpr, the declaration of the constructor 4648- for CXXNewExpr, the declaration of the operator new 4649- for ObjCIvarExpr, the declaration of the ivar 4650 4651For type nodes, hasDeclaration will generally match the declaration of the 4652sugared type. Given 4653 class X {}; 4654 typedef X Y; 4655 Y y; 4656in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 4657typedefDecl. A common use case is to match the underlying, desugared type. 4658This can be achieved by using the hasUnqualifiedDesugaredType matcher: 4659 varDecl(hasType(hasUnqualifiedDesugaredType( 4660 recordType(hasDeclaration(decl()))))) 4661In this matcher, the decl will match the CXXRecordDecl of class X. 4662 4663Usable 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>>, 4664 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>>, 4665 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>>, 4666 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>>, 4667 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>>, 4668 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>>, 4669 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 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('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> 4674<tr><td colspan="4" class="doc" id="hasBase0"><pre>Matches the base expression of an array subscript expression. 4675 4676Given 4677 int i[5]; 4678 void f() { i[1] = 42; } 4679arraySubscriptExpression(hasBase(implicitCastExpr( 4680 hasSourceExpression(declRefExpr())))) 4681 matches i[1] with the declRefExpr() matching i 4682</pre></td></tr> 4683 4684 4685<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> 4686<tr><td colspan="4" class="doc" id="hasIndex0"><pre>Matches the index expression of an array subscript expression. 4687 4688Given 4689 int i[5]; 4690 void f() { i[1] = 42; } 4691arraySubscriptExpression(hasIndex(integerLiteral())) 4692 matches i[1] with the integerLiteral() matching 1 4693</pre></td></tr> 4694 4695 4696<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> 4697<tr><td colspan="4" class="doc" id="hasLHS1"><pre>Matches the left hand side of binary operator expressions. 4698 4699Example matches a (matcher = binaryOperator(hasLHS())) 4700 a || b 4701</pre></td></tr> 4702 4703 4704<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> 4705<tr><td colspan="4" class="doc" id="hasRHS1"><pre>Matches the right hand side of binary operator expressions. 4706 4707Example matches b (matcher = binaryOperator(hasRHS())) 4708 a || b 4709</pre></td></tr> 4710 4711 4712<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> 4713<tr><td colspan="4" class="doc" id="hasElementType0"><pre>Matches arrays and C99 complex types that have a specific element 4714type. 4715 4716Given 4717 struct A {}; 4718 A a[7]; 4719 int b[7]; 4720arrayType(hasElementType(builtinType())) 4721 matches "int b[7]" 4722 4723Usable 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>> 4724</pre></td></tr> 4725 4726 4727<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> 4728<tr><td colspan="4" class="doc" id="hasValueType0"><pre>Matches atomic types with a specific value type. 4729 4730Given 4731 _Atomic(int) i; 4732 _Atomic(float) f; 4733atomicType(hasValueType(isInteger())) 4734 matches "_Atomic(int) i" 4735 4736Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AtomicType.html">AtomicType</a>> 4737</pre></td></tr> 4738 4739 4740<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> 4741<tr><td colspan="4" class="doc" id="hasDeducedType0"><pre>Matches AutoType nodes where the deduced type is a specific type. 4742 4743Note: There is no TypeLoc for the deduced type and thus no 4744getDeducedLoc() matcher. 4745 4746Given 4747 auto a = 1; 4748 auto b = 2.0; 4749autoType(hasDeducedType(isInteger())) 4750 matches "auto a" 4751 4752Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AutoType.html">AutoType</a>> 4753</pre></td></tr> 4754 4755 4756<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> 4757<tr><td colspan="4" class="doc" id="hasEitherOperand0"><pre>Matches if either the left hand side or the right hand side of a 4758binary operator matches. 4759</pre></td></tr> 4760 4761 4762<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> 4763<tr><td colspan="4" class="doc" id="hasLHS0"><pre>Matches the left hand side of binary operator expressions. 4764 4765Example matches a (matcher = binaryOperator(hasLHS())) 4766 a || b 4767</pre></td></tr> 4768 4769 4770<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> 4771<tr><td colspan="4" class="doc" id="hasRHS0"><pre>Matches the right hand side of binary operator expressions. 4772 4773Example matches b (matcher = binaryOperator(hasRHS())) 4774 a || b 4775</pre></td></tr> 4776 4777 4778<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> 4779<tr><td colspan="4" class="doc" id="hasAnyParameter2"><pre>Matches any parameter of a function or an ObjC method declaration or a 4780block. 4781 4782Does not match the 'this' parameter of a method. 4783 4784Given 4785 class X { void f(int x, int y, int z) {} }; 4786cxxMethodDecl(hasAnyParameter(hasName("y"))) 4787 matches f(int x, int y, int z) {} 4788with hasAnyParameter(...) 4789 matching int y 4790 4791For ObjectiveC, given 4792 @interface I - (void) f:(int) y; @end 4793 4794the matcher objcMethodDecl(hasAnyParameter(hasName("y"))) 4795matches the declaration of method f with hasParameter 4796matching y. 4797 4798For blocks, given 4799 b = ^(int y) { printf("%d", y) }; 4800 4801the matcher blockDecl(hasAnyParameter(hasName("y"))) 4802matches the declaration of the block b with hasParameter 4803matching y. 4804</pre></td></tr> 4805 4806 4807<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> 4808<tr><td colspan="4" class="doc" id="hasParameter2"><pre>Matches the n'th parameter of a function or an ObjC method 4809declaration or a block. 4810 4811Given 4812 class X { void f(int x) {} }; 4813cxxMethodDecl(hasParameter(0, hasType(varDecl()))) 4814 matches f(int x) {} 4815with hasParameter(...) 4816 matching int x 4817 4818For ObjectiveC, given 4819 @interface I - (void) f:(int) y; @end 4820 4821the matcher objcMethodDecl(hasParameter(0, hasName("y"))) 4822matches the declaration of method f with hasParameter 4823matching y. 4824</pre></td></tr> 4825 4826 4827<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> 4828<tr><td colspan="4" class="doc" id="pointee0"><pre>Narrows PointerType (and similar) matchers to those where the 4829pointee matches a given matcher. 4830 4831Given 4832 int *a; 4833 int const *b; 4834 float const *f; 4835pointerType(pointee(isConstQualified(), isInteger())) 4836 matches "int const *b" 4837 4838Usable 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>>, 4839 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>> 4840</pre></td></tr> 4841 4842 4843<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> 4844<tr><td colspan="4" class="doc" id="forEachArgumentWithParam1"><pre>Matches all arguments and their respective ParmVarDecl. 4845 4846Given 4847 void f(int i); 4848 int y; 4849 f(y); 4850callExpr( 4851 forEachArgumentWithParam( 4852 declRefExpr(to(varDecl(hasName("y")))), 4853 parmVarDecl(hasType(isInteger())) 4854)) 4855 matches f(y); 4856with declRefExpr(...) 4857 matching int y 4858and parmVarDecl(...) 4859 matching int i 4860</pre></td></tr> 4861 4862 4863<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> 4864<tr><td colspan="4" class="doc" id="hasAnyArgument1"><pre>Matches any argument of a call expression or a constructor call 4865expression, or an ObjC-message-send expression. 4866 4867Given 4868 void x(int, int, int) { int y; x(1, y, 42); } 4869callExpr(hasAnyArgument(declRefExpr())) 4870 matches x(1, y, 42) 4871with hasAnyArgument(...) 4872 matching y 4873 4874For ObjectiveC, given 4875 @interface I - (void) f:(int) y; @end 4876 void foo(I *i) { [i f:12]; } 4877objcMessageExpr(hasAnyArgument(integerLiteral(equals(12)))) 4878 matches [i f:12] 4879</pre></td></tr> 4880 4881 4882<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> 4883<tr><td colspan="4" class="doc" id="hasArgument1"><pre>Matches the n'th argument of a call expression or a constructor 4884call expression. 4885 4886Example matches y in x(y) 4887 (matcher = callExpr(hasArgument(0, declRefExpr()))) 4888 void x(int) { int y; x(y); } 4889</pre></td></tr> 4890 4891 4892<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> 4893<tr><td colspan="4" class="doc" id="hasDeclaration13"><pre>Matches a node if the declaration associated with that node 4894matches the given matcher. 4895 4896The associated declaration is: 4897- for type nodes, the declaration of the underlying type 4898- for CallExpr, the declaration of the callee 4899- for MemberExpr, the declaration of the referenced member 4900- for CXXConstructExpr, the declaration of the constructor 4901- for CXXNewExpr, the declaration of the operator new 4902- for ObjCIvarExpr, the declaration of the ivar 4903 4904For type nodes, hasDeclaration will generally match the declaration of the 4905sugared type. Given 4906 class X {}; 4907 typedef X Y; 4908 Y y; 4909in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 4910typedefDecl. A common use case is to match the underlying, desugared type. 4911This can be achieved by using the hasUnqualifiedDesugaredType matcher: 4912 varDecl(hasType(hasUnqualifiedDesugaredType( 4913 recordType(hasDeclaration(decl()))))) 4914In this matcher, the decl will match the CXXRecordDecl of class X. 4915 4916Usable 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>>, 4917 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>>, 4918 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>>, 4919 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>>, 4920 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>>, 4921 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>>, 4922 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 4923</pre></td></tr> 4924 4925 4926<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> 4927<tr><td colspan="4" class="doc" id="forEachConstructorInitializer0"><pre>Matches each constructor initializer in a constructor definition. 4928 4929Given 4930 class A { A() : i(42), j(42) {} int i; int j; }; 4931cxxConstructorDecl(forEachConstructorInitializer( 4932 forField(decl().bind("x")) 4933)) 4934 will trigger two matches, binding for 'i' and 'j' respectively. 4935</pre></td></tr> 4936 4937 4938<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> 4939<tr><td colspan="4" class="doc" id="hasAnyConstructorInitializer0"><pre>Matches a constructor initializer. 4940 4941Given 4942 struct Foo { 4943 Foo() : foo_(1) { } 4944 int foo_; 4945 }; 4946cxxRecordDecl(has(cxxConstructorDecl( 4947 hasAnyConstructorInitializer(anything()) 4948))) 4949 record matches Foo, hasAnyConstructorInitializer matches foo_(1) 4950</pre></td></tr> 4951 4952 4953<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> 4954<tr><td colspan="4" class="doc" id="forField0"><pre>Matches the field declaration of a constructor initializer. 4955 4956Given 4957 struct Foo { 4958 Foo() : foo_(1) { } 4959 int foo_; 4960 }; 4961cxxRecordDecl(has(cxxConstructorDecl(hasAnyConstructorInitializer( 4962 forField(hasName("foo_")))))) 4963 matches Foo 4964with forField matching foo_ 4965</pre></td></tr> 4966 4967 4968<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> 4969<tr><td colspan="4" class="doc" id="withInitializer0"><pre>Matches the initializer expression of a constructor initializer. 4970 4971Given 4972 struct Foo { 4973 Foo() : foo_(1) { } 4974 int foo_; 4975 }; 4976cxxRecordDecl(has(cxxConstructorDecl(hasAnyConstructorInitializer( 4977 withInitializer(integerLiteral(equals(1))))))) 4978 matches Foo 4979with withInitializer matching (1) 4980</pre></td></tr> 4981 4982 4983<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> 4984<tr><td colspan="4" class="doc" id="hasObjectExpression2"><pre>Matches a member expression where the object expression is matched by a 4985given matcher. Implicit object expressions are included; that is, it matches 4986use of implicit `this`. 4987 4988Given 4989 struct X { 4990 int m; 4991 int f(X x) { x.m; return m; } 4992 }; 4993memberExpr(hasObjectExpression(hasType(cxxRecordDecl(hasName("X"))))) 4994 matches `x.m`, but not `m`; however, 4995memberExpr(hasObjectExpression(hasType(pointsTo( 4996 cxxRecordDecl(hasName("X")))))) 4997 matches `m` (aka. `this->m`), but not `x.m`. 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('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> 5002<tr><td colspan="4" class="doc" id="hasBody3"><pre>Matches a 'for', 'while', 'do while' statement or a function 5003definition that has a given body. 5004 5005Given 5006 for (;;) {} 5007hasBody(compoundStmt()) 5008 matches 'for (;;) {}' 5009with compoundStmt() 5010 matching '{}' 5011</pre></td></tr> 5012 5013 5014<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> 5015<tr><td colspan="4" class="doc" id="hasLoopVariable0"><pre>Matches the initialization statement of a for loop. 5016 5017Example: 5018 forStmt(hasLoopVariable(anything())) 5019matches 'int x' in 5020 for (int x : a) { } 5021</pre></td></tr> 5022 5023 5024<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> 5025<tr><td colspan="4" class="doc" id="hasRangeInit0"><pre>Matches the range initialization statement of a for loop. 5026 5027Example: 5028 forStmt(hasRangeInit(anything())) 5029matches 'a' in 5030 for (int x : a) { } 5031</pre></td></tr> 5032 5033 5034<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> 5035<tr><td colspan="4" class="doc" id="onImplicitObjectArgument0"><pre>Matches on the implicit object argument of a member call expression. Unlike 5036`on`, matches the argument directly without stripping away anything. 5037 5038Given 5039 class Y { public: void m(); }; 5040 Y g(); 5041 class X : public Y { void g(); }; 5042 void z(Y y, X x) { y.m(); x.m(); x.g(); (g()).m(); } 5043cxxMemberCallExpr(onImplicitObjectArgument(hasType( 5044 cxxRecordDecl(hasName("Y"))))) 5045 matches `y.m()`, `x.m()` and (g()).m(), but not `x.g()`. 5046cxxMemberCallExpr(on(callExpr())) 5047 does not match `(g()).m()`, because the parens are not ignored. 5048 5049FIXME: Overload to allow directly matching types? 5050</pre></td></tr> 5051 5052 5053<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> 5054<tr><td colspan="4" class="doc" id="on0"><pre>Matches on the implicit object argument of a member call expression, after 5055stripping off any parentheses or implicit casts. 5056 5057Given 5058 class Y { public: void m(); }; 5059 Y g(); 5060 class X : public Y {}; 5061 void z(Y y, X x) { y.m(); (g()).m(); x.m(); } 5062cxxMemberCallExpr(on(hasType(cxxRecordDecl(hasName("Y"))))) 5063 matches `y.m()` and `(g()).m()`. 5064cxxMemberCallExpr(on(hasType(cxxRecordDecl(hasName("X"))))) 5065 matches `x.m()`. 5066cxxMemberCallExpr(on(callExpr())) 5067 matches `(g()).m()`. 5068 5069FIXME: Overload to allow directly matching types? 5070</pre></td></tr> 5071 5072 5073<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> 5074<tr><td colspan="4" class="doc" id="thisPointerType1"><pre>Overloaded to match the type's declaration. 5075</pre></td></tr> 5076 5077 5078<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> 5079<tr><td colspan="4" class="doc" id="thisPointerType0"><pre>Matches if the type of the expression's implicit object argument either 5080matches the InnerMatcher, or is a pointer to a type that matches the 5081InnerMatcher. 5082 5083Given 5084 class Y { public: void m(); }; 5085 class X : public Y { void g(); }; 5086 void z() { Y y; y.m(); Y *p; p->m(); X x; x.m(); x.g(); } 5087cxxMemberCallExpr(thisPointerType(hasDeclaration( 5088 cxxRecordDecl(hasName("Y"))))) 5089 matches `y.m()`, `p->m()` and `x.m()`. 5090cxxMemberCallExpr(thisPointerType(hasDeclaration( 5091 cxxRecordDecl(hasName("X"))))) 5092 matches `x.g()`. 5093</pre></td></tr> 5094 5095 5096<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> 5097<tr><td colspan="4" class="doc" id="forEachOverridden0"><pre>Matches each method overridden by the given method. This matcher may 5098produce multiple matches. 5099 5100Given 5101 class A { virtual void f(); }; 5102 class B : public A { void f(); }; 5103 class C : public B { void f(); }; 5104cxxMethodDecl(ofClass(hasName("C")), 5105 forEachOverridden(cxxMethodDecl().bind("b"))).bind("d") 5106 matches once, with "b" binding "A::f" and "d" binding "C::f" (Note 5107 that B::f is not overridden by C::f). 5108 5109The check can produce multiple matches in case of multiple inheritance, e.g. 5110 class A1 { virtual void f(); }; 5111 class A2 { virtual void f(); }; 5112 class C : public A1, public A2 { void f(); }; 5113cxxMethodDecl(ofClass(hasName("C")), 5114 forEachOverridden(cxxMethodDecl().bind("b"))).bind("d") 5115 matches twice, once with "b" binding "A1::f" and "d" binding "C::f", and 5116 once with "b" binding "A2::f" and "d" binding "C::f". 5117</pre></td></tr> 5118 5119 5120<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> 5121<tr><td colspan="4" class="doc" id="ofClass0"><pre>Matches the class declaration that the given method declaration 5122belongs to. 5123 5124FIXME: Generalize this for other kinds of declarations. 5125FIXME: What other kind of declarations would we need to generalize 5126this to? 5127 5128Example matches A() in the last line 5129 (matcher = cxxConstructExpr(hasDeclaration(cxxMethodDecl( 5130 ofClass(hasName("A")))))) 5131 class A { 5132 public: 5133 A(); 5134 }; 5135 A a = A(); 5136</pre></td></tr> 5137 5138 5139<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> 5140<tr><td colspan="4" class="doc" id="hasArraySize0"><pre>Matches array new expressions with a given array size. 5141 5142Given: 5143 MyClass *p1 = new MyClass[10]; 5144cxxNewExpr(hasArraySize(intgerLiteral(equals(10)))) 5145 matches the expression 'new MyClass[10]'. 5146</pre></td></tr> 5147 5148 5149<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> 5150<tr><td colspan="4" class="doc" id="hasDeclaration12"><pre>Matches a node if the declaration associated with that node 5151matches the given matcher. 5152 5153The associated declaration is: 5154- for type nodes, the declaration of the underlying type 5155- for CallExpr, the declaration of the callee 5156- for MemberExpr, the declaration of the referenced member 5157- for CXXConstructExpr, the declaration of the constructor 5158- for CXXNewExpr, the declaration of the operator new 5159- for ObjCIvarExpr, the declaration of the ivar 5160 5161For type nodes, hasDeclaration will generally match the declaration of the 5162sugared type. Given 5163 class X {}; 5164 typedef X Y; 5165 Y y; 5166in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 5167typedefDecl. A common use case is to match the underlying, desugared type. 5168This can be achieved by using the hasUnqualifiedDesugaredType matcher: 5169 varDecl(hasType(hasUnqualifiedDesugaredType( 5170 recordType(hasDeclaration(decl()))))) 5171In this matcher, the decl will match the CXXRecordDecl of class X. 5172 5173Usable 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>>, 5174 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>>, 5175 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>>, 5176 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>>, 5177 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>>, 5178 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>>, 5179 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 5180</pre></td></tr> 5181 5182 5183<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> 5184<tr><td colspan="4" class="doc" id="hasMethod0"><pre>Matches the first method of a class or struct that satisfies InnerMatcher. 5185 5186Given: 5187 class A { void func(); }; 5188 class B { void member(); }; 5189 5190cxxRecordDecl(hasMethod(hasName("func"))) matches the declaration of 5191A but not B. 5192</pre></td></tr> 5193 5194 5195<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> 5196<tr><td colspan="4" class="doc" id="isDerivedFrom0"><pre>Matches C++ classes that are directly or indirectly derived from 5197a class matching Base. 5198 5199Note that a class is not considered to be derived from itself. 5200 5201Example matches Y, Z, C (Base == hasName("X")) 5202 class X; 5203 class Y : public X {}; // directly derived 5204 class Z : public Y {}; // indirectly derived 5205 typedef X A; 5206 typedef A B; 5207 class C : public B {}; // derived from a typedef of X 5208 5209In the following example, Bar matches isDerivedFrom(hasName("X")): 5210 class Foo; 5211 typedef Foo X; 5212 class Bar : public Foo {}; // derived from a type that X is a typedef of 5213</pre></td></tr> 5214 5215 5216<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> 5217<tr><td colspan="4" class="doc" id="isSameOrDerivedFrom0"><pre>Similar to isDerivedFrom(), but also matches classes that directly 5218match Base. 5219</pre></td></tr> 5220 5221 5222<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> 5223<tr><td colspan="4" class="doc" id="hasAnyArgument2"><pre>Matches any argument of a call expression or a constructor call 5224expression, or an ObjC-message-send expression. 5225 5226Given 5227 void x(int, int, int) { int y; x(1, y, 42); } 5228callExpr(hasAnyArgument(declRefExpr())) 5229 matches x(1, y, 42) 5230with hasAnyArgument(...) 5231 matching y 5232 5233For ObjectiveC, given 5234 @interface I - (void) f:(int) y; @end 5235 void foo(I *i) { [i f:12]; } 5236objcMessageExpr(hasAnyArgument(integerLiteral(equals(12)))) 5237 matches [i f:12] 5238</pre></td></tr> 5239 5240 5241<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> 5242<tr><td colspan="4" class="doc" id="callee1"><pre>Matches if the call expression's callee's declaration matches the 5243given matcher. 5244 5245Example matches y.x() (matcher = callExpr(callee( 5246 cxxMethodDecl(hasName("x"))))) 5247 class Y { public: void x(); }; 5248 void z() { Y y; y.x(); } 5249</pre></td></tr> 5250 5251 5252<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> 5253<tr><td colspan="4" class="doc" id="callee0"><pre>Matches if the call expression's callee expression matches. 5254 5255Given 5256 class Y { void x() { this->x(); x(); Y y; y.x(); } }; 5257 void f() { f(); } 5258callExpr(callee(expr())) 5259 matches this->x(), x(), y.x(), f() 5260with callee(...) 5261 matching this->x, x, y.x, f respectively 5262 5263Note: Callee cannot take the more general internal::Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> 5264because this introduces ambiguous overloads with calls to Callee taking a 5265internal::Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, as the matcher hierarchy is purely 5266implemented in terms of implicit casts. 5267</pre></td></tr> 5268 5269 5270<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> 5271<tr><td colspan="4" class="doc" id="forEachArgumentWithParam0"><pre>Matches all arguments and their respective ParmVarDecl. 5272 5273Given 5274 void f(int i); 5275 int y; 5276 f(y); 5277callExpr( 5278 forEachArgumentWithParam( 5279 declRefExpr(to(varDecl(hasName("y")))), 5280 parmVarDecl(hasType(isInteger())) 5281)) 5282 matches f(y); 5283with declRefExpr(...) 5284 matching int y 5285and parmVarDecl(...) 5286 matching int i 5287</pre></td></tr> 5288 5289 5290<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> 5291<tr><td colspan="4" class="doc" id="hasAnyArgument0"><pre>Matches any argument of a call expression or a constructor call 5292expression, or an ObjC-message-send expression. 5293 5294Given 5295 void x(int, int, int) { int y; x(1, y, 42); } 5296callExpr(hasAnyArgument(declRefExpr())) 5297 matches x(1, y, 42) 5298with hasAnyArgument(...) 5299 matching y 5300 5301For ObjectiveC, given 5302 @interface I - (void) f:(int) y; @end 5303 void foo(I *i) { [i f:12]; } 5304objcMessageExpr(hasAnyArgument(integerLiteral(equals(12)))) 5305 matches [i f:12] 5306</pre></td></tr> 5307 5308 5309<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> 5310<tr><td colspan="4" class="doc" id="hasArgument0"><pre>Matches the n'th argument of a call expression or a constructor 5311call expression. 5312 5313Example matches y in x(y) 5314 (matcher = callExpr(hasArgument(0, declRefExpr()))) 5315 void x(int) { int y; x(y); } 5316</pre></td></tr> 5317 5318 5319<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> 5320<tr><td colspan="4" class="doc" id="hasDeclaration14"><pre>Matches a node if the declaration associated with that node 5321matches the given matcher. 5322 5323The associated declaration is: 5324- for type nodes, the declaration of the underlying type 5325- for CallExpr, the declaration of the callee 5326- for MemberExpr, the declaration of the referenced member 5327- for CXXConstructExpr, the declaration of the constructor 5328- for CXXNewExpr, the declaration of the operator new 5329- for ObjCIvarExpr, the declaration of the ivar 5330 5331For type nodes, hasDeclaration will generally match the declaration of the 5332sugared type. Given 5333 class X {}; 5334 typedef X Y; 5335 Y y; 5336in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 5337typedefDecl. A common use case is to match the underlying, desugared type. 5338This can be achieved by using the hasUnqualifiedDesugaredType matcher: 5339 varDecl(hasType(hasUnqualifiedDesugaredType( 5340 recordType(hasDeclaration(decl()))))) 5341In this matcher, the decl will match the CXXRecordDecl of class X. 5342 5343Usable 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>>, 5344 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>>, 5345 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>>, 5346 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>>, 5347 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>>, 5348 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>>, 5349 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 5350</pre></td></tr> 5351 5352 5353<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> 5354<tr><td colspan="4" class="doc" id="hasCaseConstant0"><pre>If the given case statement does not use the GNU case range 5355extension, matches the constant given in the statement. 5356 5357Given 5358 switch (1) { case 1: case 1+1: case 3 ... 4: ; } 5359caseStmt(hasCaseConstant(integerLiteral())) 5360 matches "case 1:" 5361</pre></td></tr> 5362 5363 5364<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> 5365<tr><td colspan="4" class="doc" id="hasSourceExpression0"><pre>Matches if the cast's source expression 5366or opaque value's source expression matches the given matcher. 5367 5368Example 1: matches "a string" 5369(matcher = castExpr(hasSourceExpression(cxxConstructExpr()))) 5370class URL { URL(string); }; 5371URL url = "a string"; 5372 5373Example 2: matches 'b' (matcher = 5374opaqueValueExpr(hasSourceExpression(implicitCastExpr(declRefExpr()))) 5375int a = b ?: 1; 5376</pre></td></tr> 5377 5378 5379<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> 5380<tr><td colspan="4" class="doc" id="hasAnyTemplateArgument0"><pre>Matches classTemplateSpecializations, templateSpecializationType and 5381functionDecl that have at least one TemplateArgument matching the given 5382InnerMatcher. 5383 5384Given 5385 template<typename T> class A {}; 5386 template<> class A<double> {}; 5387 A<int> a; 5388 5389 template<typename T> f() {}; 5390 void func() { f<int>(); }; 5391 5392classTemplateSpecializationDecl(hasAnyTemplateArgument( 5393 refersToType(asString("int")))) 5394 matches the specialization A<int> 5395 5396functionDecl(hasAnyTemplateArgument(refersToType(asString("int")))) 5397 matches the specialization f<int> 5398</pre></td></tr> 5399 5400 5401<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> 5402<tr><td colspan="4" class="doc" id="hasSpecializedTemplate0"><pre>Matches the specialized template of a specialization declaration. 5403 5404Given 5405 template<typename T> class A {}; #1 5406 template<> class A<int> {}; #2 5407classTemplateSpecializationDecl(hasSpecializedTemplate(classTemplateDecl())) 5408 matches '#2' with classTemplateDecl() matching the class template 5409 declaration of 'A' at #1. 5410</pre></td></tr> 5411 5412 5413<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> 5414<tr><td colspan="4" class="doc" id="hasTemplateArgument0"><pre>Matches classTemplateSpecializations, templateSpecializationType and 5415functionDecl where the n'th TemplateArgument matches the given InnerMatcher. 5416 5417Given 5418 template<typename T, typename U> class A {}; 5419 A<bool, int> b; 5420 A<int, bool> c; 5421 5422 template<typename T> void f() {} 5423 void func() { f<int>(); }; 5424classTemplateSpecializationDecl(hasTemplateArgument( 5425 1, refersToType(asString("int")))) 5426 matches the specialization A<bool, int> 5427 5428functionDecl(hasTemplateArgument(0, refersToType(asString("int")))) 5429 matches the specialization f<int> 5430</pre></td></tr> 5431 5432 5433<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> 5434<tr><td colspan="4" class="doc" id="hasElementType1"><pre>Matches arrays and C99 complex types that have a specific element 5435type. 5436 5437Given 5438 struct A {}; 5439 A a[7]; 5440 int b[7]; 5441arrayType(hasElementType(builtinType())) 5442 matches "int b[7]" 5443 5444Usable 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>> 5445</pre></td></tr> 5446 5447 5448<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> 5449<tr><td colspan="4" class="doc" id="hasAnySubstatement0"><pre>Matches compound statements where at least one substatement matches 5450a given matcher. Also matches StmtExprs that have CompoundStmt as children. 5451 5452Given 5453 { {}; 1+2; } 5454hasAnySubstatement(compoundStmt()) 5455 matches '{ {}; 1+2; }' 5456with compoundStmt() 5457 matching '{}' 5458</pre></td></tr> 5459 5460 5461<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> 5462<tr><td colspan="4" class="doc" id="hasDecayedType0"><pre>Matches the decayed type, whos decayed type matches InnerMatcher 5463</pre></td></tr> 5464 5465 5466<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> 5467<tr><td colspan="4" class="doc" id="hasDeclaration11"><pre>Matches a node if the declaration associated with that node 5468matches the given matcher. 5469 5470The associated declaration is: 5471- for type nodes, the declaration of the underlying type 5472- for CallExpr, the declaration of the callee 5473- for MemberExpr, the declaration of the referenced member 5474- for CXXConstructExpr, the declaration of the constructor 5475- for CXXNewExpr, the declaration of the operator new 5476- for ObjCIvarExpr, the declaration of the ivar 5477 5478For type nodes, hasDeclaration will generally match the declaration of the 5479sugared type. Given 5480 class X {}; 5481 typedef X Y; 5482 Y y; 5483in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 5484typedefDecl. A common use case is to match the underlying, desugared type. 5485This can be achieved by using the hasUnqualifiedDesugaredType matcher: 5486 varDecl(hasType(hasUnqualifiedDesugaredType( 5487 recordType(hasDeclaration(decl()))))) 5488In this matcher, the decl will match the CXXRecordDecl of class X. 5489 5490Usable 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>>, 5491 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>>, 5492 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>>, 5493 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>>, 5494 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>>, 5495 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>>, 5496 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 5497</pre></td></tr> 5498 5499 5500<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> 5501<tr><td colspan="4" class="doc" id="throughUsingDecl0"><pre>Matches a DeclRefExpr that refers to a declaration through a 5502specific using shadow declaration. 5503 5504Given 5505 namespace a { void f() {} } 5506 using a::f; 5507 void g() { 5508 f(); // Matches this .. 5509 a::f(); // .. but not this. 5510 } 5511declRefExpr(throughUsingDecl(anything())) 5512 matches f() 5513</pre></td></tr> 5514 5515 5516<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> 5517<tr><td colspan="4" class="doc" id="to0"><pre>Matches a DeclRefExpr that refers to a declaration that matches the 5518specified matcher. 5519 5520Example matches x in if(x) 5521 (matcher = declRefExpr(to(varDecl(hasName("x"))))) 5522 bool x; 5523 if (x) {} 5524</pre></td></tr> 5525 5526 5527<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> 5528<tr><td colspan="4" class="doc" id="containsDeclaration0"><pre>Matches the n'th declaration of a declaration statement. 5529 5530Note that this does not work for global declarations because the AST 5531breaks up multiple-declaration DeclStmt's into multiple single-declaration 5532DeclStmt's. 5533Example: Given non-global declarations 5534 int a, b = 0; 5535 int c; 5536 int d = 2, e; 5537declStmt(containsDeclaration( 5538 0, varDecl(hasInitializer(anything())))) 5539 matches only 'int d = 2, e;', and 5540declStmt(containsDeclaration(1, varDecl())) 5541 matches 'int a, b = 0' as well as 'int d = 2, e;' 5542 but 'int c;' is not matched. 5543</pre></td></tr> 5544 5545 5546<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> 5547<tr><td colspan="4" class="doc" id="hasSingleDecl0"><pre>Matches the Decl of a DeclStmt which has a single declaration. 5548 5549Given 5550 int a, b; 5551 int c; 5552declStmt(hasSingleDecl(anything())) 5553 matches 'int c;' but not 'int a, b;'. 5554</pre></td></tr> 5555 5556 5557<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> 5558<tr><td colspan="4" class="doc" id="hasTypeLoc0"><pre>Matches if the type location of the declarator decl's type matches 5559the inner matcher. 5560 5561Given 5562 int x; 5563declaratorDecl(hasTypeLoc(loc(asString("int")))) 5564 matches int x 5565</pre></td></tr> 5566 5567 5568<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> 5569<tr><td colspan="4" class="doc" id="hasDeclContext0"><pre>Matches declarations whose declaration context, interpreted as a 5570Decl, matches InnerMatcher. 5571 5572Given 5573 namespace N { 5574 namespace M { 5575 class D {}; 5576 } 5577 } 5578 5579cxxRcordDecl(hasDeclContext(namedDecl(hasName("M")))) matches the 5580declaration of class D. 5581</pre></td></tr> 5582 5583 5584<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> 5585<tr><td colspan="4" class="doc" id="hasUnderlyingType0"><pre>Matches DecltypeType nodes to find out the underlying type. 5586 5587Given 5588 decltype(1) a = 1; 5589 decltype(2.0) b = 2.0; 5590decltypeType(hasUnderlyingType(isInteger())) 5591 matches the type of "a" 5592 5593Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1DecltypeType.html">DecltypeType</a>> 5594</pre></td></tr> 5595 5596 5597<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> 5598<tr><td colspan="4" class="doc" id="hasBody0"><pre>Matches a 'for', 'while', 'do while' statement or a function 5599definition that has a given body. 5600 5601Given 5602 for (;;) {} 5603hasBody(compoundStmt()) 5604 matches 'for (;;) {}' 5605with compoundStmt() 5606 matching '{}' 5607</pre></td></tr> 5608 5609 5610<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> 5611<tr><td colspan="4" class="doc" id="hasCondition3"><pre>Matches the condition expression of an if statement, for loop, 5612switch statement or conditional operator. 5613 5614Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true)))) 5615 if (true) {} 5616</pre></td></tr> 5617 5618 5619<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> 5620<tr><td colspan="4" class="doc" id="hasQualifier0"><pre>Matches ElaboratedTypes whose qualifier, a NestedNameSpecifier, 5621matches InnerMatcher if the qualifier exists. 5622 5623Given 5624 namespace N { 5625 namespace M { 5626 class D {}; 5627 } 5628 } 5629 N::M::D d; 5630 5631elaboratedType(hasQualifier(hasPrefix(specifiesNamespace(hasName("N")))) 5632matches the type of the variable declaration of d. 5633</pre></td></tr> 5634 5635 5636<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> 5637<tr><td colspan="4" class="doc" id="namesType0"><pre>Matches ElaboratedTypes whose named type matches InnerMatcher. 5638 5639Given 5640 namespace N { 5641 namespace M { 5642 class D {}; 5643 } 5644 } 5645 N::M::D d; 5646 5647elaboratedType(namesType(recordType( 5648hasDeclaration(namedDecl(hasName("D")))))) matches the type of the variable 5649declaration of d. 5650</pre></td></tr> 5651 5652 5653<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> 5654<tr><td colspan="4" class="doc" id="hasDeclaration10"><pre>Matches a node if the declaration associated with that node 5655matches the given matcher. 5656 5657The associated declaration is: 5658- for type nodes, the declaration of the underlying type 5659- for CallExpr, the declaration of the callee 5660- for MemberExpr, the declaration of the referenced member 5661- for CXXConstructExpr, the declaration of the constructor 5662- for CXXNewExpr, the declaration of the operator new 5663- for ObjCIvarExpr, the declaration of the ivar 5664 5665For type nodes, hasDeclaration will generally match the declaration of the 5666sugared type. Given 5667 class X {}; 5668 typedef X Y; 5669 Y y; 5670in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 5671typedefDecl. A common use case is to match the underlying, desugared type. 5672This can be achieved by using the hasUnqualifiedDesugaredType matcher: 5673 varDecl(hasType(hasUnqualifiedDesugaredType( 5674 recordType(hasDeclaration(decl()))))) 5675In this matcher, the decl will match the CXXRecordDecl of class X. 5676 5677Usable 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>>, 5678 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>>, 5679 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>>, 5680 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>>, 5681 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>>, 5682 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>>, 5683 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 5684</pre></td></tr> 5685 5686 5687<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> 5688<tr><td colspan="4" class="doc" id="hasDestinationType0"><pre>Matches casts whose destination type matches a given matcher. 5689 5690(Note: Clang's AST refers to other conversions as "casts" too, and calls 5691actual casts "explicit" casts.) 5692</pre></td></tr> 5693 5694 5695<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> 5696<tr><td colspan="4" class="doc" id="hasType4"><pre>Overloaded to match the declaration of the expression's or value 5697declaration's type. 5698 5699In case of a value declaration (for example a variable declaration), 5700this resolves one layer of indirection. For example, in the value 5701declaration "X x;", cxxRecordDecl(hasName("X")) matches the declaration of 5702X, while varDecl(hasType(cxxRecordDecl(hasName("X")))) matches the 5703declaration of x. 5704 5705Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) 5706 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) 5707 and friend class X (matcher = friendDecl(hasType("X")) 5708 class X {}; 5709 void y(X &x) { x; X z; } 5710 class Y { friend class X; }; 5711 5712Usable 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>> 5713</pre></td></tr> 5714 5715 5716<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> 5717<tr><td colspan="4" class="doc" id="hasType0"><pre>Matches if the expression's or declaration's type matches a type 5718matcher. 5719 5720Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) 5721 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) 5722 and U (matcher = typedefDecl(hasType(asString("int"))) 5723 and friend class X (matcher = friendDecl(hasType("X")) 5724 class X {}; 5725 void y(X &x) { x; X z; } 5726 typedef int U; 5727 class Y { friend class X; }; 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('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> 5732<tr><td colspan="4" class="doc" id="ignoringImpCasts0"><pre>Matches expressions that match InnerMatcher after any implicit casts 5733are stripped off. 5734 5735Parentheses and explicit casts are not discarded. 5736Given 5737 int arr[5]; 5738 int a = 0; 5739 char b = 0; 5740 const int c = a; 5741 int *d = arr; 5742 long e = (long) 0l; 5743The matchers 5744 varDecl(hasInitializer(ignoringImpCasts(integerLiteral()))) 5745 varDecl(hasInitializer(ignoringImpCasts(declRefExpr()))) 5746would match the declarations for a, b, c, and d, but not e. 5747While 5748 varDecl(hasInitializer(integerLiteral())) 5749 varDecl(hasInitializer(declRefExpr())) 5750only match the declarations for b, c, and d. 5751</pre></td></tr> 5752 5753 5754<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> 5755<tr><td colspan="4" class="doc" id="ignoringImplicit0"><pre>Matches expressions that match InnerMatcher after any implicit AST 5756nodes are stripped off. 5757 5758Parentheses and explicit casts are not discarded. 5759Given 5760 class C {}; 5761 C a = C(); 5762 C b; 5763 C c = b; 5764The matchers 5765 varDecl(hasInitializer(ignoringImplicit(cxxConstructExpr()))) 5766would match the declarations for a, b, and c. 5767While 5768 varDecl(hasInitializer(cxxConstructExpr())) 5769only match the declarations for b and c. 5770</pre></td></tr> 5771 5772 5773<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> 5774<tr><td colspan="4" class="doc" id="ignoringParenCasts0"><pre>Matches expressions that match InnerMatcher after parentheses and 5775casts are stripped off. 5776 5777Implicit and non-C Style casts are also discarded. 5778Given 5779 int a = 0; 5780 char b = (0); 5781 void* c = reinterpret_cast<char*>(0); 5782 char d = char(0); 5783The matcher 5784 varDecl(hasInitializer(ignoringParenCasts(integerLiteral()))) 5785would match the declarations for a, b, c, and d. 5786while 5787 varDecl(hasInitializer(integerLiteral())) 5788only 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('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> 5793<tr><td colspan="4" class="doc" id="ignoringParenImpCasts0"><pre>Matches expressions that match InnerMatcher after implicit casts and 5794parentheses are stripped off. 5795 5796Explicit casts are not discarded. 5797Given 5798 int arr[5]; 5799 int a = 0; 5800 char b = (0); 5801 const int c = a; 5802 int *d = (arr); 5803 long e = ((long) 0l); 5804The matchers 5805 varDecl(hasInitializer(ignoringParenImpCasts(integerLiteral()))) 5806 varDecl(hasInitializer(ignoringParenImpCasts(declRefExpr()))) 5807would match the declarations for a, b, c, and d, but not e. 5808while 5809 varDecl(hasInitializer(integerLiteral())) 5810 varDecl(hasInitializer(declRefExpr())) 5811would only match the declaration for a. 5812</pre></td></tr> 5813 5814 5815<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> 5816<tr><td colspan="4" class="doc" id="ignoringParens1"><pre>Overload ignoringParens for Expr. 5817 5818Given 5819 const char* str = ("my-string"); 5820The matcher 5821 implicitCastExpr(hasSourceExpression(ignoringParens(stringLiteral()))) 5822would match the implicit cast resulting from the assignment. 5823</pre></td></tr> 5824 5825 5826<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> 5827<tr><td colspan="4" class="doc" id="hasInClassInitializer0"><pre>Matches non-static data members that have an in-class initializer. 5828 5829Given 5830 class C { 5831 int a = 2; 5832 int b = 3; 5833 int c; 5834 }; 5835fieldDecl(hasInClassInitializer(integerLiteral(equals(2)))) 5836 matches 'int a;' but not 'int b;'. 5837fieldDecl(hasInClassInitializer(anything())) 5838 matches 'int a;' and 'int b;' but not 'int c;'. 5839</pre></td></tr> 5840 5841 5842<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> 5843<tr><td colspan="4" class="doc" id="hasBody1"><pre>Matches a 'for', 'while', 'do while' statement or a function 5844definition that has a given body. 5845 5846Given 5847 for (;;) {} 5848hasBody(compoundStmt()) 5849 matches 'for (;;) {}' 5850with compoundStmt() 5851 matching '{}' 5852</pre></td></tr> 5853 5854 5855<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> 5856<tr><td colspan="4" class="doc" id="hasCondition1"><pre>Matches the condition expression of an if statement, for loop, 5857switch statement or conditional operator. 5858 5859Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true)))) 5860 if (true) {} 5861</pre></td></tr> 5862 5863 5864<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> 5865<tr><td colspan="4" class="doc" id="hasIncrement0"><pre>Matches the increment statement of a for loop. 5866 5867Example: 5868 forStmt(hasIncrement(unaryOperator(hasOperatorName("++")))) 5869matches '++x' in 5870 for (x; x < N; ++x) { } 5871</pre></td></tr> 5872 5873 5874<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> 5875<tr><td colspan="4" class="doc" id="hasLoopInit0"><pre>Matches the initialization statement of a for loop. 5876 5877Example: 5878 forStmt(hasLoopInit(declStmt())) 5879matches 'int x = 0' in 5880 for (int x = 0; x < N; ++x) { } 5881</pre></td></tr> 5882 5883 5884<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> 5885<tr><td colspan="4" class="doc" id="hasType5"><pre>Overloaded to match the declaration of the expression's or value 5886declaration's type. 5887 5888In case of a value declaration (for example a variable declaration), 5889this resolves one layer of indirection. For example, in the value 5890declaration "X x;", cxxRecordDecl(hasName("X")) matches the declaration of 5891X, while varDecl(hasType(cxxRecordDecl(hasName("X")))) matches the 5892declaration of x. 5893 5894Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) 5895 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) 5896 and friend class X (matcher = friendDecl(hasType("X")) 5897 class X {}; 5898 void y(X &x) { x; X z; } 5899 class Y { friend class X; }; 5900 5901Usable 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>> 5902</pre></td></tr> 5903 5904 5905<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> 5906<tr><td colspan="4" class="doc" id="hasType1"><pre>Matches if the expression's or declaration's type matches a type 5907matcher. 5908 5909Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) 5910 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) 5911 and U (matcher = typedefDecl(hasType(asString("int"))) 5912 and friend class X (matcher = friendDecl(hasType("X")) 5913 class X {}; 5914 void y(X &x) { x; X z; } 5915 typedef int U; 5916 class Y { friend class X; }; 5917</pre></td></tr> 5918 5919 5920<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> 5921<tr><td colspan="4" class="doc" id="hasAnyParameter0"><pre>Matches any parameter of a function or an ObjC method declaration or a 5922block. 5923 5924Does not match the 'this' parameter of a method. 5925 5926Given 5927 class X { void f(int x, int y, int z) {} }; 5928cxxMethodDecl(hasAnyParameter(hasName("y"))) 5929 matches f(int x, int y, int z) {} 5930with hasAnyParameter(...) 5931 matching int y 5932 5933For ObjectiveC, given 5934 @interface I - (void) f:(int) y; @end 5935 5936the matcher objcMethodDecl(hasAnyParameter(hasName("y"))) 5937matches the declaration of method f with hasParameter 5938matching y. 5939 5940For blocks, given 5941 b = ^(int y) { printf("%d", y) }; 5942 5943the matcher blockDecl(hasAnyParameter(hasName("y"))) 5944matches the declaration of the block b with hasParameter 5945matching y. 5946</pre></td></tr> 5947 5948 5949<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> 5950<tr><td colspan="4" class="doc" id="hasAnyTemplateArgument2"><pre>Matches classTemplateSpecializations, templateSpecializationType and 5951functionDecl that have at least one TemplateArgument matching the given 5952InnerMatcher. 5953 5954Given 5955 template<typename T> class A {}; 5956 template<> class A<double> {}; 5957 A<int> a; 5958 5959 template<typename T> f() {}; 5960 void func() { f<int>(); }; 5961 5962classTemplateSpecializationDecl(hasAnyTemplateArgument( 5963 refersToType(asString("int")))) 5964 matches the specialization A<int> 5965 5966functionDecl(hasAnyTemplateArgument(refersToType(asString("int")))) 5967 matches the specialization f<int> 5968</pre></td></tr> 5969 5970 5971<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> 5972<tr><td colspan="4" class="doc" id="hasBody4"><pre>Matches a 'for', 'while', 'do while' statement or a function 5973definition that has a given body. 5974 5975Given 5976 for (;;) {} 5977hasBody(compoundStmt()) 5978 matches 'for (;;) {}' 5979with compoundStmt() 5980 matching '{}' 5981</pre></td></tr> 5982 5983 5984<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> 5985<tr><td colspan="4" class="doc" id="hasParameter0"><pre>Matches the n'th parameter of a function or an ObjC method 5986declaration or a block. 5987 5988Given 5989 class X { void f(int x) {} }; 5990cxxMethodDecl(hasParameter(0, hasType(varDecl()))) 5991 matches f(int x) {} 5992with hasParameter(...) 5993 matching int x 5994 5995For ObjectiveC, given 5996 @interface I - (void) f:(int) y; @end 5997 5998the matcher objcMethodDecl(hasParameter(0, hasName("y"))) 5999matches the declaration of method f with hasParameter 6000matching y. 6001</pre></td></tr> 6002 6003 6004<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> 6005<tr><td colspan="4" class="doc" id="hasTemplateArgument2"><pre>Matches classTemplateSpecializations, templateSpecializationType and 6006functionDecl where the n'th TemplateArgument matches the given InnerMatcher. 6007 6008Given 6009 template<typename T, typename U> class A {}; 6010 A<bool, int> b; 6011 A<int, bool> c; 6012 6013 template<typename T> void f() {} 6014 void func() { f<int>(); }; 6015classTemplateSpecializationDecl(hasTemplateArgument( 6016 1, refersToType(asString("int")))) 6017 matches the specialization A<bool, int> 6018 6019functionDecl(hasTemplateArgument(0, refersToType(asString("int")))) 6020 matches the specialization f<int> 6021</pre></td></tr> 6022 6023 6024<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> 6025<tr><td colspan="4" class="doc" id="returns0"><pre>Matches the return type of a function declaration. 6026 6027Given: 6028 class X { int f() { return 1; } }; 6029cxxMethodDecl(returns(asString("int"))) 6030 matches int f() { return 1; } 6031</pre></td></tr> 6032 6033 6034<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> 6035<tr><td colspan="4" class="doc" id="hasCondition0"><pre>Matches the condition expression of an if statement, for loop, 6036switch statement or conditional operator. 6037 6038Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true)))) 6039 if (true) {} 6040</pre></td></tr> 6041 6042 6043<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> 6044<tr><td colspan="4" class="doc" id="hasConditionVariableStatement0"><pre>Matches the condition variable statement in an if statement. 6045 6046Given 6047 if (A* a = GetAPointer()) {} 6048hasConditionVariableStatement(...) 6049 matches 'A* a = GetAPointer()'. 6050</pre></td></tr> 6051 6052 6053<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> 6054<tr><td colspan="4" class="doc" id="hasElse0"><pre>Matches the else-statement of an if statement. 6055 6056Examples matches the if statement 6057 (matcher = ifStmt(hasElse(cxxBoolLiteral(equals(true))))) 6058 if (false) false; else true; 6059</pre></td></tr> 6060 6061 6062<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> 6063<tr><td colspan="4" class="doc" id="hasThen0"><pre>Matches the then-statement of an if statement. 6064 6065Examples matches the if statement 6066 (matcher = ifStmt(hasThen(cxxBoolLiteral(equals(true))))) 6067 if (false) true; else false; 6068</pre></td></tr> 6069 6070 6071<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> 6072<tr><td colspan="4" class="doc" id="hasImplicitDestinationType0"><pre>Matches implicit casts whose destination type matches a given 6073matcher. 6074 6075FIXME: Unit test this matcher 6076</pre></td></tr> 6077 6078 6079<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> 6080<tr><td colspan="4" class="doc" id="hasInit0"><pre>Matches the n'th item of an initializer list expression. 6081 6082Example matches y. 6083 (matcher = initListExpr(hasInit(0, expr()))) 6084 int x{y}. 6085</pre></td></tr> 6086 6087 6088<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> 6089<tr><td colspan="4" class="doc" id="hasSyntacticForm0"><pre>Matches the syntactic form of init list expressions 6090(if expression have it). 6091</pre></td></tr> 6092 6093 6094<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> 6095<tr><td colspan="4" class="doc" id="hasDeclaration9"><pre>Matches a node if the declaration associated with that node 6096matches the given matcher. 6097 6098The associated declaration is: 6099- for type nodes, the declaration of the underlying type 6100- for CallExpr, the declaration of the callee 6101- for MemberExpr, the declaration of the referenced member 6102- for CXXConstructExpr, the declaration of the constructor 6103- for CXXNewExpr, the declaration of the operator new 6104- for ObjCIvarExpr, the declaration of the ivar 6105 6106For type nodes, hasDeclaration will generally match the declaration of the 6107sugared type. Given 6108 class X {}; 6109 typedef X Y; 6110 Y y; 6111in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 6112typedefDecl. A common use case is to match the underlying, desugared type. 6113This can be achieved by using the hasUnqualifiedDesugaredType matcher: 6114 varDecl(hasType(hasUnqualifiedDesugaredType( 6115 recordType(hasDeclaration(decl()))))) 6116In this matcher, the decl will match the CXXRecordDecl of class X. 6117 6118Usable 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>>, 6119 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>>, 6120 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>>, 6121 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>>, 6122 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>>, 6123 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>>, 6124 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 6125</pre></td></tr> 6126 6127 6128<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> 6129<tr><td colspan="4" class="doc" id="hasDeclaration8"><pre>Matches a node if the declaration associated with that node 6130matches the given matcher. 6131 6132The associated declaration is: 6133- for type nodes, the declaration of the underlying type 6134- for CallExpr, the declaration of the callee 6135- for MemberExpr, the declaration of the referenced member 6136- for CXXConstructExpr, the declaration of the constructor 6137- for CXXNewExpr, the declaration of the operator new 6138- for ObjCIvarExpr, the declaration of the ivar 6139 6140For type nodes, hasDeclaration will generally match the declaration of the 6141sugared type. Given 6142 class X {}; 6143 typedef X Y; 6144 Y y; 6145in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 6146typedefDecl. A common use case is to match the underlying, desugared type. 6147This can be achieved by using the hasUnqualifiedDesugaredType matcher: 6148 varDecl(hasType(hasUnqualifiedDesugaredType( 6149 recordType(hasDeclaration(decl()))))) 6150In this matcher, the decl will match the CXXRecordDecl of class X. 6151 6152Usable 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>>, 6153 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>>, 6154 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>>, 6155 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>>, 6156 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>>, 6157 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>>, 6158 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 6159</pre></td></tr> 6160 6161 6162<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> 6163<tr><td colspan="4" class="doc" id="hasDeclaration7"><pre>Matches a node if the declaration associated with that node 6164matches the given matcher. 6165 6166The associated declaration is: 6167- for type nodes, the declaration of the underlying type 6168- for CallExpr, the declaration of the callee 6169- for MemberExpr, the declaration of the referenced member 6170- for CXXConstructExpr, the declaration of the constructor 6171- for CXXNewExpr, the declaration of the operator new 6172- for ObjCIvarExpr, the declaration of the ivar 6173 6174For type nodes, hasDeclaration will generally match the declaration of the 6175sugared type. Given 6176 class X {}; 6177 typedef X Y; 6178 Y y; 6179in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 6180typedefDecl. A common use case is to match the underlying, desugared type. 6181This can be achieved by using the hasUnqualifiedDesugaredType matcher: 6182 varDecl(hasType(hasUnqualifiedDesugaredType( 6183 recordType(hasDeclaration(decl()))))) 6184In this matcher, the decl will match the CXXRecordDecl of class X. 6185 6186Usable 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>>, 6187 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>>, 6188 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>>, 6189 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>>, 6190 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>>, 6191 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>>, 6192 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 6193</pre></td></tr> 6194 6195 6196<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> 6197<tr><td colspan="4" class="doc" id="hasObjectExpression0"><pre>Matches a member expression where the object expression is matched by a 6198given matcher. Implicit object expressions are included; that is, it matches 6199use of implicit `this`. 6200 6201Given 6202 struct X { 6203 int m; 6204 int f(X x) { x.m; return m; } 6205 }; 6206memberExpr(hasObjectExpression(hasType(cxxRecordDecl(hasName("X"))))) 6207 matches `x.m`, but not `m`; however, 6208memberExpr(hasObjectExpression(hasType(pointsTo( 6209 cxxRecordDecl(hasName("X")))))) 6210 matches `m` (aka. `this->m`), but not `x.m`. 6211</pre></td></tr> 6212 6213 6214<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> 6215<tr><td colspan="4" class="doc" id="member0"><pre>Matches a member expression where the member is matched by a 6216given matcher. 6217 6218Given 6219 struct { int first, second; } first, second; 6220 int i(second.first); 6221 int j(first.second); 6222memberExpr(member(hasName("first"))) 6223 matches second.first 6224 but not first.second (because the member name there is "second"). 6225</pre></td></tr> 6226 6227 6228<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> 6229<tr><td colspan="4" class="doc" id="pointee1"><pre>Narrows PointerType (and similar) matchers to those where the 6230pointee matches a given matcher. 6231 6232Given 6233 int *a; 6234 int const *b; 6235 float const *f; 6236pointerType(pointee(isConstQualified(), isInteger())) 6237 matches "int const *b" 6238 6239Usable 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>>, 6240 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>> 6241</pre></td></tr> 6242 6243 6244<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> 6245<tr><td colspan="4" class="doc" id="hasUnderlyingDecl0"><pre>Matches a NamedDecl whose underlying declaration matches the given 6246matcher. 6247 6248Given 6249 namespace N { template<class T> void f(T t); } 6250 template <class T> void g() { using N::f; f(T()); } 6251unresolvedLookupExpr(hasAnyDeclaration( 6252 namedDecl(hasUnderlyingDecl(hasName("::N::f"))))) 6253 matches the use of f in g() . 6254</pre></td></tr> 6255 6256 6257<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> 6258<tr><td colspan="4" class="doc" id="hasPrefix1"><pre>Matches on the prefix of a NestedNameSpecifierLoc. 6259 6260Given 6261 struct A { struct B { struct C {}; }; }; 6262 A::B::C c; 6263nestedNameSpecifierLoc(hasPrefix(loc(specifiesType(asString("struct A"))))) 6264 matches "A::" 6265</pre></td></tr> 6266 6267 6268<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> 6269<tr><td colspan="4" class="doc" id="specifiesTypeLoc0"><pre>Matches nested name specifier locs that specify a type matching the 6270given TypeLoc. 6271 6272Given 6273 struct A { struct B { struct C {}; }; }; 6274 A::B::C c; 6275nestedNameSpecifierLoc(specifiesTypeLoc(loc(type( 6276 hasDeclaration(cxxRecordDecl(hasName("A"))))))) 6277 matches "A::" 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('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> 6282<tr><td colspan="4" class="doc" id="hasPrefix0"><pre>Matches on the prefix of a NestedNameSpecifier. 6283 6284Given 6285 struct A { struct B { struct C {}; }; }; 6286 A::B::C c; 6287nestedNameSpecifier(hasPrefix(specifiesType(asString("struct A")))) and 6288 matches "A::" 6289</pre></td></tr> 6290 6291 6292<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> 6293<tr><td colspan="4" class="doc" id="specifiesNamespace0"><pre>Matches nested name specifiers that specify a namespace matching the 6294given namespace matcher. 6295 6296Given 6297 namespace ns { struct A {}; } 6298 ns::A a; 6299nestedNameSpecifier(specifiesNamespace(hasName("ns"))) 6300 matches "ns::" 6301</pre></td></tr> 6302 6303 6304<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> 6305<tr><td colspan="4" class="doc" id="specifiesType0"><pre>Matches nested name specifiers that specify a type matching the 6306given QualType matcher without qualifiers. 6307 6308Given 6309 struct A { struct B { struct C {}; }; }; 6310 A::B::C c; 6311nestedNameSpecifier(specifiesType( 6312 hasDeclaration(cxxRecordDecl(hasName("A"))) 6313)) 6314 matches "A::" 6315</pre></td></tr> 6316 6317 6318<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> 6319<tr><td colspan="4" class="doc" id="hasAnyClause0"><pre>Matches any clause in an OpenMP directive. 6320 6321Given 6322 6323 #pragma omp parallel 6324 #pragma omp parallel default(none) 6325 6326``ompExecutableDirective(hasAnyClause(anything()))`` matches 6327``omp parallel default(none)``. 6328</pre></td></tr> 6329 6330 6331<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> 6332<tr><td colspan="4" class="doc" id="hasStructuredBlock0"><pre>Matches the structured-block of the OpenMP executable directive 6333 6334Prerequisite: the executable directive must not be standalone directive. 6335If it is, it will never match. 6336 6337Given 6338 6339 #pragma omp parallel 6340 ; 6341 #pragma omp parallel 6342 {} 6343 6344``ompExecutableDirective(hasStructuredBlock(nullStmt()))`` will match ``;`` 6345</pre></td></tr> 6346 6347 6348<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> 6349<tr><td colspan="4" class="doc" id="hasAnyArgument3"><pre>Matches any argument of a call expression or a constructor call 6350expression, or an ObjC-message-send expression. 6351 6352Given 6353 void x(int, int, int) { int y; x(1, y, 42); } 6354callExpr(hasAnyArgument(declRefExpr())) 6355 matches x(1, y, 42) 6356with hasAnyArgument(...) 6357 matching y 6358 6359For ObjectiveC, given 6360 @interface I - (void) f:(int) y; @end 6361 void foo(I *i) { [i f:12]; } 6362objcMessageExpr(hasAnyArgument(integerLiteral(equals(12)))) 6363 matches [i f:12] 6364</pre></td></tr> 6365 6366 6367<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> 6368<tr><td colspan="4" class="doc" id="hasArgument2"><pre>Matches the n'th argument of a call expression or a constructor 6369call expression. 6370 6371Example matches y in x(y) 6372 (matcher = callExpr(hasArgument(0, declRefExpr()))) 6373 void x(int) { int y; x(y); } 6374</pre></td></tr> 6375 6376 6377<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> 6378<tr><td colspan="4" class="doc" id="hasReceiver0"><pre>Matches if the Objective-C message is sent to an instance, 6379and the inner matcher matches on that instance. 6380 6381For example the method call in 6382 NSString *x = @"hello"; 6383 [x containsString:@"h"]; 6384is matched by 6385objcMessageExpr(hasReceiver(declRefExpr(to(varDecl(hasName("x")))))) 6386</pre></td></tr> 6387 6388 6389<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> 6390<tr><td colspan="4" class="doc" id="hasReceiverType0"><pre>Matches on the receiver of an ObjectiveC Message expression. 6391 6392Example 6393matcher = objCMessageExpr(hasReceiverType(asString("UIWebView *"))); 6394matches the [webView ...] message invocation. 6395 NSString *webViewJavaScript = ... 6396 UIWebView *webView = ... 6397 [webView stringByEvaluatingJavaScriptFromString:webViewJavascript]; 6398</pre></td></tr> 6399 6400 6401<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> 6402<tr><td colspan="4" class="doc" id="hasAnyParameter1"><pre>Matches any parameter of a function or an ObjC method declaration or a 6403block. 6404 6405Does not match the 'this' parameter of a method. 6406 6407Given 6408 class X { void f(int x, int y, int z) {} }; 6409cxxMethodDecl(hasAnyParameter(hasName("y"))) 6410 matches f(int x, int y, int z) {} 6411with hasAnyParameter(...) 6412 matching int y 6413 6414For ObjectiveC, given 6415 @interface I - (void) f:(int) y; @end 6416 6417the matcher objcMethodDecl(hasAnyParameter(hasName("y"))) 6418matches the declaration of method f with hasParameter 6419matching y. 6420 6421For blocks, given 6422 b = ^(int y) { printf("%d", y) }; 6423 6424the matcher blockDecl(hasAnyParameter(hasName("y"))) 6425matches the declaration of the block b with hasParameter 6426matching y. 6427</pre></td></tr> 6428 6429 6430<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> 6431<tr><td colspan="4" class="doc" id="hasParameter1"><pre>Matches the n'th parameter of a function or an ObjC method 6432declaration or a block. 6433 6434Given 6435 class X { void f(int x) {} }; 6436cxxMethodDecl(hasParameter(0, hasType(varDecl()))) 6437 matches f(int x) {} 6438with hasParameter(...) 6439 matching int x 6440 6441For ObjectiveC, given 6442 @interface I - (void) f:(int) y; @end 6443 6444the matcher objcMethodDecl(hasParameter(0, hasName("y"))) 6445matches the declaration of method f with hasParameter 6446matching y. 6447</pre></td></tr> 6448 6449 6450<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> 6451<tr><td colspan="4" class="doc" id="hasSourceExpression1"><pre>Matches if the cast's source expression 6452or opaque value's source expression matches the given matcher. 6453 6454Example 1: matches "a string" 6455(matcher = castExpr(hasSourceExpression(cxxConstructExpr()))) 6456class URL { URL(string); }; 6457URL url = "a string"; 6458 6459Example 2: matches 'b' (matcher = 6460opaqueValueExpr(hasSourceExpression(implicitCastExpr(declRefExpr()))) 6461int a = b ?: 1; 6462</pre></td></tr> 6463 6464 6465<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> 6466<tr><td colspan="4" class="doc" id="hasAnyDeclaration0"><pre>Matches an OverloadExpr if any of the declarations in the set of 6467overloads matches the given matcher. 6468 6469Given 6470 template <typename T> void foo(T); 6471 template <typename T> void bar(T); 6472 template <typename T> void baz(T t) { 6473 foo(t); 6474 bar(t); 6475 } 6476unresolvedLookupExpr(hasAnyDeclaration( 6477 functionTemplateDecl(hasName("foo")))) 6478 matches foo in foo(t); but not bar in bar(t); 6479</pre></td></tr> 6480 6481 6482<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> 6483<tr><td colspan="4" class="doc" id="innerType0"><pre>Matches ParenType nodes where the inner type is a specific type. 6484 6485Given 6486 int (*ptr_to_array)[4]; 6487 int (*ptr_to_func)(int); 6488 6489varDecl(hasType(pointsTo(parenType(innerType(functionType()))))) matches 6490ptr_to_func but not ptr_to_array. 6491 6492Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ParenType.html">ParenType</a>> 6493</pre></td></tr> 6494 6495 6496<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> 6497<tr><td colspan="4" class="doc" id="pointee2"><pre>Narrows PointerType (and similar) matchers to those where the 6498pointee matches a given matcher. 6499 6500Given 6501 int *a; 6502 int const *b; 6503 float const *f; 6504pointerType(pointee(isConstQualified(), isInteger())) 6505 matches "int const *b" 6506 6507Usable 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>>, 6508 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>> 6509</pre></td></tr> 6510 6511 6512<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> 6513<tr><td colspan="4" class="doc" id="hasCanonicalType0"><pre>Matches QualTypes whose canonical type matches InnerMatcher. 6514 6515Given: 6516 typedef int &int_ref; 6517 int a; 6518 int_ref b = a; 6519 6520varDecl(hasType(qualType(referenceType()))))) will not match the 6521declaration of b but varDecl(hasType(qualType(hasCanonicalType(referenceType())))))) does. 6522</pre></td></tr> 6523 6524 6525<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> 6526<tr><td colspan="4" class="doc" id="hasDeclaration6"><pre>Matches a node if the declaration associated with that node 6527matches the given matcher. 6528 6529The associated declaration is: 6530- for type nodes, the declaration of the underlying type 6531- for CallExpr, the declaration of the callee 6532- for MemberExpr, the declaration of the referenced member 6533- for CXXConstructExpr, the declaration of the constructor 6534- for CXXNewExpr, the declaration of the operator new 6535- for ObjCIvarExpr, the declaration of the ivar 6536 6537For type nodes, hasDeclaration will generally match the declaration of the 6538sugared type. Given 6539 class X {}; 6540 typedef X Y; 6541 Y y; 6542in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 6543typedefDecl. A common use case is to match the underlying, desugared type. 6544This can be achieved by using the hasUnqualifiedDesugaredType matcher: 6545 varDecl(hasType(hasUnqualifiedDesugaredType( 6546 recordType(hasDeclaration(decl()))))) 6547In this matcher, the decl will match the CXXRecordDecl of class X. 6548 6549Usable 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>>, 6550 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>>, 6551 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>>, 6552 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>>, 6553 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>>, 6554 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>>, 6555 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 6556</pre></td></tr> 6557 6558 6559<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> 6560<tr><td colspan="4" class="doc" id="ignoringParens0"><pre>Matches types that match InnerMatcher after any parens are stripped. 6561 6562Given 6563 void (*fp)(void); 6564The matcher 6565 varDecl(hasType(pointerType(pointee(ignoringParens(functionType()))))) 6566would match the declaration for fp. 6567</pre></td></tr> 6568 6569 6570<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> 6571<tr><td colspan="4" class="doc" id="pointsTo1"><pre>Overloaded to match the pointee type's declaration. 6572</pre></td></tr> 6573 6574 6575<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> 6576<tr><td colspan="4" class="doc" id="pointsTo0"><pre>Matches if the matched type is a pointer type and the pointee type 6577matches the specified matcher. 6578 6579Example matches y->x() 6580 (matcher = cxxMemberCallExpr(on(hasType(pointsTo 6581 cxxRecordDecl(hasName("Y"))))))) 6582 class Y { public: void x(); }; 6583 void z() { Y *y; y->x(); } 6584</pre></td></tr> 6585 6586 6587<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> 6588<tr><td colspan="4" class="doc" id="references1"><pre>Overloaded to match the referenced type's declaration. 6589</pre></td></tr> 6590 6591 6592<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> 6593<tr><td colspan="4" class="doc" id="references0"><pre>Matches if the matched type is a reference type and the referenced 6594type matches the specified matcher. 6595 6596Example matches X &x and const X &y 6597 (matcher = varDecl(hasType(references(cxxRecordDecl(hasName("X")))))) 6598 class X { 6599 void a(X b) { 6600 X &x = b; 6601 const X &y = b; 6602 } 6603 }; 6604</pre></td></tr> 6605 6606 6607<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> 6608<tr><td colspan="4" class="doc" id="hasDeclaration5"><pre>Matches a node if the declaration associated with that node 6609matches the given matcher. 6610 6611The associated declaration is: 6612- for type nodes, the declaration of the underlying type 6613- for CallExpr, the declaration of the callee 6614- for MemberExpr, the declaration of the referenced member 6615- for CXXConstructExpr, the declaration of the constructor 6616- for CXXNewExpr, the declaration of the operator new 6617- for ObjCIvarExpr, the declaration of the ivar 6618 6619For type nodes, hasDeclaration will generally match the declaration of the 6620sugared type. Given 6621 class X {}; 6622 typedef X Y; 6623 Y y; 6624in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 6625typedefDecl. A common use case is to match the underlying, desugared type. 6626This can be achieved by using the hasUnqualifiedDesugaredType matcher: 6627 varDecl(hasType(hasUnqualifiedDesugaredType( 6628 recordType(hasDeclaration(decl()))))) 6629In this matcher, the decl will match the CXXRecordDecl of class X. 6630 6631Usable 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>>, 6632 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>>, 6633 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>>, 6634 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>>, 6635 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>>, 6636 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>>, 6637 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 6638</pre></td></tr> 6639 6640 6641<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> 6642<tr><td colspan="4" class="doc" id="pointee3"><pre>Narrows PointerType (and similar) matchers to those where the 6643pointee matches a given matcher. 6644 6645Given 6646 int *a; 6647 int const *b; 6648 float const *f; 6649pointerType(pointee(isConstQualified(), isInteger())) 6650 matches "int const *b" 6651 6652Usable 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>>, 6653 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>> 6654</pre></td></tr> 6655 6656 6657<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> 6658<tr><td colspan="4" class="doc" id="hasReturnValue0"><pre>Matches the return value expression of a return statement 6659 6660Given 6661 return a + b; 6662hasReturnValue(binaryOperator()) 6663 matches 'return a + b' 6664with binaryOperator() 6665 matching 'a + b' 6666</pre></td></tr> 6667 6668 6669<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> 6670<tr><td colspan="4" class="doc" id="hasAnySubstatement1"><pre>Matches compound statements where at least one substatement matches 6671a given matcher. Also matches StmtExprs that have CompoundStmt as children. 6672 6673Given 6674 { {}; 1+2; } 6675hasAnySubstatement(compoundStmt()) 6676 matches '{ {}; 1+2; }' 6677with compoundStmt() 6678 matching '{}' 6679</pre></td></tr> 6680 6681 6682<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> 6683<tr><td colspan="4" class="doc" id="alignOfExpr0"><pre>Same as unaryExprOrTypeTraitExpr, but only matching 6684alignof. 6685</pre></td></tr> 6686 6687 6688<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> 6689<tr><td colspan="4" class="doc" id="forFunction0"><pre>Matches declaration of the function the statement belongs to 6690 6691Given: 6692F& operator=(const F& o) { 6693 std::copy_if(o.begin(), o.end(), begin(), [](V v) { return v > 0; }); 6694 return *this; 6695} 6696returnStmt(forFunction(hasName("operator="))) 6697 matches 'return *this' 6698 but does match 'return > 0' 6699</pre></td></tr> 6700 6701 6702<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> 6703<tr><td colspan="4" class="doc" id="sizeOfExpr0"><pre>Same as unaryExprOrTypeTraitExpr, but only matching 6704sizeof. 6705</pre></td></tr> 6706 6707 6708<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> 6709<tr><td colspan="4" class="doc" id="hasReplacementType0"><pre>Matches template type parameter substitutions that have a replacement 6710type that matches the provided matcher. 6711 6712Given 6713 template <typename T> 6714 double F(T t); 6715 int i; 6716 double j = F(i); 6717 6718substTemplateTypeParmType(hasReplacementType(type())) matches int 6719</pre></td></tr> 6720 6721 6722<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> 6723<tr><td colspan="4" class="doc" id="forEachSwitchCase0"><pre>Matches each case or default statement belonging to the given switch 6724statement. This matcher may produce multiple matches. 6725 6726Given 6727 switch (1) { case 1: case 2: default: switch (2) { case 3: case 4: ; } } 6728switchStmt(forEachSwitchCase(caseStmt().bind("c"))).bind("s") 6729 matches four times, with "c" binding each of "case 1:", "case 2:", 6730"case 3:" and "case 4:", and "s" respectively binding "switch (1)", 6731"switch (1)", "switch (2)" and "switch (2)". 6732</pre></td></tr> 6733 6734 6735<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> 6736<tr><td colspan="4" class="doc" id="hasCondition4"><pre>Matches the condition expression of an if statement, for loop, 6737switch statement or conditional operator. 6738 6739Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true)))) 6740 if (true) {} 6741</pre></td></tr> 6742 6743 6744<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> 6745<tr><td colspan="4" class="doc" id="hasDeclaration4"><pre>Matches a node if the declaration associated with that node 6746matches the given matcher. 6747 6748The associated declaration is: 6749- for type nodes, the declaration of the underlying type 6750- for CallExpr, the declaration of the callee 6751- for MemberExpr, the declaration of the referenced member 6752- for CXXConstructExpr, the declaration of the constructor 6753- for CXXNewExpr, the declaration of the operator new 6754- for ObjCIvarExpr, the declaration of the ivar 6755 6756For type nodes, hasDeclaration will generally match the declaration of the 6757sugared type. Given 6758 class X {}; 6759 typedef X Y; 6760 Y y; 6761in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 6762typedefDecl. A common use case is to match the underlying, desugared type. 6763This can be achieved by using the hasUnqualifiedDesugaredType matcher: 6764 varDecl(hasType(hasUnqualifiedDesugaredType( 6765 recordType(hasDeclaration(decl()))))) 6766In this matcher, the decl will match the CXXRecordDecl of class X. 6767 6768Usable 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>>, 6769 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>>, 6770 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>>, 6771 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>>, 6772 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>>, 6773 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>>, 6774 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 6775</pre></td></tr> 6776 6777 6778<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> 6779<tr><td colspan="4" class="doc" id="isExpr0"><pre>Matches a sugar TemplateArgument that refers to a certain expression. 6780 6781Given 6782 struct B { int next; }; 6783 template<int(B::*next_ptr)> struct A {}; 6784 A<&B::next> a; 6785templateSpecializationType(hasAnyTemplateArgument( 6786 isExpr(hasDescendant(declRefExpr(to(fieldDecl(hasName("next")))))))) 6787 matches the specialization A<&B::next> with fieldDecl(...) matching 6788 B::next 6789</pre></td></tr> 6790 6791 6792<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> 6793<tr><td colspan="4" class="doc" id="refersToDeclaration0"><pre>Matches a canonical TemplateArgument that refers to a certain 6794declaration. 6795 6796Given 6797 struct B { int next; }; 6798 template<int(B::*next_ptr)> struct A {}; 6799 A<&B::next> a; 6800classTemplateSpecializationDecl(hasAnyTemplateArgument( 6801 refersToDeclaration(fieldDecl(hasName("next"))))) 6802 matches the specialization A<&B::next> with fieldDecl(...) matching 6803 B::next 6804</pre></td></tr> 6805 6806 6807<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> 6808<tr><td colspan="4" class="doc" id="refersToIntegralType0"><pre>Matches a TemplateArgument that referes to an integral type. 6809 6810Given 6811 template<int T> struct C {}; 6812 C<42> c; 6813classTemplateSpecializationDecl( 6814 hasAnyTemplateArgument(refersToIntegralType(asString("int")))) 6815 matches the implicit instantiation of C in C<42>. 6816</pre></td></tr> 6817 6818 6819<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> 6820<tr><td colspan="4" class="doc" id="refersToTemplate0"><pre>Matches a TemplateArgument that refers to a certain template. 6821 6822Given 6823 template<template <typename> class S> class X {}; 6824 template<typename T> class Y {}; 6825 X<Y> xi; 6826classTemplateSpecializationDecl(hasAnyTemplateArgument( 6827 refersToTemplate(templateName()))) 6828 matches the specialization X<Y> 6829</pre></td></tr> 6830 6831 6832<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> 6833<tr><td colspan="4" class="doc" id="refersToType0"><pre>Matches a TemplateArgument that refers to a certain type. 6834 6835Given 6836 struct X {}; 6837 template<typename T> struct A {}; 6838 A<X> a; 6839classTemplateSpecializationDecl(hasAnyTemplateArgument( 6840 refersToType(class(hasName("X"))))) 6841 matches the specialization A<X> 6842</pre></td></tr> 6843 6844 6845<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> 6846<tr><td colspan="4" class="doc" id="hasAnyTemplateArgument1"><pre>Matches classTemplateSpecializations, templateSpecializationType and 6847functionDecl that have at least one TemplateArgument matching the given 6848InnerMatcher. 6849 6850Given 6851 template<typename T> class A {}; 6852 template<> class A<double> {}; 6853 A<int> a; 6854 6855 template<typename T> f() {}; 6856 void func() { f<int>(); }; 6857 6858classTemplateSpecializationDecl(hasAnyTemplateArgument( 6859 refersToType(asString("int")))) 6860 matches the specialization A<int> 6861 6862functionDecl(hasAnyTemplateArgument(refersToType(asString("int")))) 6863 matches the specialization f<int> 6864</pre></td></tr> 6865 6866 6867<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> 6868<tr><td colspan="4" class="doc" id="hasDeclaration3"><pre>Matches a node if the declaration associated with that node 6869matches the given matcher. 6870 6871The associated declaration is: 6872- for type nodes, the declaration of the underlying type 6873- for CallExpr, the declaration of the callee 6874- for MemberExpr, the declaration of the referenced member 6875- for CXXConstructExpr, the declaration of the constructor 6876- for CXXNewExpr, the declaration of the operator new 6877- for ObjCIvarExpr, the declaration of the ivar 6878 6879For type nodes, hasDeclaration will generally match the declaration of the 6880sugared type. Given 6881 class X {}; 6882 typedef X Y; 6883 Y y; 6884in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 6885typedefDecl. A common use case is to match the underlying, desugared type. 6886This can be achieved by using the hasUnqualifiedDesugaredType matcher: 6887 varDecl(hasType(hasUnqualifiedDesugaredType( 6888 recordType(hasDeclaration(decl()))))) 6889In this matcher, the decl will match the CXXRecordDecl of class X. 6890 6891Usable 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>>, 6892 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>>, 6893 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>>, 6894 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>>, 6895 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>>, 6896 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>>, 6897 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 6898</pre></td></tr> 6899 6900 6901<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> 6902<tr><td colspan="4" class="doc" id="hasTemplateArgument1"><pre>Matches classTemplateSpecializations, templateSpecializationType and 6903functionDecl where the n'th TemplateArgument matches the given InnerMatcher. 6904 6905Given 6906 template<typename T, typename U> class A {}; 6907 A<bool, int> b; 6908 A<int, bool> c; 6909 6910 template<typename T> void f() {} 6911 void func() { f<int>(); }; 6912classTemplateSpecializationDecl(hasTemplateArgument( 6913 1, refersToType(asString("int")))) 6914 matches the specialization A<bool, int> 6915 6916functionDecl(hasTemplateArgument(0, refersToType(asString("int")))) 6917 matches the specialization f<int> 6918</pre></td></tr> 6919 6920 6921<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> 6922<tr><td colspan="4" class="doc" id="hasDeclaration2"><pre>Matches a node if the declaration associated with that node 6923matches the given matcher. 6924 6925The associated declaration is: 6926- for type nodes, the declaration of the underlying type 6927- for CallExpr, the declaration of the callee 6928- for MemberExpr, the declaration of the referenced member 6929- for CXXConstructExpr, the declaration of the constructor 6930- for CXXNewExpr, the declaration of the operator new 6931- for ObjCIvarExpr, the declaration of the ivar 6932 6933For type nodes, hasDeclaration will generally match the declaration of the 6934sugared type. Given 6935 class X {}; 6936 typedef X Y; 6937 Y y; 6938in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 6939typedefDecl. A common use case is to match the underlying, desugared type. 6940This can be achieved by using the hasUnqualifiedDesugaredType matcher: 6941 varDecl(hasType(hasUnqualifiedDesugaredType( 6942 recordType(hasDeclaration(decl()))))) 6943In this matcher, the decl will match the CXXRecordDecl of class X. 6944 6945Usable 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>>, 6946 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>>, 6947 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>>, 6948 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>>, 6949 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>>, 6950 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>>, 6951 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 6952</pre></td></tr> 6953 6954 6955<tr><td>Matcher<T></td><td class="name" onclick="toggle('findAll0')"><a name="findAll0Anchor">findAll</a></td><td>const Matcher<T> Matcher</td></tr> 6956<tr><td colspan="4" class="doc" id="findAll0"><pre>Matches if the node or any descendant matches. 6957 6958Generates results for each match. 6959 6960For example, in: 6961 class A { class B {}; class C {}; }; 6962The matcher: 6963 cxxRecordDecl(hasName("::A"), 6964 findAll(cxxRecordDecl(isDefinition()).bind("m"))) 6965will generate results for A, B and C. 6966 6967Usable as: Any Matcher 6968</pre></td></tr> 6969 6970 6971<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> 6972<tr><td colspan="4" class="doc" id="hasType2"><pre>Matches if the expression's or declaration's type matches a type 6973matcher. 6974 6975Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) 6976 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) 6977 and U (matcher = typedefDecl(hasType(asString("int"))) 6978 and friend class X (matcher = friendDecl(hasType("X")) 6979 class X {}; 6980 void y(X &x) { x; X z; } 6981 typedef int U; 6982 class Y { friend class X; }; 6983</pre></td></tr> 6984 6985 6986<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> 6987<tr><td colspan="4" class="doc" id="hasDeclaration1"><pre>Matches a node if the declaration associated with that node 6988matches the given matcher. 6989 6990The associated declaration is: 6991- for type nodes, the declaration of the underlying type 6992- for CallExpr, the declaration of the callee 6993- for MemberExpr, the declaration of the referenced member 6994- for CXXConstructExpr, the declaration of the constructor 6995- for CXXNewExpr, the declaration of the operator new 6996- for ObjCIvarExpr, the declaration of the ivar 6997 6998For type nodes, hasDeclaration will generally match the declaration of the 6999sugared type. Given 7000 class X {}; 7001 typedef X Y; 7002 Y y; 7003in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 7004typedefDecl. A common use case is to match the underlying, desugared type. 7005This can be achieved by using the hasUnqualifiedDesugaredType matcher: 7006 varDecl(hasType(hasUnqualifiedDesugaredType( 7007 recordType(hasDeclaration(decl()))))) 7008In this matcher, the decl will match the CXXRecordDecl of class X. 7009 7010Usable 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>>, 7011 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>>, 7012 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>>, 7013 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>>, 7014 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>>, 7015 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>>, 7016 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 7017</pre></td></tr> 7018 7019 7020<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> 7021<tr><td colspan="4" class="doc" id="hasUnqualifiedDesugaredType0"><pre>Matches if the matched type matches the unqualified desugared 7022type of the matched node. 7023 7024For example, in: 7025 class A {}; 7026 using B = A; 7027The matcher type(hasUnqualifiedDesugaredType(recordType())) matches 7028both B and A. 7029</pre></td></tr> 7030 7031 7032<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> 7033<tr><td colspan="4" class="doc" id="hasArgumentOfType0"><pre>Matches unary expressions that have a specific type of argument. 7034 7035Given 7036 int a, c; float b; int s = sizeof(a) + sizeof(b) + alignof(c); 7037unaryExprOrTypeTraitExpr(hasArgumentOfType(asString("int")) 7038 matches sizeof(a) and alignof(c) 7039</pre></td></tr> 7040 7041 7042<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> 7043<tr><td colspan="4" class="doc" id="hasUnaryOperand0"><pre>Matches if the operand of a unary operator matches. 7044 7045Example matches true (matcher = hasUnaryOperand( 7046 cxxBoolLiteral(equals(true)))) 7047 !true 7048</pre></td></tr> 7049 7050 7051<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> 7052<tr><td colspan="4" class="doc" id="hasObjectExpression1"><pre>Matches a member expression where the object expression is matched by a 7053given matcher. Implicit object expressions are included; that is, it matches 7054use of implicit `this`. 7055 7056Given 7057 struct X { 7058 int m; 7059 int f(X x) { x.m; return m; } 7060 }; 7061memberExpr(hasObjectExpression(hasType(cxxRecordDecl(hasName("X"))))) 7062 matches `x.m`, but not `m`; however, 7063memberExpr(hasObjectExpression(hasType(pointsTo( 7064 cxxRecordDecl(hasName("X")))))) 7065 matches `m` (aka. `this->m`), but not `x.m`. 7066</pre></td></tr> 7067 7068 7069<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> 7070<tr><td colspan="4" class="doc" id="hasDeclaration0"><pre>Matches a node if the declaration associated with that node 7071matches the given matcher. 7072 7073The associated declaration is: 7074- for type nodes, the declaration of the underlying type 7075- for CallExpr, the declaration of the callee 7076- for MemberExpr, the declaration of the referenced member 7077- for CXXConstructExpr, the declaration of the constructor 7078- for CXXNewExpr, the declaration of the operator new 7079- for ObjCIvarExpr, the declaration of the ivar 7080 7081For type nodes, hasDeclaration will generally match the declaration of the 7082sugared type. Given 7083 class X {}; 7084 typedef X Y; 7085 Y y; 7086in varDecl(hasType(hasDeclaration(decl()))) the decl will match the 7087typedefDecl. A common use case is to match the underlying, desugared type. 7088This can be achieved by using the hasUnqualifiedDesugaredType matcher: 7089 varDecl(hasType(hasUnqualifiedDesugaredType( 7090 recordType(hasDeclaration(decl()))))) 7091In this matcher, the decl will match the CXXRecordDecl of class X. 7092 7093Usable 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>>, 7094 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>>, 7095 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>>, 7096 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>>, 7097 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>>, 7098 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>>, 7099 Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 7100</pre></td></tr> 7101 7102 7103<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> 7104<tr><td colspan="4" class="doc" id="hasAnyUsingShadowDecl0"><pre>Matches any using shadow declaration. 7105 7106Given 7107 namespace X { void b(); } 7108 using X::b; 7109usingDecl(hasAnyUsingShadowDecl(hasName("b")))) 7110 matches using X::b </pre></td></tr> 7111 7112 7113<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> 7114<tr><td colspan="4" class="doc" id="hasTargetDecl0"><pre>Matches a using shadow declaration where the target declaration is 7115matched by the given matcher. 7116 7117Given 7118 namespace X { int a; void b(); } 7119 using X::a; 7120 using X::b; 7121usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(functionDecl()))) 7122 matches using X::b but not using X::a </pre></td></tr> 7123 7124 7125<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> 7126<tr><td colspan="4" class="doc" id="hasType6"><pre>Overloaded to match the declaration of the expression's or value 7127declaration's type. 7128 7129In case of a value declaration (for example a variable declaration), 7130this resolves one layer of indirection. For example, in the value 7131declaration "X x;", cxxRecordDecl(hasName("X")) matches the declaration of 7132X, while varDecl(hasType(cxxRecordDecl(hasName("X")))) matches the 7133declaration of x. 7134 7135Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) 7136 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) 7137 and friend class X (matcher = friendDecl(hasType("X")) 7138 class X {}; 7139 void y(X &x) { x; X z; } 7140 class Y { friend class X; }; 7141 7142Usable 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>> 7143</pre></td></tr> 7144 7145 7146<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> 7147<tr><td colspan="4" class="doc" id="hasType3"><pre>Matches if the expression's or declaration's type matches a type 7148matcher. 7149 7150Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) 7151 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) 7152 and U (matcher = typedefDecl(hasType(asString("int"))) 7153 and friend class X (matcher = friendDecl(hasType("X")) 7154 class X {}; 7155 void y(X &x) { x; X z; } 7156 typedef int U; 7157 class Y { friend class X; }; 7158</pre></td></tr> 7159 7160 7161<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> 7162<tr><td colspan="4" class="doc" id="hasInitializer0"><pre>Matches a variable declaration that has an initializer expression 7163that matches the given matcher. 7164 7165Example matches x (matcher = varDecl(hasInitializer(callExpr()))) 7166 bool y() { return true; } 7167 bool x = y(); 7168</pre></td></tr> 7169 7170 7171<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> 7172<tr><td colspan="4" class="doc" id="hasSizeExpr0"><pre>Matches VariableArrayType nodes that have a specific size 7173expression. 7174 7175Given 7176 void f(int b) { 7177 int a[b]; 7178 } 7179variableArrayType(hasSizeExpr(ignoringImpCasts(declRefExpr(to( 7180 varDecl(hasName("b"))))))) 7181 matches "int a[b]" 7182</pre></td></tr> 7183 7184 7185<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> 7186<tr><td colspan="4" class="doc" id="hasBody2"><pre>Matches a 'for', 'while', 'do while' statement or a function 7187definition that has a given body. 7188 7189Given 7190 for (;;) {} 7191hasBody(compoundStmt()) 7192 matches 'for (;;) {}' 7193with compoundStmt() 7194 matching '{}' 7195</pre></td></tr> 7196 7197 7198<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> 7199<tr><td colspan="4" class="doc" id="hasCondition2"><pre>Matches the condition expression of an if statement, for loop, 7200switch statement or conditional operator. 7201 7202Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true)))) 7203 if (true) {} 7204</pre></td></tr> 7205 7206 7207<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> 7208<tr><td colspan="4" class="doc" id="loc1"><pre>Matches NestedNameSpecifierLocs for which the given inner 7209NestedNameSpecifier-matcher matches. 7210</pre></td></tr> 7211 7212 7213<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> 7214<tr><td colspan="4" class="doc" id="loc0"><pre>Matches TypeLocs for which the given inner 7215QualType-matcher matches. 7216</pre></td></tr> 7217 7218<!--END_TRAVERSAL_MATCHERS --> 7219</table> 7220 7221</div> 7222</body> 7223</html> 7224 7225 7226