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