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