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