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="http://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="http://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="http://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="http://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="http://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="http://clang.llvm.org/doxygen/classclang_1_1ClassTemplateDecl.html">ClassTemplateDecl</a>>...</td></tr> 128<tr><td colspan="4" class="doc" id="classTemplateDecl0"><pre>Matches C++ class template declarations. 129 130Example matches Z 131 template<class T> class Z {}; 132</pre></td></tr> 133 134 135<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html">ClassTemplateSpecializationDecl</a>>...</td></tr> 136<tr><td colspan="4" class="doc" id="classTemplateSpecializationDecl0"><pre>Matches C++ class template specializations. 137 138Given 139 template<typename T> class A {}; 140 template<> class A<double> {}; 141 A<int> a; 142classTemplateSpecializationDecl() 143 matches the specializations A<int> and A<double> 144</pre></td></tr> 145 146 147<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html">CXXConstructorDecl</a>>...</td></tr> 148<tr><td colspan="4" class="doc" id="cxxConstructorDecl0"><pre>Matches C++ constructor declarations. 149 150Example matches Foo::Foo() and Foo::Foo(int) 151 class Foo { 152 public: 153 Foo(); 154 Foo(int); 155 int DoSomething(); 156 }; 157</pre></td></tr> 158 159 160<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXConversionDecl.html">CXXConversionDecl</a>>...</td></tr> 161<tr><td colspan="4" class="doc" id="cxxConversionDecl0"><pre>Matches conversion operator declarations. 162 163Example matches the operator. 164 class X { operator int() const; }; 165</pre></td></tr> 166 167 168<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXDestructorDecl.html">CXXDestructorDecl</a>>...</td></tr> 169<tr><td colspan="4" class="doc" id="cxxDestructorDecl0"><pre>Matches explicit C++ destructor declarations. 170 171Example matches Foo::~Foo() 172 class Foo { 173 public: 174 virtual ~Foo(); 175 }; 176</pre></td></tr> 177 178 179<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>>...</td></tr> 180<tr><td colspan="4" class="doc" id="cxxMethodDecl0"><pre>Matches method declarations. 181 182Example matches y 183 class X { void y(); }; 184</pre></td></tr> 185 186 187<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>>...</td></tr> 188<tr><td colspan="4" class="doc" id="cxxRecordDecl0"><pre>Matches C++ class declarations. 189 190Example matches X, Z 191 class X; 192 template<class T> class Z {}; 193</pre></td></tr> 194 195 196<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>...</td></tr> 197<tr><td colspan="4" class="doc" id="decl0"><pre>Matches declarations. 198 199Examples matches X, C, and the friend declaration inside C; 200 void X(); 201 class C { 202 friend X; 203 }; 204</pre></td></tr> 205 206 207<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1DeclaratorDecl.html">DeclaratorDecl</a>>...</td></tr> 208<tr><td colspan="4" class="doc" id="declaratorDecl0"><pre>Matches declarator declarations (field, variable, function 209and non-type template parameter declarations). 210 211Given 212 class X { int y; }; 213declaratorDecl() 214 matches int y. 215</pre></td></tr> 216 217 218<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1EnumConstantDecl.html">EnumConstantDecl</a>>...</td></tr> 219<tr><td colspan="4" class="doc" id="enumConstantDecl0"><pre>Matches enum constants. 220 221Example matches A, B, C 222 enum X { 223 A, B, C 224 }; 225</pre></td></tr> 226 227 228<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1EnumDecl.html">EnumDecl</a>>...</td></tr> 229<tr><td colspan="4" class="doc" id="enumDecl0"><pre>Matches enum declarations. 230 231Example matches X 232 enum X { 233 A, B, C 234 }; 235</pre></td></tr> 236 237 238<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html">FieldDecl</a>>...</td></tr> 239<tr><td colspan="4" class="doc" id="fieldDecl0"><pre>Matches field declarations. 240 241Given 242 class X { int m; }; 243fieldDecl() 244 matches 'm'. 245</pre></td></tr> 246 247 248<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1FriendDecl.html">FriendDecl</a>>...</td></tr> 249<tr><td colspan="4" class="doc" id="friendDecl0"><pre>Matches friend declarations. 250 251Given 252 class X { friend void foo(); }; 253friendDecl() 254 matches 'friend void foo()'. 255</pre></td></tr> 256 257 258<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>...</td></tr> 259<tr><td colspan="4" class="doc" id="functionDecl0"><pre>Matches function declarations. 260 261Example matches f 262 void f(); 263</pre></td></tr> 264 265 266<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1FunctionTemplateDecl.html">FunctionTemplateDecl</a>>...</td></tr> 267<tr><td colspan="4" class="doc" id="functionTemplateDecl0"><pre>Matches C++ function template declarations. 268 269Example matches f 270 template<class T> void f(T t) {} 271</pre></td></tr> 272 273 274<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1LabelDecl.html">LabelDecl</a>>...</td></tr> 275<tr><td colspan="4" class="doc" id="labelDecl0"><pre>Matches a declaration of label. 276 277Given 278 goto FOO; 279 FOO: bar(); 280labelDecl() 281 matches 'FOO:' 282</pre></td></tr> 283 284 285<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1LinkageSpecDecl.html">LinkageSpecDecl</a>>...</td></tr> 286<tr><td colspan="4" class="doc" id="linkageSpecDecl0"><pre>Matches a declaration of a linkage specification. 287 288Given 289 extern "C" {} 290linkageSpecDecl() 291 matches "extern "C" {}" 292</pre></td></tr> 293 294 295<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>>...</td></tr> 296<tr><td colspan="4" class="doc" id="namedDecl0"><pre>Matches a declaration of anything that could have a name. 297 298Example matches X, S, the anonymous union type, i, and U; 299 typedef int X; 300 struct S { 301 union { 302 int i; 303 } U; 304 }; 305</pre></td></tr> 306 307 308<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1NamespaceAliasDecl.html">NamespaceAliasDecl</a>>...</td></tr> 309<tr><td colspan="4" class="doc" id="namespaceAliasDecl0"><pre>Matches a declaration of a namespace alias. 310 311Given 312 namespace test {} 313 namespace alias = ::test; 314namespaceAliasDecl() 315 matches "namespace alias" but not "namespace test" 316</pre></td></tr> 317 318 319<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1NamespaceDecl.html">NamespaceDecl</a>>...</td></tr> 320<tr><td colspan="4" class="doc" id="namespaceDecl0"><pre>Matches a declaration of a namespace. 321 322Given 323 namespace {} 324 namespace test {} 325namespaceDecl() 326 matches "namespace {}" and "namespace test {}" 327</pre></td></tr> 328 329 330<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1NonTypeTemplateParmDecl.html">NonTypeTemplateParmDecl</a>>...</td></tr> 331<tr><td colspan="4" class="doc" id="nonTypeTemplateParmDecl0"><pre>Matches non-type template parameter declarations. 332 333Given 334 template <typename T, int N> struct C {}; 335nonTypeTemplateParmDecl() 336 matches 'N', but not 'T'. 337</pre></td></tr> 338 339 340<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1ObjCInterfaceDecl.html">ObjCInterfaceDecl</a>>...</td></tr> 341<tr><td colspan="4" class="doc" id="objcInterfaceDecl0"><pre>Matches Objective-C interface declarations. 342 343Example matches Foo 344 @interface Foo 345 @end 346</pre></td></tr> 347 348 349<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html">ParmVarDecl</a>>...</td></tr> 350<tr><td colspan="4" class="doc" id="parmVarDecl0"><pre>Matches parameter variable declarations. 351 352Given 353 void f(int x); 354parmVarDecl() 355 matches int x. 356</pre></td></tr> 357 358 359<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1RecordDecl.html">RecordDecl</a>>...</td></tr> 360<tr><td colspan="4" class="doc" id="recordDecl0"><pre>Matches class, struct, and union declarations. 361 362Example matches X, Z, U, and S 363 class X; 364 template<class T> class Z {}; 365 struct S {}; 366 union U {}; 367</pre></td></tr> 368 369 370<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1StaticAssertDecl.html">StaticAssertDecl</a>>...</td></tr> 371<tr><td colspan="4" class="doc" id="staticAssertDecl0"><pre>Matches a C++ static_assert declaration. 372 373Example: 374 staticAssertExpr() 375matches 376 static_assert(sizeof(S) == sizeof(int)) 377in 378 struct S { 379 int x; 380 }; 381 static_assert(sizeof(S) == sizeof(int)); 382</pre></td></tr> 383 384 385<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmDecl.html">TemplateTypeParmDecl</a>>...</td></tr> 386<tr><td colspan="4" class="doc" id="templateTypeParmDecl0"><pre>Matches template type parameter declarations. 387 388Given 389 template <typename T, int N> struct C {}; 390templateTypeParmDecl() 391 matches 'T', but not 'N'. 392</pre></td></tr> 393 394 395<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1TranslationUnitDecl.html">TranslationUnitDecl</a>>...</td></tr> 396<tr><td colspan="4" class="doc" id="translationUnitDecl0"><pre>Matches the top declaration context. 397 398Given 399 int X; 400 namespace NS { 401 int Y; 402 } namespace NS 403decl(hasDeclContext(translationUnitDecl())) 404 matches "int X", but not "int Y". 405</pre></td></tr> 406 407 408<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1TypeAliasDecl.html">TypeAliasDecl</a>>...</td></tr> 409<tr><td colspan="4" class="doc" id="typeAliasDecl0"><pre>Matches type alias declarations. 410 411Given 412 typedef int X; 413 using Y = int; 414typeAliasDecl() 415 matches "using Y = int", but not "typedef int X" 416</pre></td></tr> 417 418 419<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1TypedefDecl.html">TypedefDecl</a>>...</td></tr> 420<tr><td colspan="4" class="doc" id="typedefDecl0"><pre>Matches typedef declarations. 421 422Given 423 typedef int X; 424 using Y = int; 425typedefDecl() 426 matches "typedef int X", but not "using Y = int" 427</pre></td></tr> 428 429 430<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1TypedefNameDecl.html">TypedefNameDecl</a>>...</td></tr> 431<tr><td colspan="4" class="doc" id="typedefNameDecl0"><pre>Matches typedef name declarations. 432 433Given 434 typedef int X; 435 using Y = int; 436typedefNameDecl() 437 matches "typedef int X" and "using Y = int" 438</pre></td></tr> 439 440 441<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingTypenameDecl.html">UnresolvedUsingTypenameDecl</a>>...</td></tr> 442<tr><td colspan="4" class="doc" id="unresolvedUsingTypenameDecl0"><pre>Matches unresolved using value declarations that involve the 443typename. 444 445Given 446 template <typename T> 447 struct Base { typedef T Foo; }; 448 449 template<typename T> 450 struct S : private Base<T> { 451 using typename Base<T>::Foo; 452 }; 453unresolvedUsingTypenameDecl() 454 matches using Base<T>::Foo </pre></td></tr> 455 456 457<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingValueDecl.html">UnresolvedUsingValueDecl</a>>...</td></tr> 458<tr><td colspan="4" class="doc" id="unresolvedUsingValueDecl0"><pre>Matches unresolved using value declarations. 459 460Given 461 template<typename X> 462 class C : private X { 463 using X::x; 464 }; 465unresolvedUsingValueDecl() 466 matches using X::x </pre></td></tr> 467 468 469<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1UsingDecl.html">UsingDecl</a>>...</td></tr> 470<tr><td colspan="4" class="doc" id="usingDecl0"><pre>Matches using declarations. 471 472Given 473 namespace X { int x; } 474 using X::x; 475usingDecl() 476 matches using X::x </pre></td></tr> 477 478 479<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1UsingDirectiveDecl.html">UsingDirectiveDecl</a>>...</td></tr> 480<tr><td colspan="4" class="doc" id="usingDirectiveDecl0"><pre>Matches using namespace declarations. 481 482Given 483 namespace X { int x; } 484 using namespace X; 485usingDirectiveDecl() 486 matches using namespace X </pre></td></tr> 487 488 489<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</a>>...</td></tr> 490<tr><td colspan="4" class="doc" id="valueDecl0"><pre>Matches any value declaration. 491 492Example matches A, B, C and F 493 enum X { A, B, C }; 494 void F(); 495</pre></td></tr> 496 497 498<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>...</td></tr> 499<tr><td colspan="4" class="doc" id="varDecl0"><pre>Matches variable declarations. 500 501Note: this does not match declarations of member variables, which are 502"field" declarations in Clang parlance. 503 504Example matches a 505 int a; 506</pre></td></tr> 507 508 509<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifierLoc.html">NestedNameSpecifierLoc</a>>...</td></tr> 510<tr><td colspan="4" class="doc" id="nestedNameSpecifierLoc0"><pre>Same as nestedNameSpecifier but matches NestedNameSpecifierLoc. 511</pre></td></tr> 512 513 514<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifier.html">NestedNameSpecifier</a>>...</td></tr> 515<tr><td colspan="4" class="doc" id="nestedNameSpecifier0"><pre>Matches nested name specifiers. 516 517Given 518 namespace ns { 519 struct A { static void f(); }; 520 void A::f() {} 521 void g() { A::f(); } 522 } 523 ns::A a; 524nestedNameSpecifier() 525 matches "ns::" and both "A::" 526</pre></td></tr> 527 528 529<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>...</td></tr> 530<tr><td colspan="4" class="doc" id="qualType0"><pre>Matches QualTypes in the clang AST. 531</pre></td></tr> 532 533 534<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>...</td></tr> 535<tr><td colspan="4" class="doc" id="addrLabelExpr0"><pre>Matches address of label statements (GNU extension). 536 537Given 538 FOO: bar(); 539 void *ptr = &&FOO; 540 goto *bar; 541addrLabelExpr() 542 matches '&&FOO' 543</pre></td></tr> 544 545 546<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1ArraySubscriptExpr.html">ArraySubscriptExpr</a>>...</td></tr> 547<tr><td colspan="4" class="doc" id="arraySubscriptExpr0"><pre>Matches array subscript expressions. 548 549Given 550 int i = a[1]; 551arraySubscriptExpr() 552 matches "a[1]" 553</pre></td></tr> 554 555 556<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1AsmStmt.html">AsmStmt</a>>...</td></tr> 557<tr><td colspan="4" class="doc" id="asmStmt0"><pre>Matches asm statements. 558 559 int i = 100; 560 __asm("mov al, 2"); 561asmStmt() 562 matches '__asm("mov al, 2")' 563</pre></td></tr> 564 565 566<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1AtomicExpr.html">AtomicExpr</a>>...</td></tr> 567<tr><td colspan="4" class="doc" id="atomicExpr0"><pre>Matches atomic builtins. 568Example matches __atomic_load_n(ptr, 1) 569 void foo() { int *ptr; __atomic_load_n(ptr, 1); } 570</pre></td></tr> 571 572 573<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1BinaryConditionalOperator.html">BinaryConditionalOperator</a>>...</td></tr> 574<tr><td colspan="4" class="doc" id="binaryConditionalOperator0"><pre>Matches binary conditional operator expressions (GNU extension). 575 576Example matches a ?: b 577 (a ?: b) + 42; 578</pre></td></tr> 579 580 581<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html">BinaryOperator</a>>...</td></tr> 582<tr><td colspan="4" class="doc" id="binaryOperator0"><pre>Matches binary operator expressions. 583 584Example matches a || b 585 !(a || b) 586</pre></td></tr> 587 588 589<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1BreakStmt.html">BreakStmt</a>>...</td></tr> 590<tr><td colspan="4" class="doc" id="breakStmt0"><pre>Matches break statements. 591 592Given 593 while (true) { break; } 594breakStmt() 595 matches 'break' 596</pre></td></tr> 597 598 599<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CStyleCastExpr.html">CStyleCastExpr</a>>...</td></tr> 600<tr><td colspan="4" class="doc" id="cStyleCastExpr0"><pre>Matches a C-style cast expression. 601 602Example: Matches (int*) 2.2f in 603 int i = (int) 2.2f; 604</pre></td></tr> 605 606 607<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>...</td></tr> 608<tr><td colspan="4" class="doc" id="callExpr0"><pre>Matches call expressions. 609 610Example matches x.y() and y() 611 X x; 612 x.y(); 613 y(); 614</pre></td></tr> 615 616 617<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CaseStmt.html">CaseStmt</a>>...</td></tr> 618<tr><td colspan="4" class="doc" id="caseStmt0"><pre>Matches case statements inside switch statements. 619 620Given 621 switch(a) { case 42: break; default: break; } 622caseStmt() 623 matches 'case 42: break;'. 624</pre></td></tr> 625 626 627<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CastExpr.html">CastExpr</a>>...</td></tr> 628<tr><td colspan="4" class="doc" id="castExpr0"><pre>Matches any cast nodes of Clang's AST. 629 630Example: castExpr() matches each of the following: 631 (int) 3; 632 const_cast<Expr *>(SubExpr); 633 char c = 0; 634but does not match 635 int i = (0); 636 int k = 0; 637</pre></td></tr> 638 639 640<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>>...</td></tr> 641<tr><td colspan="4" class="doc" id="characterLiteral0"><pre>Matches character literals (also matches wchar_t). 642 643Not matching Hex-encoded chars (e.g. 0x1234, which is a IntegerLiteral), 644though. 645 646Example matches 'a', L'a' 647 char ch = 'a'; 648 wchar_t chw = L'a'; 649</pre></td></tr> 650 651 652<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CompoundLiteralExpr.html">CompoundLiteralExpr</a>>...</td></tr> 653<tr><td colspan="4" class="doc" id="compoundLiteralExpr0"><pre>Matches compound (i.e. non-scalar) literals 654 655Example match: {1}, (1, 2) 656 int array[4] = {1}; 657 vector int myvec = (vector int)(1, 2); 658</pre></td></tr> 659 660 661<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CompoundStmt.html">CompoundStmt</a>>...</td></tr> 662<tr><td colspan="4" class="doc" id="compoundStmt0"><pre>Matches compound statements. 663 664Example matches '{}' and '{{}}'in 'for (;;) {{}}' 665 for (;;) {{}} 666</pre></td></tr> 667 668 669<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1ConditionalOperator.html">ConditionalOperator</a>>...</td></tr> 670<tr><td colspan="4" class="doc" id="conditionalOperator0"><pre>Matches conditional operator expressions. 671 672Example matches a ? b : c 673 (a ? b : c) + 42 674</pre></td></tr> 675 676 677<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1ContinueStmt.html">ContinueStmt</a>>...</td></tr> 678<tr><td colspan="4" class="doc" id="continueStmt0"><pre>Matches continue statements. 679 680Given 681 while (true) { continue; } 682continueStmt() 683 matches 'continue' 684</pre></td></tr> 685 686 687<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CUDAKernelCallExpr.html">CUDAKernelCallExpr</a>>...</td></tr> 688<tr><td colspan="4" class="doc" id="cudaKernelCallExpr0"><pre>Matches CUDA kernel call expression. 689 690Example matches, 691 kernel<<<i,j>>>(); 692</pre></td></tr> 693 694 695<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXBindTemporaryExpr.html">CXXBindTemporaryExpr</a>>...</td></tr> 696<tr><td colspan="4" class="doc" id="cxxBindTemporaryExpr0"><pre>Matches nodes where temporaries are created. 697 698Example matches FunctionTakesString(GetStringByValue()) 699 (matcher = cxxBindTemporaryExpr()) 700 FunctionTakesString(GetStringByValue()); 701 FunctionTakesStringByPointer(GetStringPointer()); 702</pre></td></tr> 703 704 705<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXBoolLiteralExpr.html">CXXBoolLiteralExpr</a>>...</td></tr> 706<tr><td colspan="4" class="doc" id="cxxBoolLiteral0"><pre>Matches bool literals. 707 708Example matches true 709 true 710</pre></td></tr> 711 712 713<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXCatchStmt.html">CXXCatchStmt</a>>...</td></tr> 714<tr><td colspan="4" class="doc" id="cxxCatchStmt0"><pre>Matches catch statements. 715 716 try {} catch(int i) {} 717cxxCatchStmt() 718 matches 'catch(int i)' 719</pre></td></tr> 720 721 722<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXConstCastExpr.html">CXXConstCastExpr</a>>...</td></tr> 723<tr><td colspan="4" class="doc" id="cxxConstCastExpr0"><pre>Matches a const_cast expression. 724 725Example: Matches const_cast<int*>(&r) in 726 int n = 42; 727 const int &r(n); 728 int* p = const_cast<int*>(&r); 729</pre></td></tr> 730 731 732<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>...</td></tr> 733<tr><td colspan="4" class="doc" id="cxxConstructExpr0"><pre>Matches constructor call expressions (including implicit ones). 734 735Example matches string(ptr, n) and ptr within arguments of f 736 (matcher = cxxConstructExpr()) 737 void f(const string &a, const string &b); 738 char *ptr; 739 int n; 740 f(string(ptr, n), ptr); 741</pre></td></tr> 742 743 744<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXDefaultArgExpr.html">CXXDefaultArgExpr</a>>...</td></tr> 745<tr><td colspan="4" class="doc" id="cxxDefaultArgExpr0"><pre>Matches the value of a default argument at the call site. 746 747Example matches the CXXDefaultArgExpr placeholder inserted for the 748 default value of the second parameter in the call expression f(42) 749 (matcher = cxxDefaultArgExpr()) 750 void f(int x, int y = 0); 751 f(42); 752</pre></td></tr> 753 754 755<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXDeleteExpr.html">CXXDeleteExpr</a>>...</td></tr> 756<tr><td colspan="4" class="doc" id="cxxDeleteExpr0"><pre>Matches delete expressions. 757 758Given 759 delete X; 760cxxDeleteExpr() 761 matches 'delete X'. 762</pre></td></tr> 763 764 765<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXDynamicCastExpr.html">CXXDynamicCastExpr</a>>...</td></tr> 766<tr><td colspan="4" class="doc" id="cxxDynamicCastExpr0"><pre>Matches a dynamic_cast expression. 767 768Example: 769 cxxDynamicCastExpr() 770matches 771 dynamic_cast<D*>(&b); 772in 773 struct B { virtual ~B() {} }; struct D : B {}; 774 B b; 775 D* p = dynamic_cast<D*>(&b); 776</pre></td></tr> 777 778 779<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXForRangeStmt.html">CXXForRangeStmt</a>>...</td></tr> 780<tr><td colspan="4" class="doc" id="cxxForRangeStmt0"><pre>Matches range-based for statements. 781 782cxxForRangeStmt() matches 'for (auto a : i)' 783 int i[] = {1, 2, 3}; for (auto a : i); 784 for(int j = 0; j < 5; ++j); 785</pre></td></tr> 786 787 788<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXFunctionalCastExpr.html">CXXFunctionalCastExpr</a>>...</td></tr> 789<tr><td colspan="4" class="doc" id="cxxFunctionalCastExpr0"><pre>Matches functional cast expressions 790 791Example: Matches Foo(bar); 792 Foo f = bar; 793 Foo g = (Foo) bar; 794 Foo h = Foo(bar); 795</pre></td></tr> 796 797 798<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXMemberCallExpr.html">CXXMemberCallExpr</a>>...</td></tr> 799<tr><td colspan="4" class="doc" id="cxxMemberCallExpr0"><pre>Matches member call expressions. 800 801Example matches x.y() 802 X x; 803 x.y(); 804</pre></td></tr> 805 806 807<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXNewExpr.html">CXXNewExpr</a>>...</td></tr> 808<tr><td colspan="4" class="doc" id="cxxNewExpr0"><pre>Matches new expressions. 809 810Given 811 new X; 812cxxNewExpr() 813 matches 'new X'. 814</pre></td></tr> 815 816 817<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXNullPtrLiteralExpr.html">CXXNullPtrLiteralExpr</a>>...</td></tr> 818<tr><td colspan="4" class="doc" id="cxxNullPtrLiteralExpr0"><pre>Matches nullptr literal. 819</pre></td></tr> 820 821 822<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>>...</td></tr> 823<tr><td colspan="4" class="doc" id="cxxOperatorCallExpr0"><pre>Matches overloaded operator calls. 824 825Note that if an operator isn't overloaded, it won't match. Instead, use 826binaryOperator matcher. 827Currently it does not match operators such as new delete. 828FIXME: figure out why these do not match? 829 830Example matches both operator<<((o << b), c) and operator<<(o, b) 831 (matcher = cxxOperatorCallExpr()) 832 ostream &operator<< (ostream &out, int i) { }; 833 ostream &o; int b = 1, c = 1; 834 o << b << c; 835</pre></td></tr> 836 837 838<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXReinterpretCastExpr.html">CXXReinterpretCastExpr</a>>...</td></tr> 839<tr><td colspan="4" class="doc" id="cxxReinterpretCastExpr0"><pre>Matches a reinterpret_cast expression. 840 841Either the source expression or the destination type can be matched 842using has(), but hasDestinationType() is more specific and can be 843more readable. 844 845Example matches reinterpret_cast<char*>(&p) in 846 void* p = reinterpret_cast<char*>(&p); 847</pre></td></tr> 848 849 850<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXStaticCastExpr.html">CXXStaticCastExpr</a>>...</td></tr> 851<tr><td colspan="4" class="doc" id="cxxStaticCastExpr0"><pre>Matches a C++ static_cast expression. 852 853See also: hasDestinationType 854See also: reinterpretCast 855 856Example: 857 cxxStaticCastExpr() 858matches 859 static_cast<long>(8) 860in 861 long eight(static_cast<long>(8)); 862</pre></td></tr> 863 864 865<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXTemporaryObjectExpr.html">CXXTemporaryObjectExpr</a>>...</td></tr> 866<tr><td colspan="4" class="doc" id="cxxTemporaryObjectExpr0"><pre>Matches functional cast expressions having N != 1 arguments 867 868Example: Matches Foo(bar, bar) 869 Foo h = Foo(bar, bar); 870</pre></td></tr> 871 872 873<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXThisExpr.html">CXXThisExpr</a>>...</td></tr> 874<tr><td colspan="4" class="doc" id="cxxThisExpr0"><pre>Matches implicit and explicit this expressions. 875 876Example matches the implicit this expression in "return i". 877 (matcher = cxxThisExpr()) 878struct foo { 879 int i; 880 int f() { return i; } 881}; 882</pre></td></tr> 883 884 885<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXThrowExpr.html">CXXThrowExpr</a>>...</td></tr> 886<tr><td colspan="4" class="doc" id="cxxThrowExpr0"><pre>Matches throw expressions. 887 888 try { throw 5; } catch(int i) {} 889cxxThrowExpr() 890 matches 'throw 5' 891</pre></td></tr> 892 893 894<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXTryStmt.html">CXXTryStmt</a>>...</td></tr> 895<tr><td colspan="4" class="doc" id="cxxTryStmt0"><pre>Matches try statements. 896 897 try {} catch(int i) {} 898cxxTryStmt() 899 matches 'try {}' 900</pre></td></tr> 901 902 903<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXUnresolvedConstructExpr.html">CXXUnresolvedConstructExpr</a>>...</td></tr> 904<tr><td colspan="4" class="doc" id="cxxUnresolvedConstructExpr0"><pre>Matches unresolved constructor call expressions. 905 906Example matches T(t) in return statement of f 907 (matcher = cxxUnresolvedConstructExpr()) 908 template <typename T> 909 void f(const T& t) { return T(t); } 910</pre></td></tr> 911 912 913<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>...</td></tr> 914<tr><td colspan="4" class="doc" id="declRefExpr0"><pre>Matches expressions that refer to declarations. 915 916Example matches x in if (x) 917 bool x; 918 if (x) {} 919</pre></td></tr> 920 921 922<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html">DeclStmt</a>>...</td></tr> 923<tr><td colspan="4" class="doc" id="declStmt0"><pre>Matches declaration statements. 924 925Given 926 int a; 927declStmt() 928 matches 'int a'. 929</pre></td></tr> 930 931 932<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1DefaultStmt.html">DefaultStmt</a>>...</td></tr> 933<tr><td colspan="4" class="doc" id="defaultStmt0"><pre>Matches default statements inside switch statements. 934 935Given 936 switch(a) { case 42: break; default: break; } 937defaultStmt() 938 matches 'default: break;'. 939</pre></td></tr> 940 941 942<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1DesignatedInitExpr.html">DesignatedInitExpr</a>>...</td></tr> 943<tr><td colspan="4" class="doc" id="designatedInitExpr0"><pre>Matches C99 designated initializer expressions [C99 6.7.8]. 944 945Example: Matches { [2].y = 1.0, [0].x = 1.0 } 946 point ptarray[10] = { [2].y = 1.0, [0].x = 1.0 }; 947</pre></td></tr> 948 949 950<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1DoStmt.html">DoStmt</a>>...</td></tr> 951<tr><td colspan="4" class="doc" id="doStmt0"><pre>Matches do statements. 952 953Given 954 do {} while (true); 955doStmt() 956 matches 'do {} while(true)' 957</pre></td></tr> 958 959 960<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1ExplicitCastExpr.html">ExplicitCastExpr</a>>...</td></tr> 961<tr><td colspan="4" class="doc" id="explicitCastExpr0"><pre>Matches explicit cast expressions. 962 963Matches any cast expression written in user code, whether it be a 964C-style cast, a functional-style cast, or a keyword cast. 965 966Does not match implicit conversions. 967 968Note: the name "explicitCast" is chosen to match Clang's terminology, as 969Clang uses the term "cast" to apply to implicit conversions as well as to 970actual cast expressions. 971 972See also: hasDestinationType. 973 974Example: matches all five of the casts in 975 int((int)(reinterpret_cast<int>(static_cast<int>(const_cast<int>(42))))) 976but does not match the implicit conversion in 977 long ell = 42; 978</pre></td></tr> 979 980 981<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>>...</td></tr> 982<tr><td colspan="4" class="doc" id="expr0"><pre>Matches expressions. 983 984Example matches x() 985 void f() { x(); } 986</pre></td></tr> 987 988 989<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1ExprWithCleanups.html">ExprWithCleanups</a>>...</td></tr> 990<tr><td colspan="4" class="doc" id="exprWithCleanups0"><pre>Matches expressions that introduce cleanups to be run at the end 991of the sub-expression's evaluation. 992 993Example matches std::string() 994 const std::string str = std::string(); 995</pre></td></tr> 996 997 998<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>>...</td></tr> 999<tr><td colspan="4" class="doc" id="floatLiteral0"><pre>Matches float literals of all sizes encodings, e.g. 10001.0, 1.0f, 1.0L and 1e10. 1001 1002Does not match implicit conversions such as 1003 float a = 10; 1004</pre></td></tr> 1005 1006 1007<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1ForStmt.html">ForStmt</a>>...</td></tr> 1008<tr><td colspan="4" class="doc" id="forStmt0"><pre>Matches for statements. 1009 1010Example matches 'for (;;) {}' 1011 for (;;) {} 1012 int i[] = {1, 2, 3}; for (auto a : i); 1013</pre></td></tr> 1014 1015 1016<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1GNUNullExpr.html">GNUNullExpr</a>>...</td></tr> 1017<tr><td colspan="4" class="doc" id="gnuNullExpr0"><pre>Matches GNU __null expression. 1018</pre></td></tr> 1019 1020 1021<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1GotoStmt.html">GotoStmt</a>>...</td></tr> 1022<tr><td colspan="4" class="doc" id="gotoStmt0"><pre>Matches goto statements. 1023 1024Given 1025 goto FOO; 1026 FOO: bar(); 1027gotoStmt() 1028 matches 'goto FOO' 1029</pre></td></tr> 1030 1031 1032<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1IfStmt.html">IfStmt</a>>...</td></tr> 1033<tr><td colspan="4" class="doc" id="ifStmt0"><pre>Matches if statements. 1034 1035Example matches 'if (x) {}' 1036 if (x) {} 1037</pre></td></tr> 1038 1039 1040<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1ImplicitCastExpr.html">ImplicitCastExpr</a>>...</td></tr> 1041<tr><td colspan="4" class="doc" id="implicitCastExpr0"><pre>Matches the implicit cast nodes of Clang's AST. 1042 1043This matches many different places, including function call return value 1044eliding, as well as any type conversions. 1045</pre></td></tr> 1046 1047 1048<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1ImplicitValueInitExpr.html">ImplicitValueInitExpr</a>>...</td></tr> 1049<tr><td colspan="4" class="doc" id="implicitValueInitExpr0"><pre>Matches implicit initializers of init list expressions. 1050 1051Given 1052 point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 }; 1053implicitValueInitExpr() 1054 matches "[0].y" (implicitly) 1055</pre></td></tr> 1056 1057 1058<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1InitListExpr.html">InitListExpr</a>>...</td></tr> 1059<tr><td colspan="4" class="doc" id="initListExpr0"><pre>Matches init list expressions. 1060 1061Given 1062 int a[] = { 1, 2 }; 1063 struct B { int x, y; }; 1064 B b = { 5, 6 }; 1065initListExpr() 1066 matches "{ 1, 2 }" and "{ 5, 6 }" 1067</pre></td></tr> 1068 1069 1070<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>>...</td></tr> 1071<tr><td colspan="4" class="doc" id="integerLiteral0"><pre>Matches integer literals of all sizes encodings, e.g. 10721, 1L, 0x1 and 1U. 1073 1074Does not match character-encoded integers such as L'a'. 1075</pre></td></tr> 1076 1077 1078<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>...</td></tr> 1079<tr><td colspan="4" class="doc" id="labelStmt0"><pre>Matches label statements. 1080 1081Given 1082 goto FOO; 1083 FOO: bar(); 1084labelStmt() 1085 matches 'FOO:' 1086</pre></td></tr> 1087 1088 1089<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1LambdaExpr.html">LambdaExpr</a>>...</td></tr> 1090<tr><td colspan="4" class="doc" id="lambdaExpr0"><pre>Matches lambda expressions. 1091 1092Example matches [&](){return 5;} 1093 [&](){return 5;} 1094</pre></td></tr> 1095 1096 1097<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1MaterializeTemporaryExpr.html">MaterializeTemporaryExpr</a>>...</td></tr> 1098<tr><td colspan="4" class="doc" id="materializeTemporaryExpr0"><pre>Matches nodes where temporaries are materialized. 1099 1100Example: Given 1101 struct T {void func()}; 1102 T f(); 1103 void g(T); 1104materializeTemporaryExpr() matches 'f()' in these statements 1105 T u(f()); 1106 g(f()); 1107but does not match 1108 f(); 1109 f().func(); 1110</pre></td></tr> 1111 1112 1113<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>...</td></tr> 1114<tr><td colspan="4" class="doc" id="memberExpr0"><pre>Matches member expressions. 1115 1116Given 1117 class Y { 1118 void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; } 1119 int a; static int b; 1120 }; 1121memberExpr() 1122 matches this->x, x, y.x, a, this->b 1123</pre></td></tr> 1124 1125 1126<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1NullStmt.html">NullStmt</a>>...</td></tr> 1127<tr><td colspan="4" class="doc" id="nullStmt0"><pre>Matches null statements. 1128 1129 foo();; 1130nullStmt() 1131 matches the second ';' 1132</pre></td></tr> 1133 1134 1135<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>>...</td></tr> 1136<tr><td colspan="4" class="doc" id="objcMessageExpr0"><pre>Matches ObjectiveC Message invocation expressions. 1137 1138The innermost message send invokes the "alloc" class method on the 1139NSString class, while the outermost message send invokes the 1140"initWithString" instance method on the object returned from 1141NSString's "alloc". This matcher should match both message sends. 1142 [[NSString alloc] initWithString:@"Hello"] 1143</pre></td></tr> 1144 1145 1146<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1OpaqueValueExpr.html">OpaqueValueExpr</a>>...</td></tr> 1147<tr><td colspan="4" class="doc" id="opaqueValueExpr0"><pre>Matches opaque value expressions. They are used as helpers 1148to reference another expressions and can be met 1149in BinaryConditionalOperators, for example. 1150 1151Example matches 'a' 1152 (a ?: c) + 42; 1153</pre></td></tr> 1154 1155 1156<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1ParenExpr.html">ParenExpr</a>>...</td></tr> 1157<tr><td colspan="4" class="doc" id="parenExpr0"><pre>Matches parentheses used in expressions. 1158 1159Example matches (foo() + 1) 1160 int foo() { return 1; } 1161 int a = (foo() + 1); 1162</pre></td></tr> 1163 1164 1165<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1ParenListExpr.html">ParenListExpr</a>>...</td></tr> 1166<tr><td colspan="4" class="doc" id="parenListExpr0"><pre>Matches paren list expressions. 1167ParenListExprs don't have a predefined type and are used for late parsing. 1168In the final AST, they can be met in template declarations. 1169 1170Given 1171 template<typename T> class X { 1172 void f() { 1173 X x(*this); 1174 int a = 0, b = 1; int i = (a, b); 1175 } 1176 }; 1177parenListExpr() matches "*this" but NOT matches (a, b) because (a, b) 1178has a predefined type and is a ParenExpr, not a ParenListExpr. 1179</pre></td></tr> 1180 1181 1182<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1PredefinedExpr.html">PredefinedExpr</a>>...</td></tr> 1183<tr><td colspan="4" class="doc" id="predefinedExpr0"><pre>Matches predefined identifier expressions [C99 6.4.2.2]. 1184 1185Example: Matches __func__ 1186 printf("%s", __func__); 1187</pre></td></tr> 1188 1189 1190<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1ReturnStmt.html">ReturnStmt</a>>...</td></tr> 1191<tr><td colspan="4" class="doc" id="returnStmt0"><pre>Matches return statements. 1192 1193Given 1194 return 1; 1195returnStmt() 1196 matches 'return 1' 1197</pre></td></tr> 1198 1199 1200<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>>...</td></tr> 1201<tr><td colspan="4" class="doc" id="stmt0"><pre>Matches statements. 1202 1203Given 1204 { ++a; } 1205stmt() 1206 matches both the compound statement '{ ++a; }' and '++a'. 1207</pre></td></tr> 1208 1209 1210<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1StmtExpr.html">StmtExpr</a>>...</td></tr> 1211<tr><td colspan="4" class="doc" id="stmtExpr0"><pre>Matches statement expression (GNU extension). 1212 1213Example match: ({ int X = 4; X; }) 1214 int C = ({ int X = 4; X; }); 1215</pre></td></tr> 1216 1217 1218<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1StringLiteral.html">StringLiteral</a>>...</td></tr> 1219<tr><td colspan="4" class="doc" id="stringLiteral0"><pre>Matches string literals (also matches wide string literals). 1220 1221Example matches "abcd", L"abcd" 1222 char *s = "abcd"; 1223 wchar_t *ws = L"abcd"; 1224</pre></td></tr> 1225 1226 1227<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1SubstNonTypeTemplateParmExpr.html">SubstNonTypeTemplateParmExpr</a>>...</td></tr> 1228<tr><td colspan="4" class="doc" id="substNonTypeTemplateParmExpr0"><pre>Matches substitutions of non-type template parameters. 1229 1230Given 1231 template <int N> 1232 struct A { static const int n = N; }; 1233 struct B : public A<42> {}; 1234substNonTypeTemplateParmExpr() 1235 matches "N" in the right-hand side of "static const int n = N;" 1236</pre></td></tr> 1237 1238 1239<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1SwitchCase.html">SwitchCase</a>>...</td></tr> 1240<tr><td colspan="4" class="doc" id="switchCase0"><pre>Matches case and default statements inside switch statements. 1241 1242Given 1243 switch(a) { case 42: break; default: break; } 1244switchCase() 1245 matches 'case 42: break;' and 'default: break;'. 1246</pre></td></tr> 1247 1248 1249<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1SwitchStmt.html">SwitchStmt</a>>...</td></tr> 1250<tr><td colspan="4" class="doc" id="switchStmt0"><pre>Matches switch statements. 1251 1252Given 1253 switch(a) { case 42: break; default: break; } 1254switchStmt() 1255 matches 'switch(a)'. 1256</pre></td></tr> 1257 1258 1259<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html">UnaryExprOrTypeTraitExpr</a>>...</td></tr> 1260<tr><td colspan="4" class="doc" id="unaryExprOrTypeTraitExpr0"><pre>Matches sizeof (C99), alignof (C++11) and vec_step (OpenCL) 1261 1262Given 1263 Foo x = bar; 1264 int y = sizeof(x) + alignof(x); 1265unaryExprOrTypeTraitExpr() 1266 matches sizeof(x) and alignof(x) 1267</pre></td></tr> 1268 1269 1270<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1UnaryOperator.html">UnaryOperator</a>>...</td></tr> 1271<tr><td colspan="4" class="doc" id="unaryOperator0"><pre>Matches unary operator expressions. 1272 1273Example matches !a 1274 !a || b 1275</pre></td></tr> 1276 1277 1278<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedLookupExpr.html">UnresolvedLookupExpr</a>>...</td></tr> 1279<tr><td colspan="4" class="doc" id="unresolvedLookupExpr0"><pre>Matches reference to a name that can be looked up during parsing 1280but could not be resolved to a specific declaration. 1281 1282Given 1283 template<typename T> 1284 T foo() { T a; return a; } 1285 template<typename T> 1286 void bar() { 1287 foo<T>(); 1288 } 1289unresolvedLookupExpr() 1290 matches foo<T>() </pre></td></tr> 1291 1292 1293<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1UserDefinedLiteral.html">UserDefinedLiteral</a>>...</td></tr> 1294<tr><td colspan="4" class="doc" id="userDefinedLiteral0"><pre>Matches user defined literal operator call. 1295 1296Example match: "foo"_suffix 1297</pre></td></tr> 1298 1299 1300<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1WhileStmt.html">WhileStmt</a>>...</td></tr> 1301<tr><td colspan="4" class="doc" id="whileStmt0"><pre>Matches while statements. 1302 1303Given 1304 while (true) {} 1305whileStmt() 1306 matches 'while (true) {}'. 1307</pre></td></tr> 1308 1309 1310<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>>...</td></tr> 1311<tr><td colspan="4" class="doc" id="templateArgument0"><pre>Matches template arguments. 1312 1313Given 1314 template <typename T> struct C {}; 1315 C<int> c; 1316templateArgument() 1317 matches 'int' in C<int>. 1318</pre></td></tr> 1319 1320 1321<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1TemplateName.html">TemplateName</a>>...</td></tr> 1322<tr><td colspan="4" class="doc" id="templateName0"><pre>Matches template name. 1323 1324Given 1325 template <typename T> class X { }; 1326 X<int> xi; 1327templateName() 1328 matches 'X' in X<int>. 1329</pre></td></tr> 1330 1331 1332<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>>...</td></tr> 1333<tr><td colspan="4" class="doc" id="typeLoc0"><pre>Matches TypeLocs in the clang AST. 1334</pre></td></tr> 1335 1336 1337<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1ArrayType.html">ArrayType</a>>...</td></tr> 1338<tr><td colspan="4" class="doc" id="arrayType0"><pre>Matches all kinds of arrays. 1339 1340Given 1341 int a[] = { 2, 3 }; 1342 int b[4]; 1343 void f() { int c[a[0]]; } 1344arrayType() 1345 matches "int a[]", "int b[4]" and "int c[a[0]]"; 1346</pre></td></tr> 1347 1348 1349<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1AtomicType.html">AtomicType</a>>...</td></tr> 1350<tr><td colspan="4" class="doc" id="atomicType0"><pre>Matches atomic types. 1351 1352Given 1353 _Atomic(int) i; 1354atomicType() 1355 matches "_Atomic(int) i" 1356</pre></td></tr> 1357 1358 1359<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1AutoType.html">AutoType</a>>...</td></tr> 1360<tr><td colspan="4" class="doc" id="autoType0"><pre>Matches types nodes representing C++11 auto types. 1361 1362Given: 1363 auto n = 4; 1364 int v[] = { 2, 3 } 1365 for (auto i : v) { } 1366autoType() 1367 matches "auto n" and "auto i" 1368</pre></td></tr> 1369 1370 1371<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1BlockPointerType.html">BlockPointerType</a>>...</td></tr> 1372<tr><td colspan="4" class="doc" id="blockPointerType0"><pre>Matches block pointer types, i.e. types syntactically represented as 1373"void (^)(int)". 1374 1375The pointee is always required to be a FunctionType. 1376</pre></td></tr> 1377 1378 1379<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1BuiltinType.html">BuiltinType</a>>...</td></tr> 1380<tr><td colspan="4" class="doc" id="builtinType0"><pre>Matches builtin Types. 1381 1382Given 1383 struct A {}; 1384 A a; 1385 int b; 1386 float c; 1387 bool d; 1388builtinType() 1389 matches "int b", "float c" and "bool d" 1390</pre></td></tr> 1391 1392 1393<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1ComplexType.html">ComplexType</a>>...</td></tr> 1394<tr><td colspan="4" class="doc" id="complexType0"><pre>Matches C99 complex types. 1395 1396Given 1397 _Complex float f; 1398complexType() 1399 matches "_Complex float f" 1400</pre></td></tr> 1401 1402 1403<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1ConstantArrayType.html">ConstantArrayType</a>>...</td></tr> 1404<tr><td colspan="4" class="doc" id="constantArrayType0"><pre>Matches C arrays with a specified constant size. 1405 1406Given 1407 void() { 1408 int a[2]; 1409 int b[] = { 2, 3 }; 1410 int c[b[0]]; 1411 } 1412constantArrayType() 1413 matches "int a[2]" 1414</pre></td></tr> 1415 1416 1417<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1DecayedType.html">DecayedType</a>>...</td></tr> 1418<tr><td colspan="4" class="doc" id="decayedType0"><pre>Matches decayed type 1419Example matches i[] in declaration of f. 1420 (matcher = valueDecl(hasType(decayedType(hasDecayedType(pointerType()))))) 1421Example matches i[1]. 1422 (matcher = expr(hasType(decayedType(hasDecayedType(pointerType()))))) 1423 void f(int i[]) { 1424 i[1] = 0; 1425 } 1426</pre></td></tr> 1427 1428 1429<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1DependentSizedArrayType.html">DependentSizedArrayType</a>>...</td></tr> 1430<tr><td colspan="4" class="doc" id="dependentSizedArrayType0"><pre>Matches C++ arrays whose size is a value-dependent expression. 1431 1432Given 1433 template<typename T, int Size> 1434 class array { 1435 T data[Size]; 1436 }; 1437dependentSizedArrayType 1438 matches "T data[Size]" 1439</pre></td></tr> 1440 1441 1442<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1ElaboratedType.html">ElaboratedType</a>>...</td></tr> 1443<tr><td colspan="4" class="doc" id="elaboratedType0"><pre>Matches types specified with an elaborated type keyword or with a 1444qualified name. 1445 1446Given 1447 namespace N { 1448 namespace M { 1449 class D {}; 1450 } 1451 } 1452 class C {}; 1453 1454 class C c; 1455 N::M::D d; 1456 1457elaboratedType() matches the type of the variable declarations of both 1458c and d. 1459</pre></td></tr> 1460 1461 1462<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>...</td></tr> 1463<tr><td colspan="4" class="doc" id="enumType0"><pre>Matches enum types. 1464 1465Given 1466 enum C { Green }; 1467 enum class S { Red }; 1468 1469 C c; 1470 S s; 1471 1472enumType() matches the type of the variable declarations of both c and 1473s. 1474</pre></td></tr> 1475 1476 1477<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1FunctionProtoType.html">FunctionProtoType</a>>...</td></tr> 1478<tr><td colspan="4" class="doc" id="functionProtoType0"><pre>Matches FunctionProtoType nodes. 1479 1480Given 1481 int (*f)(int); 1482 void g(); 1483functionProtoType() 1484 matches "int (*f)(int)" and the type of "g" in C++ mode. 1485 In C mode, "g" is not matched because it does not contain a prototype. 1486</pre></td></tr> 1487 1488 1489<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1FunctionType.html">FunctionType</a>>...</td></tr> 1490<tr><td colspan="4" class="doc" id="functionType0"><pre>Matches FunctionType nodes. 1491 1492Given 1493 int (*f)(int); 1494 void g(); 1495functionType() 1496 matches "int (*f)(int)" and the type of "g". 1497</pre></td></tr> 1498 1499 1500<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1IncompleteArrayType.html">IncompleteArrayType</a>>...</td></tr> 1501<tr><td colspan="4" class="doc" id="incompleteArrayType0"><pre>Matches C arrays with unspecified size. 1502 1503Given 1504 int a[] = { 2, 3 }; 1505 int b[42]; 1506 void f(int c[]) { int d[a[0]]; }; 1507incompleteArrayType() 1508 matches "int a[]" and "int c[]" 1509</pre></td></tr> 1510 1511 1512<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>...</td></tr> 1513<tr><td colspan="4" class="doc" id="injectedClassNameType0"><pre>Matches injected class name types. 1514 1515Example matches S s, but not S<T> s. 1516 (matcher = parmVarDecl(hasType(injectedClassNameType()))) 1517 template <typename T> struct S { 1518 void f(S s); 1519 void g(S<T> s); 1520 }; 1521</pre></td></tr> 1522 1523 1524<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1LValueReferenceType.html">LValueReferenceType</a>>...</td></tr> 1525<tr><td colspan="4" class="doc" id="lValueReferenceType0"><pre>Matches lvalue reference types. 1526 1527Given: 1528 int *a; 1529 int &b = *a; 1530 int &&c = 1; 1531 auto &d = b; 1532 auto &&e = c; 1533 auto &&f = 2; 1534 int g = 5; 1535 1536lValueReferenceType() matches the types of b, d, and e. e is 1537matched since the type is deduced as int& by reference collapsing rules. 1538</pre></td></tr> 1539 1540 1541<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1MemberPointerType.html">MemberPointerType</a>>...</td></tr> 1542<tr><td colspan="4" class="doc" id="memberPointerType0"><pre>Matches member pointer types. 1543Given 1544 struct A { int i; } 1545 A::* ptr = A::i; 1546memberPointerType() 1547 matches "A::* ptr" 1548</pre></td></tr> 1549 1550 1551<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1ObjCObjectPointerType.html">ObjCObjectPointerType</a>>...</td></tr> 1552<tr><td colspan="4" class="doc" id="objcObjectPointerType0"><pre>Matches an Objective-C object pointer type, which is different from 1553a pointer type, despite being syntactically similar. 1554 1555Given 1556 int *a; 1557 1558 @interface Foo 1559 @end 1560 Foo *f; 1561pointerType() 1562 matches "Foo *f", but does not match "int *a". 1563</pre></td></tr> 1564 1565 1566<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1ParenType.html">ParenType</a>>...</td></tr> 1567<tr><td colspan="4" class="doc" id="parenType0"><pre>Matches ParenType nodes. 1568 1569Given 1570 int (*ptr_to_array)[4]; 1571 int *array_of_ptrs[4]; 1572 1573varDecl(hasType(pointsTo(parenType()))) matches ptr_to_array but not 1574array_of_ptrs. 1575</pre></td></tr> 1576 1577 1578<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1PointerType.html">PointerType</a>>...</td></tr> 1579<tr><td colspan="4" class="doc" id="pointerType0"><pre>Matches pointer types, but does not match Objective-C object pointer 1580types. 1581 1582Given 1583 int *a; 1584 int &b = *a; 1585 int c = 5; 1586 1587 @interface Foo 1588 @end 1589 Foo *f; 1590pointerType() 1591 matches "int *a", but does not match "Foo *f". 1592</pre></td></tr> 1593 1594 1595<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1RValueReferenceType.html">RValueReferenceType</a>>...</td></tr> 1596<tr><td colspan="4" class="doc" id="rValueReferenceType0"><pre>Matches rvalue reference types. 1597 1598Given: 1599 int *a; 1600 int &b = *a; 1601 int &&c = 1; 1602 auto &d = b; 1603 auto &&e = c; 1604 auto &&f = 2; 1605 int g = 5; 1606 1607rValueReferenceType() matches the types of c and f. e is not 1608matched as it is deduced to int& by reference collapsing rules. 1609</pre></td></tr> 1610 1611 1612<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>...</td></tr> 1613<tr><td colspan="4" class="doc" id="recordType0"><pre>Matches record types (e.g. structs, classes). 1614 1615Given 1616 class C {}; 1617 struct S {}; 1618 1619 C c; 1620 S s; 1621 1622recordType() matches the type of the variable declarations of both c 1623and s. 1624</pre></td></tr> 1625 1626 1627<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1ReferenceType.html">ReferenceType</a>>...</td></tr> 1628<tr><td colspan="4" class="doc" id="referenceType0"><pre>Matches both lvalue and rvalue reference types. 1629 1630Given 1631 int *a; 1632 int &b = *a; 1633 int &&c = 1; 1634 auto &d = b; 1635 auto &&e = c; 1636 auto &&f = 2; 1637 int g = 5; 1638 1639referenceType() matches the types of b, c, d, e, and f. 1640</pre></td></tr> 1641 1642 1643<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1SubstTemplateTypeParmType.html">SubstTemplateTypeParmType</a>>...</td></tr> 1644<tr><td colspan="4" class="doc" id="substTemplateTypeParmType0"><pre>Matches types that represent the result of substituting a type for a 1645template type parameter. 1646 1647Given 1648 template <typename T> 1649 void F(T t) { 1650 int i = 1 + t; 1651 } 1652 1653substTemplateTypeParmType() matches the type of 't' but not '1' 1654</pre></td></tr> 1655 1656 1657<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>...</td></tr> 1658<tr><td colspan="4" class="doc" id="templateSpecializationType0"><pre>Matches template specialization types. 1659 1660Given 1661 template <typename T> 1662 class C { }; 1663 1664 template class C<int>; A 1665 C<char> var; B 1666 1667templateSpecializationType() matches the type of the explicit 1668instantiation in A and the type of the variable declaration in B. 1669</pre></td></tr> 1670 1671 1672<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>...</td></tr> 1673<tr><td colspan="4" class="doc" id="templateTypeParmType0"><pre>Matches template type parameter types. 1674 1675Example matches T, but not int. 1676 (matcher = templateTypeParmType()) 1677 template <typename T> void f(int i); 1678</pre></td></tr> 1679 1680 1681<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>>...</td></tr> 1682<tr><td colspan="4" class="doc" id="type0"><pre>Matches Types in the clang AST. 1683</pre></td></tr> 1684 1685 1686<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>...</td></tr> 1687<tr><td colspan="4" class="doc" id="typedefType0"><pre>Matches typedef types. 1688 1689Given 1690 typedef int X; 1691typedefType() 1692 matches "typedef int X" 1693</pre></td></tr> 1694 1695 1696<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1UnaryTransformType.html">UnaryTransformType</a>>...</td></tr> 1697<tr><td colspan="4" class="doc" id="unaryTransformType0"><pre>Matches types nodes representing unary type transformations. 1698 1699Given: 1700 typedef __underlying_type(T) type; 1701unaryTransformType() 1702 matches "__underlying_type(T)" 1703</pre></td></tr> 1704 1705 1706<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1VariableArrayType.html">VariableArrayType</a>>...</td></tr> 1707<tr><td colspan="4" class="doc" id="variableArrayType0"><pre>Matches C arrays with a specified size that is not an 1708integer-constant-expression. 1709 1710Given 1711 void f() { 1712 int a[] = { 2, 3 } 1713 int b[42]; 1714 int c[a[0]]; 1715 } 1716variableArrayType() 1717 matches "int c[a[0]]" 1718</pre></td></tr> 1719 1720<!--END_DECL_MATCHERS --> 1721</table> 1722 1723<!-- ======================================================================= --> 1724<h2 id="narrowing-matchers">Narrowing Matchers</h2> 1725<!-- ======================================================================= --> 1726 1727<p>Narrowing matchers match certain attributes on the current node, thus 1728narrowing down the set of nodes of the current type to match on.</p> 1729 1730<p>There are special logical narrowing matchers (allOf, anyOf, anything and unless) 1731which allow users to create more powerful match expressions.</p> 1732 1733<table> 1734<tr style="text-align:left"><th>Return type</th><th>Name</th><th>Parameters</th></tr> 1735<!-- START_NARROWING_MATCHERS --> 1736 1737<tr><td>Matcher<*></td><td class="name" onclick="toggle('allOf0')"><a name="allOf0Anchor">allOf</a></td><td>Matcher<*>, ..., Matcher<*></td></tr> 1738<tr><td colspan="4" class="doc" id="allOf0"><pre>Matches if all given matchers match. 1739 1740Usable as: Any Matcher 1741</pre></td></tr> 1742 1743 1744<tr><td>Matcher<*></td><td class="name" onclick="toggle('anyOf0')"><a name="anyOf0Anchor">anyOf</a></td><td>Matcher<*>, ..., Matcher<*></td></tr> 1745<tr><td colspan="4" class="doc" id="anyOf0"><pre>Matches if any of the given matchers matches. 1746 1747Usable as: Any Matcher 1748</pre></td></tr> 1749 1750 1751<tr><td>Matcher<*></td><td class="name" onclick="toggle('anything0')"><a name="anything0Anchor">anything</a></td><td></td></tr> 1752<tr><td colspan="4" class="doc" id="anything0"><pre>Matches any node. 1753 1754Useful when another matcher requires a child matcher, but there's no 1755additional constraint. This will often be used with an explicit conversion 1756to an internal::Matcher<> type such as TypeMatcher. 1757 1758Example: DeclarationMatcher(anything()) matches all declarations, e.g., 1759"int* p" and "void f()" in 1760 int* p; 1761 void f(); 1762 1763Usable as: Any Matcher 1764</pre></td></tr> 1765 1766 1767<tr><td>Matcher<*></td><td class="name" onclick="toggle('unless0')"><a name="unless0Anchor">unless</a></td><td>Matcher<*></td></tr> 1768<tr><td colspan="4" class="doc" id="unless0"><pre>Matches if the provided matcher does not match. 1769 1770Example matches Y (matcher = cxxRecordDecl(unless(hasName("X")))) 1771 class X {}; 1772 class Y {}; 1773 1774Usable as: Any Matcher 1775</pre></td></tr> 1776 1777 1778<tr><td>Matcher<<a href="http://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> 1779<tr><td colspan="4" class="doc" id="hasOperatorName0"><pre>Matches the operator Name of operator expressions (binary or 1780unary). 1781 1782Example matches a || b (matcher = binaryOperator(hasOperatorName("||"))) 1783 !(a || b) 1784</pre></td></tr> 1785 1786 1787<tr><td>Matcher<CXXBoolLiteral></td><td class="name" onclick="toggle('equals2')"><a name="equals2Anchor">equals</a></td><td>ValueT Value</td></tr> 1788<tr><td colspan="4" class="doc" id="equals2"><pre>Matches literals that are equal to the given value. 1789 1790Example matches true (matcher = cxxBoolLiteral(equals(true))) 1791 true 1792 1793Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>>, Matcher<CXXBoolLiteral>, 1794 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>> 1795</pre></td></tr> 1796 1797 1798<tr><td>Matcher<<a href="http://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> 1799<tr><td colspan="4" class="doc" id="isCatchAll0"><pre>Matches a C++ catch statement that has a catch-all handler. 1800 1801Given 1802 try { 1803 ... 1804 } catch (int) { 1805 ... 1806 } catch (...) { 1807 ... 1808 } 1809endcode 1810cxxCatchStmt(isCatchAll()) matches catch(...) but not catch(int). 1811</pre></td></tr> 1812 1813 1814<tr><td>Matcher<<a href="http://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> 1815<tr><td colspan="4" class="doc" id="argumentCountIs1"><pre>Checks that a call expression or a constructor call expression has 1816a specific number of arguments (including absent default arguments). 1817 1818Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2))) 1819 void f(int x, int y); 1820 f(0, 0); 1821</pre></td></tr> 1822 1823 1824<tr><td>Matcher<<a href="http://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> 1825<tr><td colspan="4" class="doc" id="isListInitialization0"><pre>Matches a constructor call expression which uses list initialization. 1826</pre></td></tr> 1827 1828 1829<tr><td>Matcher<<a href="http://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> 1830<tr><td colspan="4" class="doc" id="requiresZeroInitialization0"><pre>Matches a constructor call expression which requires 1831zero initialization. 1832 1833Given 1834void foo() { 1835 struct point { double x; double y; }; 1836 point pt[2] = { { 1.0, 2.0 } }; 1837} 1838initListExpr(has(cxxConstructExpr(requiresZeroInitialization())) 1839will match the implicit array filler for pt[1]. 1840</pre></td></tr> 1841 1842 1843<tr><td>Matcher<<a href="http://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> 1844<tr><td colspan="4" class="doc" id="isCopyConstructor0"><pre>Matches constructor declarations that are copy constructors. 1845 1846Given 1847 struct S { 1848 S(); #1 1849 S(const S &); #2 1850 S(S &&); #3 1851 }; 1852cxxConstructorDecl(isCopyConstructor()) will match #2, but not #1 or #3. 1853</pre></td></tr> 1854 1855 1856<tr><td>Matcher<<a href="http://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> 1857<tr><td colspan="4" class="doc" id="isDefaultConstructor0"><pre>Matches constructor declarations that are default constructors. 1858 1859Given 1860 struct S { 1861 S(); #1 1862 S(const S &); #2 1863 S(S &&); #3 1864 }; 1865cxxConstructorDecl(isDefaultConstructor()) will match #1, but not #2 or #3. 1866</pre></td></tr> 1867 1868 1869<tr><td>Matcher<<a href="http://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> 1870<tr><td colspan="4" class="doc" id="isDelegatingConstructor0"><pre>Matches constructors that delegate to another constructor. 1871 1872Given 1873 struct S { 1874 S(); #1 1875 S(int) {} #2 1876 S(S &&) : S() {} #3 1877 }; 1878 S::S() : S(0) {} #4 1879cxxConstructorDecl(isDelegatingConstructor()) will match #3 and #4, but not 1880#1 or #2. 1881</pre></td></tr> 1882 1883 1884<tr><td>Matcher<<a href="http://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> 1885<tr><td colspan="4" class="doc" id="isExplicit0"><pre>Matches constructor and conversion declarations that are marked with 1886the explicit keyword. 1887 1888Given 1889 struct S { 1890 S(int); #1 1891 explicit S(double); #2 1892 operator int(); #3 1893 explicit operator bool(); #4 1894 }; 1895cxxConstructorDecl(isExplicit()) will match #2, but not #1. 1896cxxConversionDecl(isExplicit()) will match #4, but not #3. 1897</pre></td></tr> 1898 1899 1900<tr><td>Matcher<<a href="http://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> 1901<tr><td colspan="4" class="doc" id="isMoveConstructor0"><pre>Matches constructor declarations that are move constructors. 1902 1903Given 1904 struct S { 1905 S(); #1 1906 S(const S &); #2 1907 S(S &&); #3 1908 }; 1909cxxConstructorDecl(isMoveConstructor()) will match #3, but not #1 or #2. 1910</pre></td></tr> 1911 1912 1913<tr><td>Matcher<<a href="http://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> 1914<tr><td colspan="4" class="doc" id="isExplicit1"><pre>Matches constructor and conversion declarations that are marked with 1915the explicit keyword. 1916 1917Given 1918 struct S { 1919 S(int); #1 1920 explicit S(double); #2 1921 operator int(); #3 1922 explicit operator bool(); #4 1923 }; 1924cxxConstructorDecl(isExplicit()) will match #2, but not #1. 1925cxxConversionDecl(isExplicit()) will match #4, but not #3. 1926</pre></td></tr> 1927 1928 1929<tr><td>Matcher<<a href="http://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> 1930<tr><td colspan="4" class="doc" id="isBaseInitializer0"><pre>Matches a constructor initializer if it is initializing a base, as 1931opposed to a member. 1932 1933Given 1934 struct B {}; 1935 struct D : B { 1936 int I; 1937 D(int i) : I(i) {} 1938 }; 1939 struct E : B { 1940 E() : B() {} 1941 }; 1942cxxConstructorDecl(hasAnyConstructorInitializer(isBaseInitializer())) 1943 will match E(), but not match D(int). 1944</pre></td></tr> 1945 1946 1947<tr><td>Matcher<<a href="http://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> 1948<tr><td colspan="4" class="doc" id="isMemberInitializer0"><pre>Matches a constructor initializer if it is initializing a member, as 1949opposed to a base. 1950 1951Given 1952 struct B {}; 1953 struct D : B { 1954 int I; 1955 D(int i) : I(i) {} 1956 }; 1957 struct E : B { 1958 E() : B() {} 1959 }; 1960cxxConstructorDecl(hasAnyConstructorInitializer(isMemberInitializer())) 1961 will match D(int), but not match E(). 1962</pre></td></tr> 1963 1964 1965<tr><td>Matcher<<a href="http://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> 1966<tr><td colspan="4" class="doc" id="isWritten0"><pre>Matches a constructor initializer if it is explicitly written in 1967code (as opposed to implicitly added by the compiler). 1968 1969Given 1970 struct Foo { 1971 Foo() { } 1972 Foo(int) : foo_("A") { } 1973 string foo_; 1974 }; 1975cxxConstructorDecl(hasAnyConstructorInitializer(isWritten())) 1976 will match Foo(int), but not Foo() 1977</pre></td></tr> 1978 1979 1980<tr><td>Matcher<<a href="http://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> 1981<tr><td colspan="4" class="doc" id="isConst0"><pre>Matches if the given method declaration is const. 1982 1983Given 1984struct A { 1985 void foo() const; 1986 void bar(); 1987}; 1988 1989cxxMethodDecl(isConst()) matches A::foo() but not A::bar() 1990</pre></td></tr> 1991 1992 1993<tr><td>Matcher<<a href="http://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> 1994<tr><td colspan="4" class="doc" id="isCopyAssignmentOperator0"><pre>Matches if the given method declaration declares a copy assignment 1995operator. 1996 1997Given 1998struct A { 1999 A &operator=(const A &); 2000 A &operator=(A &&); 2001}; 2002 2003cxxMethodDecl(isCopyAssignmentOperator()) matches the first method but not 2004the second one. 2005</pre></td></tr> 2006 2007 2008<tr><td>Matcher<<a href="http://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> 2009<tr><td colspan="4" class="doc" id="isFinal1"><pre>Matches if the given method or class declaration is final. 2010 2011Given: 2012 class A final {}; 2013 2014 struct B { 2015 virtual void f(); 2016 }; 2017 2018 struct C : B { 2019 void f() final; 2020 }; 2021matches A and C::f, but not B, C, or B::f 2022</pre></td></tr> 2023 2024 2025<tr><td>Matcher<<a href="http://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> 2026<tr><td colspan="4" class="doc" id="isMoveAssignmentOperator0"><pre>Matches if the given method declaration declares a move assignment 2027operator. 2028 2029Given 2030struct A { 2031 A &operator=(const A &); 2032 A &operator=(A &&); 2033}; 2034 2035cxxMethodDecl(isMoveAssignmentOperator()) matches the second method but not 2036the first one. 2037</pre></td></tr> 2038 2039 2040<tr><td>Matcher<<a href="http://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> 2041<tr><td colspan="4" class="doc" id="isOverride0"><pre>Matches if the given method declaration overrides another method. 2042 2043Given 2044 class A { 2045 public: 2046 virtual void x(); 2047 }; 2048 class B : public A { 2049 public: 2050 virtual void x(); 2051 }; 2052 matches B::x 2053</pre></td></tr> 2054 2055 2056<tr><td>Matcher<<a href="http://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> 2057<tr><td colspan="4" class="doc" id="isPure0"><pre>Matches if the given method declaration is pure. 2058 2059Given 2060 class A { 2061 public: 2062 virtual void x() = 0; 2063 }; 2064 matches A::x 2065</pre></td></tr> 2066 2067 2068<tr><td>Matcher<<a href="http://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> 2069<tr><td colspan="4" class="doc" id="isUserProvided0"><pre>Matches method declarations that are user-provided. 2070 2071Given 2072 struct S { 2073 S(); #1 2074 S(const S &) = default; #2 2075 S(S &&) = delete; #3 2076 }; 2077cxxConstructorDecl(isUserProvided()) will match #1, but not #2 or #3. 2078</pre></td></tr> 2079 2080 2081<tr><td>Matcher<<a href="http://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> 2082<tr><td colspan="4" class="doc" id="isVirtual0"><pre>Matches if the given method declaration is virtual. 2083 2084Given 2085 class A { 2086 public: 2087 virtual void x(); 2088 }; 2089 matches A::x 2090</pre></td></tr> 2091 2092 2093<tr><td>Matcher<<a href="http://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> 2094<tr><td colspan="4" class="doc" id="isVirtualAsWritten0"><pre>Matches if the given method declaration has an explicit "virtual". 2095 2096Given 2097 class A { 2098 public: 2099 virtual void x(); 2100 }; 2101 class B : public A { 2102 public: 2103 void x(); 2104 }; 2105 matches A::x but not B::x 2106</pre></td></tr> 2107 2108 2109<tr><td>Matcher<<a href="http://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> 2110<tr><td colspan="4" class="doc" id="hasOverloadedOperatorName1"><pre>Matches overloaded operator names. 2111 2112Matches overloaded operator names specified in strings without the 2113"operator" prefix: e.g. "<<". 2114 2115Given: 2116 class A { int operator*(); }; 2117 const A &operator<<(const A &a, const A &b); 2118 A a; 2119 a << a; <-- This matches 2120 2121cxxOperatorCallExpr(hasOverloadedOperatorName("<<"))) matches the 2122specified line and 2123cxxRecordDecl(hasMethod(hasOverloadedOperatorName("*"))) 2124matches the declaration of A. 2125 2126Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>> 2127</pre></td></tr> 2128 2129 2130<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isDerivedFrom1')"><a name="isDerivedFrom1Anchor">isDerivedFrom</a></td><td>std::string BaseName</td></tr> 2131<tr><td colspan="4" class="doc" id="isDerivedFrom1"><pre>Overloaded method as shortcut for isDerivedFrom(hasName(...)). 2132</pre></td></tr> 2133 2134 2135<tr><td>Matcher<<a href="http://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> 2136<tr><td colspan="4" class="doc" id="isExplicitTemplateSpecialization2"><pre>Matches explicit template specializations of function, class, or 2137static member variable template instantiations. 2138 2139Given 2140 template<typename T> void A(T t) { } 2141 template<> void A(int N) { } 2142functionDecl(isExplicitTemplateSpecialization()) 2143 matches the specialization A<int>(). 2144 2145Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>> 2146</pre></td></tr> 2147 2148 2149<tr><td>Matcher<<a href="http://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> 2150<tr><td colspan="4" class="doc" id="isFinal0"><pre>Matches if the given method or class declaration is final. 2151 2152Given: 2153 class A final {}; 2154 2155 struct B { 2156 virtual void f(); 2157 }; 2158 2159 struct C : B { 2160 void f() final; 2161 }; 2162matches A and C::f, but not B, C, or B::f 2163</pre></td></tr> 2164 2165 2166<tr><td>Matcher<<a href="http://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> 2167<tr><td colspan="4" class="doc" id="isLambda0"><pre>Matches the generated class of lambda expressions. 2168 2169Given: 2170 auto x = []{}; 2171 2172cxxRecordDecl(isLambda()) matches the implicit class declaration of 2173decltype(x) 2174</pre></td></tr> 2175 2176 2177<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isSameOrDerivedFrom1')"><a name="isSameOrDerivedFrom1Anchor">isSameOrDerivedFrom</a></td><td>std::string BaseName</td></tr> 2178<tr><td colspan="4" class="doc" id="isSameOrDerivedFrom1"><pre>Overloaded method as shortcut for 2179isSameOrDerivedFrom(hasName(...)). 2180</pre></td></tr> 2181 2182 2183<tr><td>Matcher<<a href="http://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> 2184<tr><td colspan="4" class="doc" id="isTemplateInstantiation2"><pre>Matches template instantiations of function, class, or static 2185member variable template instantiations. 2186 2187Given 2188 template <typename T> class X {}; class A {}; X<A> x; 2189or 2190 template <typename T> class X {}; class A {}; template class X<A>; 2191cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) 2192 matches the template instantiation of X<A>. 2193 2194But given 2195 template <typename T> class X {}; class A {}; 2196 template <> class X<A> {}; X<A> x; 2197cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) 2198 does not match, as X<A> is an explicit template specialization. 2199 2200Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>> 2201</pre></td></tr> 2202 2203 2204<tr><td>Matcher<<a href="http://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> 2205<tr><td colspan="4" class="doc" id="argumentCountIs0"><pre>Checks that a call expression or a constructor call expression has 2206a specific number of arguments (including absent default arguments). 2207 2208Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2))) 2209 void f(int x, int y); 2210 f(0, 0); 2211</pre></td></tr> 2212 2213 2214<tr><td>Matcher<<a href="http://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> 2215<tr><td colspan="4" class="doc" id="hasCastKind0"><pre>Matches casts that has a given cast kind. 2216 2217Example: matches the implicit cast around 0 2218(matcher = castExpr(hasCastKind(CK_NullToPointer))) 2219 int *p = 0; 2220</pre></td></tr> 2221 2222 2223<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>></td><td class="name" onclick="toggle('equals3')"><a name="equals3Anchor">equals</a></td><td>ValueT Value</td></tr> 2224<tr><td colspan="4" class="doc" id="equals3"><pre>Matches literals that are equal to the given value. 2225 2226Example matches true (matcher = cxxBoolLiteral(equals(true))) 2227 true 2228 2229Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>>, Matcher<CXXBoolLiteral>, 2230 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>> 2231</pre></td></tr> 2232 2233 2234<tr><td>Matcher<<a href="http://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> 2235<tr><td colspan="4" class="doc" id="templateArgumentCountIs0"><pre>Matches if the number of template arguments equals N. 2236 2237Given 2238 template<typename T> struct C {}; 2239 C<int> c; 2240classTemplateSpecializationDecl(templateArgumentCountIs(1)) 2241 matches C<int>. 2242</pre></td></tr> 2243 2244 2245<tr><td>Matcher<<a href="http://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> 2246<tr><td colspan="4" class="doc" id="statementCountIs0"><pre>Checks that a compound statement contains a specific number of 2247child statements. 2248 2249Example: Given 2250 { for (;;) {} } 2251compoundStmt(statementCountIs(0))) 2252 matches '{}' 2253 but does not match the outer compound statement. 2254</pre></td></tr> 2255 2256 2257<tr><td>Matcher<<a href="http://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> 2258<tr><td colspan="4" class="doc" id="hasSize0"><pre>Matches nodes that have the specified size. 2259 2260Given 2261 int a[42]; 2262 int b[2 * 21]; 2263 int c[41], d[43]; 2264 char *s = "abcd"; 2265 wchar_t *ws = L"abcd"; 2266 char *w = "a"; 2267constantArrayType(hasSize(42)) 2268 matches "int a[42]" and "int b[2 * 21]" 2269stringLiteral(hasSize(4)) 2270 matches "abcd", L"abcd" 2271</pre></td></tr> 2272 2273 2274<tr><td>Matcher<<a href="http://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> 2275<tr><td colspan="4" class="doc" id="declCountIs0"><pre>Matches declaration statements that contain a specific number of 2276declarations. 2277 2278Example: Given 2279 int a, b; 2280 int c; 2281 int d = 2, e; 2282declCountIs(2) 2283 matches 'int a, b;' and 'int d = 2, e;', but not 'int c;'. 2284</pre></td></tr> 2285 2286 2287<tr><td>Matcher<<a href="http://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> 2288<tr><td colspan="4" class="doc" id="equalsBoundNode1"><pre>Matches if a node equals a previously bound node. 2289 2290Matches a node if it equals the node previously bound to ID. 2291 2292Given 2293 class X { int a; int b; }; 2294cxxRecordDecl( 2295 has(fieldDecl(hasName("a"), hasType(type().bind("t")))), 2296 has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t")))))) 2297 matches the class X, as a and b have the same type. 2298 2299Note that when multiple matches are involved via forEach* matchers, 2300equalsBoundNodes acts as a filter. 2301For example: 2302compoundStmt( 2303 forEachDescendant(varDecl().bind("d")), 2304 forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d")))))) 2305will trigger a match for each combination of variable declaration 2306and reference to that variable declaration within a compound statement. 2307</pre></td></tr> 2308 2309 2310<tr><td>Matcher<<a href="http://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> 2311<tr><td colspan="4" class="doc" id="equalsNode0"><pre>Matches if a node equals another node. 2312 2313Decl has pointer identity in the AST. 2314</pre></td></tr> 2315 2316 2317<tr><td>Matcher<<a href="http://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> 2318<tr><td colspan="4" class="doc" id="hasAttr0"><pre>Matches declaration that has a given attribute. 2319 2320Given 2321 __attribute__((device)) void f() { ... } 2322decl(hasAttr(clang::attr::CUDADevice)) matches the function declaration of 2323f. If the matcher is use from clang-query, attr::Kind parameter should be 2324passed as a quoted string. e.g., hasAttr("attr::CUDADevice"). 2325</pre></td></tr> 2326 2327 2328<tr><td>Matcher<<a href="http://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> 2329<tr><td colspan="4" class="doc" id="isExpansionInFileMatching0"><pre>Matches AST nodes that were expanded within files whose name is 2330partially matching a given regex. 2331 2332Example matches Y but not X 2333 (matcher = cxxRecordDecl(isExpansionInFileMatching("AST.*")) 2334 #include "ASTMatcher.h" 2335 class X {}; 2336ASTMatcher.h: 2337 class Y {}; 2338 2339Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> 2340</pre></td></tr> 2341 2342 2343<tr><td>Matcher<<a href="http://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> 2344<tr><td colspan="4" class="doc" id="isExpansionInMainFile0"><pre>Matches AST nodes that were expanded within the main-file. 2345 2346Example matches X but not Y 2347 (matcher = cxxRecordDecl(isExpansionInMainFile()) 2348 #include <Y.h> 2349 class X {}; 2350Y.h: 2351 class Y {}; 2352 2353Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> 2354</pre></td></tr> 2355 2356 2357<tr><td>Matcher<<a href="http://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> 2358<tr><td colspan="4" class="doc" id="isExpansionInSystemHeader0"><pre>Matches AST nodes that were expanded within system-header-files. 2359 2360Example matches Y but not X 2361 (matcher = cxxRecordDecl(isExpansionInSystemHeader()) 2362 #include <SystemHeader.h> 2363 class X {}; 2364SystemHeader.h: 2365 class Y {}; 2366 2367Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> 2368</pre></td></tr> 2369 2370 2371<tr><td>Matcher<<a href="http://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> 2372<tr><td colspan="4" class="doc" id="isImplicit0"><pre>Matches a declaration that has been implicitly added 2373by the compiler (eg. implicit defaultcopy constructors). 2374</pre></td></tr> 2375 2376 2377<tr><td>Matcher<<a href="http://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> 2378<tr><td colspan="4" class="doc" id="isPrivate0"><pre>Matches private C++ declarations. 2379 2380Given 2381 class C { 2382 public: int a; 2383 protected: int b; 2384 private: int c; 2385 }; 2386fieldDecl(isPrivate()) 2387 matches 'int c;' 2388</pre></td></tr> 2389 2390 2391<tr><td>Matcher<<a href="http://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> 2392<tr><td colspan="4" class="doc" id="isProtected0"><pre>Matches protected C++ declarations. 2393 2394Given 2395 class C { 2396 public: int a; 2397 protected: int b; 2398 private: int c; 2399 }; 2400fieldDecl(isProtected()) 2401 matches 'int b;' 2402</pre></td></tr> 2403 2404 2405<tr><td>Matcher<<a href="http://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> 2406<tr><td colspan="4" class="doc" id="isPublic0"><pre>Matches public C++ declarations. 2407 2408Given 2409 class C { 2410 public: int a; 2411 protected: int b; 2412 private: int c; 2413 }; 2414fieldDecl(isPublic()) 2415 matches 'int a;' 2416</pre></td></tr> 2417 2418 2419<tr><td>Matcher<<a href="http://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> 2420<tr><td colspan="4" class="doc" id="designatorCountIs0"><pre>Matches designated initializer expressions that contain 2421a specific number of designators. 2422 2423Example: Given 2424 point ptarray[10] = { [2].y = 1.0, [0].x = 1.0 }; 2425 point ptarray2[10] = { [2].y = 1.0, [2].x = 0.0, [0].x = 1.0 }; 2426designatorCountIs(2) 2427 matches '{ [2].y = 1.0, [0].x = 1.0 }', 2428 but not '{ [2].y = 1.0, [2].x = 0.0, [0].x = 1.0 }'. 2429</pre></td></tr> 2430 2431 2432<tr><td>Matcher<<a href="http://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> 2433<tr><td colspan="4" class="doc" id="hasBitWidth0"><pre>Matches non-static data members that are bit-fields. 2434 2435Given 2436 class C { 2437 int a : 2; 2438 int b : 4; 2439 int c : 2; 2440 }; 2441fieldDecl(isBitField()) 2442 matches 'int a;' and 'int c;' but not 'int b;'. 2443</pre></td></tr> 2444 2445 2446<tr><td>Matcher<<a href="http://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> 2447<tr><td colspan="4" class="doc" id="isBitField0"><pre>Matches non-static data members that are bit-fields. 2448 2449Given 2450 class C { 2451 int a : 2; 2452 int b; 2453 }; 2454fieldDecl(isBitField()) 2455 matches 'int a;' but not 'int b;'. 2456</pre></td></tr> 2457 2458 2459<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>></td><td class="name" onclick="toggle('equals1')"><a name="equals1Anchor">equals</a></td><td>ValueT Value</td></tr> 2460<tr><td colspan="4" class="doc" id="equals1"><pre>Matches literals that are equal to the given value. 2461 2462Example matches true (matcher = cxxBoolLiteral(equals(true))) 2463 true 2464 2465Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>>, Matcher<CXXBoolLiteral>, 2466 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>> 2467</pre></td></tr> 2468 2469 2470<tr><td>Matcher<<a href="http://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> 2471<tr><td colspan="4" class="doc" id="hasDynamicExceptionSpec0"><pre>Matches functions that have a dynamic exception specification. 2472 2473Given: 2474 void f(); 2475 void g() noexcept; 2476 void h() noexcept(true); 2477 void i() noexcept(false); 2478 void j() throw(); 2479 void k() throw(int); 2480 void l() throw(...); 2481functionDecl(hasDynamicExceptionSpec()) and 2482 functionProtoType(hasDynamicExceptionSpec()) 2483 match the declarations of j, k, and l, but not f, g, h, or i. 2484</pre></td></tr> 2485 2486 2487<tr><td>Matcher<<a href="http://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> 2488<tr><td colspan="4" class="doc" id="hasOverloadedOperatorName0"><pre>Matches overloaded operator names. 2489 2490Matches overloaded operator names specified in strings without the 2491"operator" prefix: e.g. "<<". 2492 2493Given: 2494 class A { int operator*(); }; 2495 const A &operator<<(const A &a, const A &b); 2496 A a; 2497 a << a; <-- This matches 2498 2499cxxOperatorCallExpr(hasOverloadedOperatorName("<<"))) matches the 2500specified line and 2501cxxRecordDecl(hasMethod(hasOverloadedOperatorName("*"))) 2502matches the declaration of A. 2503 2504Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>> 2505</pre></td></tr> 2506 2507 2508<tr><td>Matcher<<a href="http://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> 2509<tr><td colspan="4" class="doc" id="isConstexpr1"><pre>Matches constexpr variable and function declarations. 2510 2511Given: 2512 constexpr int foo = 42; 2513 constexpr int bar(); 2514varDecl(isConstexpr()) 2515 matches the declaration of foo. 2516functionDecl(isConstexpr()) 2517 matches the declaration of bar. 2518</pre></td></tr> 2519 2520 2521<tr><td>Matcher<<a href="http://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> 2522<tr><td colspan="4" class="doc" id="isDefaulted0"><pre>Matches defaulted function declarations. 2523 2524Given: 2525 class A { ~A(); }; 2526 class B { ~B() = default; }; 2527functionDecl(isDefaulted()) 2528 matches the declaration of ~B, but not ~A. 2529</pre></td></tr> 2530 2531 2532<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isDefinition2')"><a name="isDefinition2Anchor">isDefinition</a></td><td></td></tr> 2533<tr><td colspan="4" class="doc" id="isDefinition2"><pre>Matches if a declaration has a body attached. 2534 2535Example matches A, va, fa 2536 class A {}; 2537 class B; Doesn't match, as it has no body. 2538 int va; 2539 extern int vb; Doesn't match, as it doesn't define the variable. 2540 void fa() {} 2541 void fb(); Doesn't match, as it has no body. 2542 2543Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagDecl.html">TagDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>> 2544</pre></td></tr> 2545 2546 2547<tr><td>Matcher<<a href="http://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> 2548<tr><td colspan="4" class="doc" id="isDeleted0"><pre>Matches deleted function declarations. 2549 2550Given: 2551 void Func(); 2552 void DeletedFunc() = delete; 2553functionDecl(isDeleted()) 2554 matches the declaration of DeletedFunc, but not Func. 2555</pre></td></tr> 2556 2557 2558<tr><td>Matcher<<a href="http://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> 2559<tr><td colspan="4" class="doc" id="isExplicitTemplateSpecialization0"><pre>Matches explicit template specializations of function, class, or 2560static member variable template instantiations. 2561 2562Given 2563 template<typename T> void A(T t) { } 2564 template<> void A(int N) { } 2565functionDecl(isExplicitTemplateSpecialization()) 2566 matches the specialization A<int>(). 2567 2568Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>> 2569</pre></td></tr> 2570 2571 2572<tr><td>Matcher<<a href="http://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> 2573<tr><td colspan="4" class="doc" id="isExternC0"><pre>Matches extern "C" function declarations. 2574 2575Given: 2576 extern "C" void f() {} 2577 extern "C" { void g() {} } 2578 void h() {} 2579functionDecl(isExternC()) 2580 matches the declaration of f and g, but not the declaration h 2581</pre></td></tr> 2582 2583 2584<tr><td>Matcher<<a href="http://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> 2585<tr><td colspan="4" class="doc" id="isInline1"><pre>Matches function and namespace declarations that are marked with 2586the inline keyword. 2587 2588Given 2589 inline void f(); 2590 void g(); 2591 namespace n { 2592 inline namespace m {} 2593 } 2594functionDecl(isInline()) will match ::f(). 2595namespaceDecl(isInline()) will match n::m. 2596</pre></td></tr> 2597 2598 2599<tr><td>Matcher<<a href="http://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> 2600<tr><td colspan="4" class="doc" id="isNoThrow0"><pre>Matches functions that have a non-throwing exception specification. 2601 2602Given: 2603 void f(); 2604 void g() noexcept; 2605 void h() throw(); 2606 void i() throw(int); 2607 void j() noexcept(false); 2608functionDecl(isNoThrow()) and functionProtoType(isNoThrow()) 2609 match the declarations of g, and h, but not f, i or j. 2610</pre></td></tr> 2611 2612 2613<tr><td>Matcher<<a href="http://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> 2614<tr><td colspan="4" class="doc" id="isTemplateInstantiation0"><pre>Matches template instantiations of function, class, or static 2615member variable template instantiations. 2616 2617Given 2618 template <typename T> class X {}; class A {}; X<A> x; 2619or 2620 template <typename T> class X {}; class A {}; template class X<A>; 2621cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) 2622 matches the template instantiation of X<A>. 2623 2624But given 2625 template <typename T> class X {}; class A {}; 2626 template <> class X<A> {}; X<A> x; 2627cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) 2628 does not match, as X<A> is an explicit template specialization. 2629 2630Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>> 2631</pre></td></tr> 2632 2633 2634<tr><td>Matcher<<a href="http://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> 2635<tr><td colspan="4" class="doc" id="isVariadic0"><pre>Matches if a function declaration is variadic. 2636 2637Example matches f, but not g or h. The function i will not match, even when 2638compiled in C mode. 2639 void f(...); 2640 void g(int); 2641 template <typename... Ts> void h(Ts...); 2642 void i(); 2643</pre></td></tr> 2644 2645 2646<tr><td>Matcher<<a href="http://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> 2647<tr><td colspan="4" class="doc" id="parameterCountIs0"><pre>Matches FunctionDecls and FunctionProtoTypes that have a 2648specific parameter count. 2649 2650Given 2651 void f(int i) {} 2652 void g(int i, int j) {} 2653 void h(int i, int j); 2654 void j(int i); 2655 void k(int x, int y, int z, ...); 2656functionDecl(parameterCountIs(2)) 2657 matches void g(int i, int j) {} 2658functionProtoType(parameterCountIs(2)) 2659 matches void h(int i, int j) 2660functionProtoType(parameterCountIs(3)) 2661 matches void k(int x, int y, int z, ...); 2662</pre></td></tr> 2663 2664 2665<tr><td>Matcher<<a href="http://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> 2666<tr><td colspan="4" class="doc" id="hasDynamicExceptionSpec1"><pre>Matches functions that have a dynamic exception specification. 2667 2668Given: 2669 void f(); 2670 void g() noexcept; 2671 void h() noexcept(true); 2672 void i() noexcept(false); 2673 void j() throw(); 2674 void k() throw(int); 2675 void l() throw(...); 2676functionDecl(hasDynamicExceptionSpec()) and 2677 functionProtoType(hasDynamicExceptionSpec()) 2678 match the declarations of j, k, and l, but not f, g, h, or i. 2679</pre></td></tr> 2680 2681 2682<tr><td>Matcher<<a href="http://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> 2683<tr><td colspan="4" class="doc" id="isNoThrow1"><pre>Matches functions that have a non-throwing exception specification. 2684 2685Given: 2686 void f(); 2687 void g() noexcept; 2688 void h() throw(); 2689 void i() throw(int); 2690 void j() noexcept(false); 2691functionDecl(isNoThrow()) and functionProtoType(isNoThrow()) 2692 match the declarations of g, and h, but not f, i or j. 2693</pre></td></tr> 2694 2695 2696<tr><td>Matcher<<a href="http://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> 2697<tr><td colspan="4" class="doc" id="parameterCountIs1"><pre>Matches FunctionDecls and FunctionProtoTypes that have a 2698specific parameter count. 2699 2700Given 2701 void f(int i) {} 2702 void g(int i, int j) {} 2703 void h(int i, int j); 2704 void j(int i); 2705 void k(int x, int y, int z, ...); 2706functionDecl(parameterCountIs(2)) 2707 matches void g(int i, int j) {} 2708functionProtoType(parameterCountIs(2)) 2709 matches void h(int i, int j) 2710functionProtoType(parameterCountIs(3)) 2711 matches void k(int x, int y, int z, ...); 2712</pre></td></tr> 2713 2714 2715<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>></td><td class="name" onclick="toggle('equals0')"><a name="equals0Anchor">equals</a></td><td>ValueT Value</td></tr> 2716<tr><td colspan="4" class="doc" id="equals0"><pre>Matches literals that are equal to the given value. 2717 2718Example matches true (matcher = cxxBoolLiteral(equals(true))) 2719 true 2720 2721Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CharacterLiteral.html">CharacterLiteral</a>>, Matcher<CXXBoolLiteral>, 2722 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>> 2723</pre></td></tr> 2724 2725 2726<tr><td>Matcher<<a href="http://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> 2727<tr><td colspan="4" class="doc" id="isArrow0"><pre>Matches member expressions that are called with '->' as opposed 2728to '.'. 2729 2730Member calls on the implicit this pointer match as called with '->'. 2731 2732Given 2733 class Y { 2734 void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; } 2735 int a; 2736 static int b; 2737 }; 2738memberExpr(isArrow()) 2739 matches this->x, x, y.x, a, this->b 2740</pre></td></tr> 2741 2742 2743<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>></td><td class="name" onclick="toggle('hasName0')"><a name="hasName0Anchor">hasName</a></td><td>std::string Name</td></tr> 2744<tr><td colspan="4" class="doc" id="hasName0"><pre>Matches NamedDecl nodes that have the specified name. 2745 2746Supports specifying enclosing namespaces or classes by prefixing the name 2747with '<enclosing>::'. 2748Does not match typedefs of an underlying type with the given name. 2749 2750Example matches X (Name == "X") 2751 class X; 2752 2753Example matches X (Name is one of "::a::b::X", "a::b::X", "b::X", "X") 2754 namespace a { namespace b { class X; } } 2755</pre></td></tr> 2756 2757 2758<tr><td>Matcher<<a href="http://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> 2759<tr><td colspan="4" class="doc" id="matchesName0"><pre>Matches NamedDecl nodes whose fully qualified names contain 2760a substring matched by the given RegExp. 2761 2762Supports specifying enclosing namespaces or classes by 2763prefixing the name with '<enclosing>::'. Does not match typedefs 2764of an underlying type with the given name. 2765 2766Example matches X (regexp == "::X") 2767 class X; 2768 2769Example matches X (regexp is one of "::X", "^foo::.*X", among others) 2770 namespace foo { namespace bar { class X; } } 2771</pre></td></tr> 2772 2773 2774<tr><td>Matcher<<a href="http://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> 2775<tr><td colspan="4" class="doc" id="isAnonymous0"><pre>Matches anonymous namespace declarations. 2776 2777Given 2778 namespace n { 2779 namespace {} #1 2780 } 2781namespaceDecl(isAnonymous()) will match #1 but not ::n. 2782</pre></td></tr> 2783 2784 2785<tr><td>Matcher<<a href="http://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> 2786<tr><td colspan="4" class="doc" id="isInline0"><pre>Matches function and namespace declarations that are marked with 2787the inline keyword. 2788 2789Given 2790 inline void f(); 2791 void g(); 2792 namespace n { 2793 inline namespace m {} 2794 } 2795functionDecl(isInline()) will match ::f(). 2796namespaceDecl(isInline()) will match n::m. 2797</pre></td></tr> 2798 2799 2800<tr><td>Matcher<<a href="http://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> 2801<tr><td colspan="4" class="doc" id="argumentCountIs2"><pre>Checks that a call expression or a constructor call expression has 2802a specific number of arguments (including absent default arguments). 2803 2804Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2))) 2805 void f(int x, int y); 2806 f(0, 0); 2807</pre></td></tr> 2808 2809 2810<tr><td>Matcher<<a href="http://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> 2811<tr><td colspan="4" class="doc" id="hasKeywordSelector0"><pre>Matches when the selector is a keyword selector 2812 2813objCMessageExpr(hasKeywordSelector()) matches the generated setFrame 2814message expression in 2815 2816 UIWebView *webView = ...; 2817 CGRect bodyFrame = webView.frame; 2818 bodyFrame.size.height = self.bodyContentHeight; 2819 webView.frame = bodyFrame; 2820 ^---- matches here 2821</pre></td></tr> 2822 2823 2824<tr><td>Matcher<<a href="http://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> 2825<tr><td colspan="4" class="doc" id="hasNullSelector0"><pre>Matches when the selector is the empty selector 2826 2827Matches only when the selector of the objCMessageExpr is NULL. This may 2828represent an error condition in the tree! 2829</pre></td></tr> 2830 2831 2832<tr><td>Matcher<<a href="http://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> 2833<tr><td colspan="4" class="doc" id="hasSelector0"><pre>Matches when BaseName == Selector.getAsString() 2834 2835 matcher = objCMessageExpr(hasSelector("loadHTMLString:baseURL:")); 2836 matches the outer message expr in the code below, but NOT the message 2837 invocation for self.bodyView. 2838 [self.bodyView loadHTMLString:html baseURL:NULL]; 2839</pre></td></tr> 2840 2841 2842<tr><td>Matcher<<a href="http://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> 2843<tr><td colspan="4" class="doc" id="hasUnarySelector0"><pre>Matches when the selector is a Unary Selector 2844 2845 matcher = objCMessageExpr(matchesSelector(hasUnarySelector()); 2846 matches self.bodyView in the code below, but NOT the outer message 2847 invocation of "loadHTMLString:baseURL:". 2848 [self.bodyView loadHTMLString:html baseURL:NULL]; 2849</pre></td></tr> 2850 2851 2852<tr><td>Matcher<<a href="http://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> 2853<tr><td colspan="4" class="doc" id="matchesSelector0"><pre>Matches ObjC selectors whose name contains 2854a substring matched by the given RegExp. 2855 matcher = objCMessageExpr(matchesSelector("loadHTMLStringmatches the outer message expr in the code below, but NOT the message 2856 invocation for self.bodyView. 2857 [self.bodyView loadHTMLString:html baseURL:NULL]; 2858</pre></td></tr> 2859 2860 2861<tr><td>Matcher<<a href="http://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> 2862<tr><td colspan="4" class="doc" id="numSelectorArgs0"><pre>Matches when the selector has the specified number of arguments 2863 2864 matcher = objCMessageExpr(numSelectorArgs(0)); 2865 matches self.bodyView in the code below 2866 2867 matcher = objCMessageExpr(numSelectorArgs(2)); 2868 matches the invocation of "loadHTMLString:baseURL:" but not that 2869 of self.bodyView 2870 [self.bodyView loadHTMLString:html baseURL:NULL]; 2871</pre></td></tr> 2872 2873 2874<tr><td>Matcher<<a href="http://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> 2875<tr><td colspan="4" class="doc" id="asString0"><pre>Matches if the matched type is represented by the given string. 2876 2877Given 2878 class Y { public: void x(); }; 2879 void z() { Y* y; y->x(); } 2880cxxMemberCallExpr(on(hasType(asString("class Y *")))) 2881 matches y->x() 2882</pre></td></tr> 2883 2884 2885<tr><td>Matcher<<a href="http://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> 2886<tr><td colspan="4" class="doc" id="equalsBoundNode3"><pre>Matches if a node equals a previously bound node. 2887 2888Matches a node if it equals the node previously bound to ID. 2889 2890Given 2891 class X { int a; int b; }; 2892cxxRecordDecl( 2893 has(fieldDecl(hasName("a"), hasType(type().bind("t")))), 2894 has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t")))))) 2895 matches the class X, as a and b have the same type. 2896 2897Note that when multiple matches are involved via forEach* matchers, 2898equalsBoundNodes acts as a filter. 2899For example: 2900compoundStmt( 2901 forEachDescendant(varDecl().bind("d")), 2902 forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d")))))) 2903will trigger a match for each combination of variable declaration 2904and reference to that variable declaration within a compound statement. 2905</pre></td></tr> 2906 2907 2908<tr><td>Matcher<<a href="http://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> 2909<tr><td colspan="4" class="doc" id="hasLocalQualifiers0"><pre>Matches QualType nodes that have local CV-qualifiers attached to 2910the node, not hidden within a typedef. 2911 2912Given 2913 typedef const int const_int; 2914 const_int i; 2915 int *const j; 2916 int *volatile k; 2917 int m; 2918varDecl(hasType(hasLocalQualifiers())) matches only j and k. 2919i is const-qualified but the qualifier is not local. 2920</pre></td></tr> 2921 2922 2923<tr><td>Matcher<<a href="http://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> 2924<tr><td colspan="4" class="doc" id="isAnyCharacter0"><pre>Matches QualType nodes that are of character type. 2925 2926Given 2927 void a(char); 2928 void b(wchar_t); 2929 void c(double); 2930functionDecl(hasAnyParameter(hasType(isAnyCharacter()))) 2931matches "a(char)", "b(wchar_t)", but not "c(double)". 2932</pre></td></tr> 2933 2934 2935<tr><td>Matcher<<a href="http://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> 2936<tr><td colspan="4" class="doc" id="isAnyPointer0"><pre>Matches QualType nodes that are of any pointer type; this includes 2937the Objective-C object pointer type, which is different despite being 2938syntactically similar. 2939 2940Given 2941 int *i = nullptr; 2942 2943 @interface Foo 2944 @end 2945 Foo *f; 2946 2947 int j; 2948varDecl(hasType(isAnyPointer())) 2949 matches "int *i" and "Foo *f", but not "int j". 2950</pre></td></tr> 2951 2952 2953<tr><td>Matcher<<a href="http://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> 2954<tr><td colspan="4" class="doc" id="isConstQualified0"><pre>Matches QualType nodes that are const-qualified, i.e., that 2955include "top-level" const. 2956 2957Given 2958 void a(int); 2959 void b(int const); 2960 void c(const int); 2961 void d(const int*); 2962 void e(int const) {}; 2963functionDecl(hasAnyParameter(hasType(isConstQualified()))) 2964 matches "void b(int const)", "void c(const int)" and 2965 "void e(int const) {}". It does not match d as there 2966 is no top-level const on the parameter type "const int *". 2967</pre></td></tr> 2968 2969 2970<tr><td>Matcher<<a href="http://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> 2971<tr><td colspan="4" class="doc" id="isInteger0"><pre>Matches QualType nodes that are of integer type. 2972 2973Given 2974 void a(int); 2975 void b(long); 2976 void c(double); 2977functionDecl(hasAnyParameter(hasType(isInteger()))) 2978matches "a(int)", "b(long)", but not "c(double)". 2979</pre></td></tr> 2980 2981 2982<tr><td>Matcher<<a href="http://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> 2983<tr><td colspan="4" class="doc" id="isSignedInteger0"><pre>Matches QualType nodes that are of signed integer type. 2984 2985Given 2986 void a(int); 2987 void b(unsigned long); 2988 void c(double); 2989functionDecl(hasAnyParameter(hasType(isInteger()))) 2990matches "a(int)", but not "b(unsigned long)" and "c(double)". 2991</pre></td></tr> 2992 2993 2994<tr><td>Matcher<<a href="http://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> 2995<tr><td colspan="4" class="doc" id="isUnsignedInteger0"><pre>Matches QualType nodes that are of unsigned integer type. 2996 2997Given 2998 void a(int); 2999 void b(unsigned long); 3000 void c(double); 3001functionDecl(hasAnyParameter(hasType(isInteger()))) 3002matches "b(unsigned long)", but not "a(int)" and "c(double)". 3003</pre></td></tr> 3004 3005 3006<tr><td>Matcher<<a href="http://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> 3007<tr><td colspan="4" class="doc" id="isVolatileQualified0"><pre>Matches QualType nodes that are volatile-qualified, i.e., that 3008include "top-level" volatile. 3009 3010Given 3011 void a(int); 3012 void b(int volatile); 3013 void c(volatile int); 3014 void d(volatile int*); 3015 void e(int volatile) {}; 3016functionDecl(hasAnyParameter(hasType(isVolatileQualified()))) 3017 matches "void b(int volatile)", "void c(volatile int)" and 3018 "void e(int volatile) {}". It does not match d as there 3019 is no top-level volatile on the parameter type "volatile int *". 3020</pre></td></tr> 3021 3022 3023<tr><td>Matcher<<a href="http://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> 3024<tr><td colspan="4" class="doc" id="isClass0"><pre>Matches RecordDecl object that are spelled with "class." 3025 3026Example matches C, but not S or U. 3027 struct S {}; 3028 class C {}; 3029 union U {}; 3030</pre></td></tr> 3031 3032 3033<tr><td>Matcher<<a href="http://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> 3034<tr><td colspan="4" class="doc" id="isStruct0"><pre>Matches RecordDecl object that are spelled with "struct." 3035 3036Example matches S, but not C or U. 3037 struct S {}; 3038 class C {}; 3039 union U {}; 3040</pre></td></tr> 3041 3042 3043<tr><td>Matcher<<a href="http://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> 3044<tr><td colspan="4" class="doc" id="isUnion0"><pre>Matches RecordDecl object that are spelled with "union." 3045 3046Example matches U, but not C or S. 3047 struct S {}; 3048 class C {}; 3049 union U {}; 3050</pre></td></tr> 3051 3052 3053<tr><td>Matcher<<a href="http://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> 3054<tr><td colspan="4" class="doc" id="equalsBoundNode0"><pre>Matches if a node equals a previously bound node. 3055 3056Matches a node if it equals the node previously bound to ID. 3057 3058Given 3059 class X { int a; int b; }; 3060cxxRecordDecl( 3061 has(fieldDecl(hasName("a"), hasType(type().bind("t")))), 3062 has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t")))))) 3063 matches the class X, as a and b have the same type. 3064 3065Note that when multiple matches are involved via forEach* matchers, 3066equalsBoundNodes acts as a filter. 3067For example: 3068compoundStmt( 3069 forEachDescendant(varDecl().bind("d")), 3070 forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d")))))) 3071will trigger a match for each combination of variable declaration 3072and reference to that variable declaration within a compound statement. 3073</pre></td></tr> 3074 3075 3076<tr><td>Matcher<<a href="http://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> 3077<tr><td colspan="4" class="doc" id="equalsNode1"><pre>Matches if a node equals another node. 3078 3079Stmt has pointer identity in the AST. 3080</pre></td></tr> 3081 3082 3083<tr><td>Matcher<<a href="http://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> 3084<tr><td colspan="4" class="doc" id="isExpansionInFileMatching1"><pre>Matches AST nodes that were expanded within files whose name is 3085partially matching a given regex. 3086 3087Example matches Y but not X 3088 (matcher = cxxRecordDecl(isExpansionInFileMatching("AST.*")) 3089 #include "ASTMatcher.h" 3090 class X {}; 3091ASTMatcher.h: 3092 class Y {}; 3093 3094Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> 3095</pre></td></tr> 3096 3097 3098<tr><td>Matcher<<a href="http://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> 3099<tr><td colspan="4" class="doc" id="isExpansionInMainFile1"><pre>Matches AST nodes that were expanded within the main-file. 3100 3101Example matches X but not Y 3102 (matcher = cxxRecordDecl(isExpansionInMainFile()) 3103 #include <Y.h> 3104 class X {}; 3105Y.h: 3106 class Y {}; 3107 3108Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> 3109</pre></td></tr> 3110 3111 3112<tr><td>Matcher<<a href="http://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> 3113<tr><td colspan="4" class="doc" id="isExpansionInSystemHeader1"><pre>Matches AST nodes that were expanded within system-header-files. 3114 3115Example matches Y but not X 3116 (matcher = cxxRecordDecl(isExpansionInSystemHeader()) 3117 #include <SystemHeader.h> 3118 class X {}; 3119SystemHeader.h: 3120 class Y {}; 3121 3122Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> 3123</pre></td></tr> 3124 3125 3126<tr><td>Matcher<<a href="http://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> 3127<tr><td colspan="4" class="doc" id="hasSize1"><pre>Matches nodes that have the specified size. 3128 3129Given 3130 int a[42]; 3131 int b[2 * 21]; 3132 int c[41], d[43]; 3133 char *s = "abcd"; 3134 wchar_t *ws = L"abcd"; 3135 char *w = "a"; 3136constantArrayType(hasSize(42)) 3137 matches "int a[42]" and "int b[2 * 21]" 3138stringLiteral(hasSize(4)) 3139 matches "abcd", L"abcd" 3140</pre></td></tr> 3141 3142 3143<tr><td>Matcher<<a href="http://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> 3144<tr><td colspan="4" class="doc" id="isDefinition0"><pre>Matches if a declaration has a body attached. 3145 3146Example matches A, va, fa 3147 class A {}; 3148 class B; Doesn't match, as it has no body. 3149 int va; 3150 extern int vb; Doesn't match, as it doesn't define the variable. 3151 void fa() {} 3152 void fb(); Doesn't match, as it has no body. 3153 3154Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagDecl.html">TagDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>> 3155</pre></td></tr> 3156 3157 3158<tr><td>Matcher<<a href="http://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> 3159<tr><td colspan="4" class="doc" id="equalsIntegralValue0"><pre>Matches a TemplateArgument of integral type with a given value. 3160 3161Note that 'Value' is a string as the template argument's value is 3162an arbitrary precision integer. 'Value' must be euqal to the canonical 3163representation of that integral value in base 10. 3164 3165Given 3166 template<int T> struct A {}; 3167 C<42> c; 3168classTemplateSpecializationDecl( 3169 hasAnyTemplateArgument(equalsIntegralValue("42"))) 3170 matches the implicit instantiation of C in C<42>. 3171</pre></td></tr> 3172 3173 3174<tr><td>Matcher<<a href="http://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> 3175<tr><td colspan="4" class="doc" id="isIntegral0"><pre>Matches a TemplateArgument that is an integral value. 3176 3177Given 3178 template<int T> struct A {}; 3179 C<42> c; 3180classTemplateSpecializationDecl( 3181 hasAnyTemplateArgument(isIntegral())) 3182 matches the implicit instantiation of C in C<42> 3183 with isIntegral() matching 42. 3184</pre></td></tr> 3185 3186 3187<tr><td>Matcher<<a href="http://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> 3188<tr><td colspan="4" class="doc" id="templateArgumentCountIs1"><pre>Matches if the number of template arguments equals N. 3189 3190Given 3191 template<typename T> struct C {}; 3192 C<int> c; 3193classTemplateSpecializationDecl(templateArgumentCountIs(1)) 3194 matches C<int>. 3195</pre></td></tr> 3196 3197 3198<tr><td>Matcher<<a href="http://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> 3199<tr><td colspan="4" class="doc" id="isExpansionInFileMatching2"><pre>Matches AST nodes that were expanded within files whose name is 3200partially matching a given regex. 3201 3202Example matches Y but not X 3203 (matcher = cxxRecordDecl(isExpansionInFileMatching("AST.*")) 3204 #include "ASTMatcher.h" 3205 class X {}; 3206ASTMatcher.h: 3207 class Y {}; 3208 3209Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> 3210</pre></td></tr> 3211 3212 3213<tr><td>Matcher<<a href="http://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> 3214<tr><td colspan="4" class="doc" id="isExpansionInMainFile2"><pre>Matches AST nodes that were expanded within the main-file. 3215 3216Example matches X but not Y 3217 (matcher = cxxRecordDecl(isExpansionInMainFile()) 3218 #include <Y.h> 3219 class X {}; 3220Y.h: 3221 class Y {}; 3222 3223Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> 3224</pre></td></tr> 3225 3226 3227<tr><td>Matcher<<a href="http://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> 3228<tr><td colspan="4" class="doc" id="isExpansionInSystemHeader2"><pre>Matches AST nodes that were expanded within system-header-files. 3229 3230Example matches Y but not X 3231 (matcher = cxxRecordDecl(isExpansionInSystemHeader()) 3232 #include <SystemHeader.h> 3233 class X {}; 3234SystemHeader.h: 3235 class Y {}; 3236 3237Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> 3238</pre></td></tr> 3239 3240 3241<tr><td>Matcher<<a href="http://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> 3242<tr><td colspan="4" class="doc" id="booleanType0"><pre>Matches type bool. 3243 3244Given 3245 struct S { bool func(); }; 3246functionDecl(returns(booleanType())) 3247 matches "bool func();" 3248</pre></td></tr> 3249 3250 3251<tr><td>Matcher<<a href="http://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> 3252<tr><td colspan="4" class="doc" id="equalsBoundNode2"><pre>Matches if a node equals a previously bound node. 3253 3254Matches a node if it equals the node previously bound to ID. 3255 3256Given 3257 class X { int a; int b; }; 3258cxxRecordDecl( 3259 has(fieldDecl(hasName("a"), hasType(type().bind("t")))), 3260 has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t")))))) 3261 matches the class X, as a and b have the same type. 3262 3263Note that when multiple matches are involved via forEach* matchers, 3264equalsBoundNodes acts as a filter. 3265For example: 3266compoundStmt( 3267 forEachDescendant(varDecl().bind("d")), 3268 forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d")))))) 3269will trigger a match for each combination of variable declaration 3270and reference to that variable declaration within a compound statement. 3271</pre></td></tr> 3272 3273 3274<tr><td>Matcher<<a href="http://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> 3275<tr><td colspan="4" class="doc" id="equalsNode2"><pre>Matches if a node equals another node. 3276 3277Type has pointer identity in the AST. 3278</pre></td></tr> 3279 3280 3281<tr><td>Matcher<<a href="http://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> 3282<tr><td colspan="4" class="doc" id="realFloatingPointType0"><pre>Matches any real floating-point type (float, double, long double). 3283 3284Given 3285 int i; 3286 float f; 3287realFloatingPointType() 3288 matches "float f" but not "int i" 3289</pre></td></tr> 3290 3291 3292<tr><td>Matcher<<a href="http://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> 3293<tr><td colspan="4" class="doc" id="voidType0"><pre>Matches type void. 3294 3295Given 3296 struct S { void func(); }; 3297functionDecl(returns(voidType())) 3298 matches "void func();" 3299</pre></td></tr> 3300 3301 3302<tr><td>Matcher<<a href="http://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> 3303<tr><td colspan="4" class="doc" id="ofKind0"><pre>Matches unary expressions of a certain kind. 3304 3305Given 3306 int x; 3307 int s = sizeof(x) + alignof(x) 3308unaryExprOrTypeTraitExpr(ofKind(UETT_SizeOf)) 3309 matches sizeof(x) 3310</pre></td></tr> 3311 3312 3313<tr><td>Matcher<<a href="http://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> 3314<tr><td colspan="4" class="doc" id="hasOperatorName1"><pre>Matches the operator Name of operator expressions (binary or 3315unary). 3316 3317Example matches a || b (matcher = binaryOperator(hasOperatorName("||"))) 3318 !(a || b) 3319</pre></td></tr> 3320 3321 3322<tr><td>Matcher<<a href="http://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> 3323<tr><td colspan="4" class="doc" id="hasAutomaticStorageDuration0"><pre>Matches a variable declaration that has automatic storage duration. 3324 3325Example matches x, but not y, z, or a. 3326(matcher = varDecl(hasAutomaticStorageDuration()) 3327void f() { 3328 int x; 3329 static int y; 3330 thread_local int z; 3331} 3332int a; 3333</pre></td></tr> 3334 3335 3336<tr><td>Matcher<<a href="http://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> 3337<tr><td colspan="4" class="doc" id="hasGlobalStorage0"><pre>Matches a variable declaration that does not have local storage. 3338 3339Example matches y and z (matcher = varDecl(hasGlobalStorage()) 3340void f() { 3341 int x; 3342 static int y; 3343} 3344int z; 3345</pre></td></tr> 3346 3347 3348<tr><td>Matcher<<a href="http://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> 3349<tr><td colspan="4" class="doc" id="hasLocalStorage0"><pre>Matches a variable declaration that has function scope and is a 3350non-static local variable. 3351 3352Example matches x (matcher = varDecl(hasLocalStorage()) 3353void f() { 3354 int x; 3355 static int y; 3356} 3357int z; 3358</pre></td></tr> 3359 3360 3361<tr><td>Matcher<<a href="http://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> 3362<tr><td colspan="4" class="doc" id="hasStaticStorageDuration0"><pre>Matches a variable declaration that has static storage duration. 3363 3364Example matches y and a, but not x or z. 3365(matcher = varDecl(hasStaticStorageDuration()) 3366void f() { 3367 int x; 3368 static int y; 3369 thread_local int z; 3370} 3371int a; 3372</pre></td></tr> 3373 3374 3375<tr><td>Matcher<<a href="http://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> 3376<tr><td colspan="4" class="doc" id="hasThreadStorageDuration0"><pre>Matches a variable declaration that has thread storage duration. 3377 3378Example matches z, but not x, z, or a. 3379(matcher = varDecl(hasThreadStorageDuration()) 3380void f() { 3381 int x; 3382 static int y; 3383 thread_local int z; 3384} 3385int a; 3386</pre></td></tr> 3387 3388 3389<tr><td>Matcher<<a href="http://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> 3390<tr><td colspan="4" class="doc" id="isConstexpr0"><pre>Matches constexpr variable and function declarations. 3391 3392Given: 3393 constexpr int foo = 42; 3394 constexpr int bar(); 3395varDecl(isConstexpr()) 3396 matches the declaration of foo. 3397functionDecl(isConstexpr()) 3398 matches the declaration of bar. 3399</pre></td></tr> 3400 3401 3402<tr><td>Matcher<<a href="http://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> 3403<tr><td colspan="4" class="doc" id="isDefinition1"><pre>Matches if a declaration has a body attached. 3404 3405Example matches A, va, fa 3406 class A {}; 3407 class B; Doesn't match, as it has no body. 3408 int va; 3409 extern int vb; Doesn't match, as it doesn't define the variable. 3410 void fa() {} 3411 void fb(); Doesn't match, as it has no body. 3412 3413Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagDecl.html">TagDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>> 3414</pre></td></tr> 3415 3416 3417<tr><td>Matcher<<a href="http://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> 3418<tr><td colspan="4" class="doc" id="isExceptionVariable0"><pre>Matches a variable declaration that is an exception variable from 3419a C++ catch block, or an Objective-C statement. 3420 3421Example matches x (matcher = varDecl(isExceptionVariable()) 3422void f(int y) { 3423 try { 3424 } catch (int x) { 3425 } 3426} 3427</pre></td></tr> 3428 3429 3430<tr><td>Matcher<<a href="http://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> 3431<tr><td colspan="4" class="doc" id="isExplicitTemplateSpecialization1"><pre>Matches explicit template specializations of function, class, or 3432static member variable template instantiations. 3433 3434Given 3435 template<typename T> void A(T t) { } 3436 template<> void A(int N) { } 3437functionDecl(isExplicitTemplateSpecialization()) 3438 matches the specialization A<int>(). 3439 3440Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>> 3441</pre></td></tr> 3442 3443 3444<tr><td>Matcher<<a href="http://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> 3445<tr><td colspan="4" class="doc" id="isExternC1"><pre>Matches extern "C" function declarations. 3446 3447Given: 3448 extern "C" void f() {} 3449 extern "C" { void g() {} } 3450 void h() {} 3451functionDecl(isExternC()) 3452 matches the declaration of f and g, but not the declaration h 3453</pre></td></tr> 3454 3455 3456<tr><td>Matcher<<a href="http://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> 3457<tr><td colspan="4" class="doc" id="isTemplateInstantiation1"><pre>Matches template instantiations of function, class, or static 3458member variable template instantiations. 3459 3460Given 3461 template <typename T> class X {}; class A {}; X<A> x; 3462or 3463 template <typename T> class X {}; class A {}; template class X<A>; 3464cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) 3465 matches the template instantiation of X<A>. 3466 3467But given 3468 template <typename T> class X {}; class A {}; 3469 template <> class X<A> {}; X<A> x; 3470cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) 3471 does not match, as X<A> is an explicit template specialization. 3472 3473Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>> 3474</pre></td></tr> 3475 3476 3477<tr><td>Matcher<internal::Matcher<<a href="http://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> 3478<tr><td colspan="4" class="doc" id="isInstantiated0"><pre>Matches declarations that are template instantiations or are inside 3479template instantiations. 3480 3481Given 3482 template<typename T> void A(T t) { T i; } 3483 A(0); 3484 A(0U); 3485functionDecl(isInstantiated()) 3486 matches 'A(int) {...};' and 'A(unsigned) {...}'. 3487</pre></td></tr> 3488 3489 3490<tr><td>Matcher<internal::Matcher<<a href="http://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> 3491<tr><td colspan="4" class="doc" id="nullPointerConstant0"><pre>Matches expressions that resolve to a null pointer constant, such as 3492GNU's __null, C++11's nullptr, or C's NULL macro. 3493 3494Given: 3495 void *v1 = NULL; 3496 void *v2 = nullptr; 3497 void *v3 = __null; GNU extension 3498 char *cp = (char *)0; 3499 int *ip = 0; 3500 int i = 0; 3501expr(nullPointerConstant()) 3502 matches the initializer for v1, v2, v3, cp, and ip. Does not match the 3503 initializer for i. 3504</pre></td></tr> 3505 3506 3507<tr><td>Matcher<internal::Matcher<<a href="http://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> 3508<tr><td colspan="4" class="doc" id="hasAnyName0"><pre>Matches NamedDecl nodes that have any of the specified names. 3509 3510This matcher is only provided as a performance optimization of hasName. 3511 hasAnyName(a, b, c) 3512 is equivalent to, but faster than 3513 anyOf(hasName(a), hasName(b), hasName(c)) 3514</pre></td></tr> 3515 3516 3517<tr><td>Matcher<internal::Matcher<<a href="http://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> 3518<tr><td colspan="4" class="doc" id="isInTemplateInstantiation0"><pre>Matches statements inside of a template instantiation. 3519 3520Given 3521 int j; 3522 template<typename T> void A(T t) { T i; j += 42;} 3523 A(0); 3524 A(0U); 3525declStmt(isInTemplateInstantiation()) 3526 matches 'int i;' and 'unsigned i'. 3527unless(stmt(isInTemplateInstantiation())) 3528 will NOT match j += 42; as it's shared between the template definition and 3529 instantiation. 3530</pre></td></tr> 3531 3532<!--END_NARROWING_MATCHERS --> 3533</table> 3534 3535<!-- ======================================================================= --> 3536<h2 id="traversal-matchers">AST Traversal Matchers</h2> 3537<!-- ======================================================================= --> 3538 3539<p>Traversal matchers specify the relationship to other nodes that are 3540reachable from the current node.</p> 3541 3542<p>Note that there are special traversal matchers (has, hasDescendant, forEach and 3543forEachDescendant) which work on all nodes and allow users to write more generic 3544match expressions.</p> 3545 3546<table> 3547<tr style="text-align:left"><th>Return type</th><th>Name</th><th>Parameters</th></tr> 3548<!-- START_TRAVERSAL_MATCHERS --> 3549 3550<tr><td>Matcher<*></td><td class="name" onclick="toggle('eachOf0')"><a name="eachOf0Anchor">eachOf</a></td><td>Matcher<*>, ..., Matcher<*></td></tr> 3551<tr><td colspan="4" class="doc" id="eachOf0"><pre>Matches if any of the given matchers matches. 3552 3553Unlike anyOf, eachOf will generate a match result for each 3554matching submatcher. 3555 3556For example, in: 3557 class A { int a; int b; }; 3558The matcher: 3559 cxxRecordDecl(eachOf(has(fieldDecl(hasName("a")).bind("v")), 3560 has(fieldDecl(hasName("b")).bind("v")))) 3561will generate two results binding "v", the first of which binds 3562the field declaration of a, the second the field declaration of 3563b. 3564 3565Usable as: Any Matcher 3566</pre></td></tr> 3567 3568 3569<tr><td>Matcher<*></td><td class="name" onclick="toggle('forEachDescendant0')"><a name="forEachDescendant0Anchor">forEachDescendant</a></td><td>Matcher<*></td></tr> 3570<tr><td colspan="4" class="doc" id="forEachDescendant0"><pre>Matches AST nodes that have descendant AST nodes that match the 3571provided matcher. 3572 3573Example matches X, A, B, C 3574 (matcher = cxxRecordDecl(forEachDescendant(cxxRecordDecl(hasName("X"))))) 3575 class X {}; Matches X, because X::X is a class of name X inside X. 3576 class A { class X {}; }; 3577 class B { class C { class X {}; }; }; 3578 3579DescendantT must be an AST base type. 3580 3581As opposed to 'hasDescendant', 'forEachDescendant' will cause a match for 3582each result that matches instead of only on the first one. 3583 3584Note: Recursively combined ForEachDescendant can cause many matches: 3585 cxxRecordDecl(forEachDescendant(cxxRecordDecl( 3586 forEachDescendant(cxxRecordDecl()) 3587 ))) 3588will match 10 times (plus injected class name matches) on: 3589 class A { class B { class C { class D { class E {}; }; }; }; }; 3590 3591Usable as: Any Matcher 3592</pre></td></tr> 3593 3594 3595<tr><td>Matcher<*></td><td class="name" onclick="toggle('forEach0')"><a name="forEach0Anchor">forEach</a></td><td>Matcher<*></td></tr> 3596<tr><td colspan="4" class="doc" id="forEach0"><pre>Matches AST nodes that have child AST nodes that match the 3597provided matcher. 3598 3599Example matches X, Y 3600 (matcher = cxxRecordDecl(forEach(cxxRecordDecl(hasName("X"))) 3601 class X {}; Matches X, because X::X is a class of name X inside X. 3602 class Y { class X {}; }; 3603 class Z { class Y { class X {}; }; }; Does not match Z. 3604 3605ChildT must be an AST base type. 3606 3607As opposed to 'has', 'forEach' will cause a match for each result that 3608matches instead of only on the first one. 3609 3610Usable as: Any Matcher 3611</pre></td></tr> 3612 3613 3614<tr><td>Matcher<*></td><td class="name" onclick="toggle('hasAncestor0')"><a name="hasAncestor0Anchor">hasAncestor</a></td><td>Matcher<*></td></tr> 3615<tr><td colspan="4" class="doc" id="hasAncestor0"><pre>Matches AST nodes that have an ancestor that matches the provided 3616matcher. 3617 3618Given 3619void f() { if (true) { int x = 42; } } 3620void g() { for (;;) { int x = 43; } } 3621expr(integerLiteral(hasAncestor(ifStmt()))) matches 42, but not 43. 3622 3623Usable as: Any Matcher 3624</pre></td></tr> 3625 3626 3627<tr><td>Matcher<*></td><td class="name" onclick="toggle('hasDescendant0')"><a name="hasDescendant0Anchor">hasDescendant</a></td><td>Matcher<*></td></tr> 3628<tr><td colspan="4" class="doc" id="hasDescendant0"><pre>Matches AST nodes that have descendant AST nodes that match the 3629provided matcher. 3630 3631Example matches X, Y, Z 3632 (matcher = cxxRecordDecl(hasDescendant(cxxRecordDecl(hasName("X"))))) 3633 class X {}; Matches X, because X::X is a class of name X inside X. 3634 class Y { class X {}; }; 3635 class Z { class Y { class X {}; }; }; 3636 3637DescendantT must be an AST base type. 3638 3639Usable as: Any Matcher 3640</pre></td></tr> 3641 3642 3643<tr><td>Matcher<*></td><td class="name" onclick="toggle('has0')"><a name="has0Anchor">has</a></td><td>Matcher<*></td></tr> 3644<tr><td colspan="4" class="doc" id="has0"><pre>Matches AST nodes that have child AST nodes that match the 3645provided matcher. 3646 3647Example matches X, Y 3648 (matcher = cxxRecordDecl(has(cxxRecordDecl(hasName("X"))) 3649 class X {}; Matches X, because X::X is a class of name X inside X. 3650 class Y { class X {}; }; 3651 class Z { class Y { class X {}; }; }; Does not match Z. 3652 3653ChildT must be an AST base type. 3654 3655Usable as: Any Matcher 3656Note that has is direct matcher, so it also matches things like implicit 3657casts and paren casts. If you are matching with expr then you should 3658probably consider using ignoringParenImpCasts like: 3659has(ignoringParenImpCasts(expr())). 3660</pre></td></tr> 3661 3662 3663<tr><td>Matcher<*></td><td class="name" onclick="toggle('hasParent0')"><a name="hasParent0Anchor">hasParent</a></td><td>Matcher<*></td></tr> 3664<tr><td colspan="4" class="doc" id="hasParent0"><pre>Matches AST nodes that have a parent that matches the provided 3665matcher. 3666 3667Given 3668void f() { for (;;) { int x = 42; if (true) { int x = 43; } } } 3669compoundStmt(hasParent(ifStmt())) matches "{ int x = 43; }". 3670 3671Usable as: Any Matcher 3672</pre></td></tr> 3673 3674 3675<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 3676<tr><td colspan="4" class="doc" id="hasCondition5"><pre>Matches the condition expression of an if statement, for loop, 3677switch statement or conditional operator. 3678 3679Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true)))) 3680 if (true) {} 3681</pre></td></tr> 3682 3683 3684<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 3685<tr><td colspan="4" class="doc" id="hasFalseExpression0"><pre>Matches the false branch expression of a conditional operator 3686(binary or ternary). 3687 3688Example matches b 3689 condition ? a : b 3690 condition ?: b 3691</pre></td></tr> 3692 3693 3694<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 3695<tr><td colspan="4" class="doc" id="hasTrueExpression0"><pre>Matches the true branch expression of a conditional operator. 3696 3697Example 1 (conditional ternary operator): matches a 3698 condition ? a : b 3699 3700Example 2 (conditional binary operator): matches opaqueValueExpr(condition) 3701 condition ?: b 3702</pre></td></tr> 3703 3704 3705<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>></td><td class="name" onclick="toggle('hasDeclaration8')"><a name="hasDeclaration8Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 3706<tr><td colspan="4" class="doc" id="hasDeclaration8"><pre>Matches a node if the declaration associated with that node 3707matches the given matcher. 3708 3709The associated declaration is: 3710- for type nodes, the declaration of the underlying type 3711- for CallExpr, the declaration of the callee 3712- for MemberExpr, the declaration of the referenced member 3713- for CXXConstructExpr, the declaration of the constructor 3714 3715Also usable as Matcher<T> for any T supporting the getDecl() member 3716function. e.g. various subtypes of clang::Type and various expressions. 3717 3718Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 3719 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 3720 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, 3721 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 3722 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 3723 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 3724</pre></td></tr> 3725 3726 3727<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 3728<tr><td colspan="4" class="doc" id="hasBase0"><pre>Matches the base expression of an array subscript expression. 3729 3730Given 3731 int i[5]; 3732 void f() { i[1] = 42; } 3733arraySubscriptExpression(hasBase(implicitCastExpr( 3734 hasSourceExpression(declRefExpr())))) 3735 matches i[1] with the declRefExpr() matching i 3736</pre></td></tr> 3737 3738 3739<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 3740<tr><td colspan="4" class="doc" id="hasIndex0"><pre>Matches the index expression of an array subscript expression. 3741 3742Given 3743 int i[5]; 3744 void f() { i[1] = 42; } 3745arraySubscriptExpression(hasIndex(integerLiteral())) 3746 matches i[1] with the integerLiteral() matching 1 3747</pre></td></tr> 3748 3749 3750<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 3751<tr><td colspan="4" class="doc" id="hasLHS1"><pre>Matches the left hand side of binary operator expressions. 3752 3753Example matches a (matcher = binaryOperator(hasLHS())) 3754 a || b 3755</pre></td></tr> 3756 3757 3758<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 3759<tr><td colspan="4" class="doc" id="hasRHS1"><pre>Matches the right hand side of binary operator expressions. 3760 3761Example matches b (matcher = binaryOperator(hasRHS())) 3762 a || b 3763</pre></td></tr> 3764 3765 3766<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ArrayTypeLoc.html">ArrayTypeLoc</a>></td><td class="name" onclick="toggle('hasElementTypeLoc0')"><a name="hasElementTypeLoc0Anchor">hasElementTypeLoc</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td></tr> 3767<tr><td colspan="4" class="doc" id="hasElementTypeLoc0"><pre>Matches arrays and C99 complex types that have a specific element 3768type. 3769 3770Given 3771 struct A {}; 3772 A a[7]; 3773 int b[7]; 3774arrayType(hasElementType(builtinType())) 3775 matches "int b[7]" 3776 3777Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ArrayType.html">ArrayType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ComplexType.html">ComplexType</a>> 3778</pre></td></tr> 3779 3780 3781<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr> 3782<tr><td colspan="4" class="doc" id="hasElementType0"><pre>Matches arrays and C99 complex types that have a specific element 3783type. 3784 3785Given 3786 struct A {}; 3787 A a[7]; 3788 int b[7]; 3789arrayType(hasElementType(builtinType())) 3790 matches "int b[7]" 3791 3792Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ArrayType.html">ArrayType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ComplexType.html">ComplexType</a>> 3793</pre></td></tr> 3794 3795 3796<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AtomicTypeLoc.html">AtomicTypeLoc</a>></td><td class="name" onclick="toggle('hasValueTypeLoc0')"><a name="hasValueTypeLoc0Anchor">hasValueTypeLoc</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td></tr> 3797<tr><td colspan="4" class="doc" id="hasValueTypeLoc0"><pre>Matches atomic types with a specific value type. 3798 3799Given 3800 _Atomic(int) i; 3801 _Atomic(float) f; 3802atomicType(hasValueType(isInteger())) 3803 matches "_Atomic(int) i" 3804 3805Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AtomicType.html">AtomicType</a>> 3806</pre></td></tr> 3807 3808 3809<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr> 3810<tr><td colspan="4" class="doc" id="hasValueType0"><pre>Matches atomic types with a specific value type. 3811 3812Given 3813 _Atomic(int) i; 3814 _Atomic(float) f; 3815atomicType(hasValueType(isInteger())) 3816 matches "_Atomic(int) i" 3817 3818Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AtomicType.html">AtomicType</a>> 3819</pre></td></tr> 3820 3821 3822<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr> 3823<tr><td colspan="4" class="doc" id="hasDeducedType0"><pre>Matches AutoType nodes where the deduced type is a specific type. 3824 3825Note: There is no TypeLoc for the deduced type and thus no 3826getDeducedLoc() matcher. 3827 3828Given 3829 auto a = 1; 3830 auto b = 2.0; 3831autoType(hasDeducedType(isInteger())) 3832 matches "auto a" 3833 3834Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AutoType.html">AutoType</a>> 3835</pre></td></tr> 3836 3837 3838<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html">BinaryOperator</a>></td><td class="name" onclick="toggle('hasEitherOperand0')"><a name="hasEitherOperand0Anchor">hasEitherOperand</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 3839<tr><td colspan="4" class="doc" id="hasEitherOperand0"><pre>Matches if either the left hand side or the right hand side of a 3840binary operator matches. 3841</pre></td></tr> 3842 3843 3844<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 3845<tr><td colspan="4" class="doc" id="hasLHS0"><pre>Matches the left hand side of binary operator expressions. 3846 3847Example matches a (matcher = binaryOperator(hasLHS())) 3848 a || b 3849</pre></td></tr> 3850 3851 3852<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 3853<tr><td colspan="4" class="doc" id="hasRHS0"><pre>Matches the right hand side of binary operator expressions. 3854 3855Example matches b (matcher = binaryOperator(hasRHS())) 3856 a || b 3857</pre></td></tr> 3858 3859 3860<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BlockPointerTypeLoc.html">BlockPointerTypeLoc</a>></td><td class="name" onclick="toggle('pointeeLoc0')"><a name="pointeeLoc0Anchor">pointeeLoc</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td></tr> 3861<tr><td colspan="4" class="doc" id="pointeeLoc0"><pre>Narrows PointerType (and similar) matchers to those where the 3862pointee matches a given matcher. 3863 3864Given 3865 int *a; 3866 int const *b; 3867 float const *f; 3868pointerType(pointee(isConstQualified(), isInteger())) 3869 matches "int const *b" 3870 3871Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BlockPointerType.html">BlockPointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberPointerType.html">MemberPointerType</a>>, 3872 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1PointerType.html">PointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ReferenceType.html">ReferenceType</a>> 3873</pre></td></tr> 3874 3875 3876<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr> 3877<tr><td colspan="4" class="doc" id="pointee0"><pre>Narrows PointerType (and similar) matchers to those where the 3878pointee matches a given matcher. 3879 3880Given 3881 int *a; 3882 int const *b; 3883 float const *f; 3884pointerType(pointee(isConstQualified(), isInteger())) 3885 matches "int const *b" 3886 3887Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BlockPointerType.html">BlockPointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberPointerType.html">MemberPointerType</a>>, 3888 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1PointerType.html">PointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ReferenceType.html">ReferenceType</a>> 3889</pre></td></tr> 3890 3891 3892<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> ArgMatcher, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html">ParmVarDecl</a>> ParamMatcher</td></tr> 3893<tr><td colspan="4" class="doc" id="forEachArgumentWithParam1"><pre>Matches all arguments and their respective ParmVarDecl. 3894 3895Given 3896 void f(int i); 3897 int y; 3898 f(y); 3899callExpr( 3900 forEachArgumentWithParam( 3901 declRefExpr(to(varDecl(hasName("y")))), 3902 parmVarDecl(hasType(isInteger())) 3903)) 3904 matches f(y); 3905with declRefExpr(...) 3906 matching int y 3907and parmVarDecl(...) 3908 matching int i 3909</pre></td></tr> 3910 3911 3912<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 3913<tr><td colspan="4" class="doc" id="hasAnyArgument1"><pre>Matches any argument of a call expression or a constructor call 3914expression. 3915 3916Given 3917 void x(int, int, int) { int y; x(1, y, 42); } 3918callExpr(hasAnyArgument(declRefExpr())) 3919 matches x(1, y, 42) 3920with hasAnyArgument(...) 3921 matching y 3922</pre></td></tr> 3923 3924 3925<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 3926<tr><td colspan="4" class="doc" id="hasArgument1"><pre>Matches the n'th argument of a call expression or a constructor 3927call expression. 3928 3929Example matches y in x(y) 3930 (matcher = callExpr(hasArgument(0, declRefExpr()))) 3931 void x(int) { int y; x(y); } 3932</pre></td></tr> 3933 3934 3935<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>></td><td class="name" onclick="toggle('hasDeclaration13')"><a name="hasDeclaration13Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 3936<tr><td colspan="4" class="doc" id="hasDeclaration13"><pre>Matches a node if the declaration associated with that node 3937matches the given matcher. 3938 3939The associated declaration is: 3940- for type nodes, the declaration of the underlying type 3941- for CallExpr, the declaration of the callee 3942- for MemberExpr, the declaration of the referenced member 3943- for CXXConstructExpr, the declaration of the constructor 3944 3945Also usable as Matcher<T> for any T supporting the getDecl() member 3946function. e.g. various subtypes of clang::Type and various expressions. 3947 3948Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 3949 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 3950 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, 3951 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 3952 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 3953 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 3954</pre></td></tr> 3955 3956 3957<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>> InnerMatcher</td></tr> 3958<tr><td colspan="4" class="doc" id="forEachConstructorInitializer0"><pre>Matches each constructor initializer in a constructor definition. 3959 3960Given 3961 class A { A() : i(42), j(42) {} int i; int j; }; 3962cxxConstructorDecl(forEachConstructorInitializer( 3963 forField(decl().bind("x")) 3964)) 3965 will trigger two matches, binding for 'i' and 'j' respectively. 3966</pre></td></tr> 3967 3968 3969<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>> InnerMatcher</td></tr> 3970<tr><td colspan="4" class="doc" id="hasAnyConstructorInitializer0"><pre>Matches a constructor initializer. 3971 3972Given 3973 struct Foo { 3974 Foo() : foo_(1) { } 3975 int foo_; 3976 }; 3977cxxRecordDecl(has(cxxConstructorDecl( 3978 hasAnyConstructorInitializer(anything()) 3979))) 3980 record matches Foo, hasAnyConstructorInitializer matches foo_(1) 3981</pre></td></tr> 3982 3983 3984<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html">FieldDecl</a>> InnerMatcher</td></tr> 3985<tr><td colspan="4" class="doc" id="forField0"><pre>Matches the field declaration of a constructor initializer. 3986 3987Given 3988 struct Foo { 3989 Foo() : foo_(1) { } 3990 int foo_; 3991 }; 3992cxxRecordDecl(has(cxxConstructorDecl(hasAnyConstructorInitializer( 3993 forField(hasName("foo_")))))) 3994 matches Foo 3995with forField matching foo_ 3996</pre></td></tr> 3997 3998 3999<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 4000<tr><td colspan="4" class="doc" id="withInitializer0"><pre>Matches the initializer expression of a constructor initializer. 4001 4002Given 4003 struct Foo { 4004 Foo() : foo_(1) { } 4005 int foo_; 4006 }; 4007cxxRecordDecl(has(cxxConstructorDecl(hasAnyConstructorInitializer( 4008 withInitializer(integerLiteral(equals(1))))))) 4009 matches Foo 4010with withInitializer matching (1) 4011</pre></td></tr> 4012 4013 4014<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr> 4015<tr><td colspan="4" class="doc" id="hasBody3"><pre>Matches a 'for', 'while', 'do while' statement or a function 4016definition that has a given body. 4017 4018Given 4019 for (;;) {} 4020hasBody(compoundStmt()) 4021 matches 'for (;;) {}' 4022with compoundStmt() 4023 matching '{}' 4024</pre></td></tr> 4025 4026 4027<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>> InnerMatcher</td></tr> 4028<tr><td colspan="4" class="doc" id="hasLoopVariable0"><pre>Matches the initialization statement of a for loop. 4029 4030Example: 4031 forStmt(hasLoopVariable(anything())) 4032matches 'int x' in 4033 for (int x : a) { } 4034</pre></td></tr> 4035 4036 4037<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 4038<tr><td colspan="4" class="doc" id="hasRangeInit0"><pre>Matches the range initialization statement of a for loop. 4039 4040Example: 4041 forStmt(hasRangeInit(anything())) 4042matches 'a' in 4043 for (int x : a) { } 4044</pre></td></tr> 4045 4046 4047<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 4048<tr><td colspan="4" class="doc" id="onImplicitObjectArgument0"><pre></pre></td></tr> 4049 4050 4051<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 4052<tr><td colspan="4" class="doc" id="on0"><pre>Matches on the implicit object argument of a member call expression. 4053 4054Example matches y.x() 4055 (matcher = cxxMemberCallExpr(on(hasType(cxxRecordDecl(hasName("Y")))))) 4056 class Y { public: void x(); }; 4057 void z() { Y y; y.x(); }", 4058 4059FIXME: Overload to allow directly matching types? 4060</pre></td></tr> 4061 4062 4063<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 4064<tr><td colspan="4" class="doc" id="thisPointerType1"><pre>Overloaded to match the type's declaration. 4065</pre></td></tr> 4066 4067 4068<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 4069<tr><td colspan="4" class="doc" id="thisPointerType0"><pre>Matches if the expression's type either matches the specified 4070matcher, or is a pointer to a type that matches the InnerMatcher. 4071</pre></td></tr> 4072 4073 4074<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>> InnerMatcher</td></tr> 4075<tr><td colspan="4" class="doc" id="forEachOverridden0"><pre>Matches each method overriden by the given method. This matcher may 4076produce multiple matches. 4077 4078Given 4079 class A { virtual void f(); }; 4080 class B : public A { void f(); }; 4081 class C : public B { void f(); }; 4082cxxMethodDecl(ofClass(hasName("C")), 4083 forEachOverridden(cxxMethodDecl().bind("b"))).bind("d") 4084 matches once, with "b" binding "A::f" and "d" binding "C::f" (Note 4085 that B::f is not overridden by C::f). 4086 4087The check can produce multiple matches in case of multiple inheritance, e.g. 4088 class A1 { virtual void f(); }; 4089 class A2 { virtual void f(); }; 4090 class C : public A1, public A2 { void f(); }; 4091cxxMethodDecl(ofClass(hasName("C")), 4092 forEachOverridden(cxxMethodDecl().bind("b"))).bind("d") 4093 matches twice, once with "b" binding "A1::f" and "d" binding "C::f", and 4094 once with "b" binding "A2::f" and "d" binding "C::f". 4095</pre></td></tr> 4096 4097 4098<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>> InnerMatcher</td></tr> 4099<tr><td colspan="4" class="doc" id="ofClass0"><pre>Matches the class declaration that the given method declaration 4100belongs to. 4101 4102FIXME: Generalize this for other kinds of declarations. 4103FIXME: What other kind of declarations would we need to generalize 4104this to? 4105 4106Example matches A() in the last line 4107 (matcher = cxxConstructExpr(hasDeclaration(cxxMethodDecl( 4108 ofClass(hasName("A")))))) 4109 class A { 4110 public: 4111 A(); 4112 }; 4113 A a = A(); 4114</pre></td></tr> 4115 4116 4117<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>> InnerMatcher</td></tr> 4118<tr><td colspan="4" class="doc" id="hasMethod0"><pre>Matches the first method of a class or struct that satisfies InnerMatcher. 4119 4120Given: 4121 class A { void func(); }; 4122 class B { void member(); }; 4123 4124cxxRecordDecl(hasMethod(hasName("func"))) matches the declaration of 4125A but not B. 4126</pre></td></tr> 4127 4128 4129<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>> Base</td></tr> 4130<tr><td colspan="4" class="doc" id="isDerivedFrom0"><pre>Matches C++ classes that are directly or indirectly derived from 4131a class matching Base. 4132 4133Note that a class is not considered to be derived from itself. 4134 4135Example matches Y, Z, C (Base == hasName("X")) 4136 class X; 4137 class Y : public X {}; directly derived 4138 class Z : public Y {}; indirectly derived 4139 typedef X A; 4140 typedef A B; 4141 class C : public B {}; derived from a typedef of X 4142 4143In the following example, Bar matches isDerivedFrom(hasName("X")): 4144 class Foo; 4145 typedef Foo X; 4146 class Bar : public Foo {}; derived from a type that X is a typedef of 4147</pre></td></tr> 4148 4149 4150<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>> Base</td></tr> 4151<tr><td colspan="4" class="doc" id="isSameOrDerivedFrom0"><pre>Similar to isDerivedFrom(), but also matches classes that directly 4152match Base. 4153</pre></td></tr> 4154 4155 4156<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 4157<tr><td colspan="4" class="doc" id="callee1"><pre>Matches if the call expression's callee's declaration matches the 4158given matcher. 4159 4160Example matches y.x() (matcher = callExpr(callee( 4161 cxxMethodDecl(hasName("x"))))) 4162 class Y { public: void x(); }; 4163 void z() { Y y; y.x(); } 4164</pre></td></tr> 4165 4166 4167<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr> 4168<tr><td colspan="4" class="doc" id="callee0"><pre>Matches if the call expression's callee expression matches. 4169 4170Given 4171 class Y { void x() { this->x(); x(); Y y; y.x(); } }; 4172 void f() { f(); } 4173callExpr(callee(expr())) 4174 matches this->x(), x(), y.x(), f() 4175with callee(...) 4176 matching this->x, x, y.x, f respectively 4177 4178Note: Callee cannot take the more general internal::Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> 4179because this introduces ambiguous overloads with calls to Callee taking a 4180internal::Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>>, as the matcher hierarchy is purely 4181implemented in terms of implicit casts. 4182</pre></td></tr> 4183 4184 4185<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> ArgMatcher, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html">ParmVarDecl</a>> ParamMatcher</td></tr> 4186<tr><td colspan="4" class="doc" id="forEachArgumentWithParam0"><pre>Matches all arguments and their respective ParmVarDecl. 4187 4188Given 4189 void f(int i); 4190 int y; 4191 f(y); 4192callExpr( 4193 forEachArgumentWithParam( 4194 declRefExpr(to(varDecl(hasName("y")))), 4195 parmVarDecl(hasType(isInteger())) 4196)) 4197 matches f(y); 4198with declRefExpr(...) 4199 matching int y 4200and parmVarDecl(...) 4201 matching int i 4202</pre></td></tr> 4203 4204 4205<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 4206<tr><td colspan="4" class="doc" id="hasAnyArgument0"><pre>Matches any argument of a call expression or a constructor call 4207expression. 4208 4209Given 4210 void x(int, int, int) { int y; x(1, y, 42); } 4211callExpr(hasAnyArgument(declRefExpr())) 4212 matches x(1, y, 42) 4213with hasAnyArgument(...) 4214 matching y 4215</pre></td></tr> 4216 4217 4218<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 4219<tr><td colspan="4" class="doc" id="hasArgument0"><pre>Matches the n'th argument of a call expression or a constructor 4220call expression. 4221 4222Example matches y in x(y) 4223 (matcher = callExpr(hasArgument(0, declRefExpr()))) 4224 void x(int) { int y; x(y); } 4225</pre></td></tr> 4226 4227 4228<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>></td><td class="name" onclick="toggle('hasDeclaration14')"><a name="hasDeclaration14Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 4229<tr><td colspan="4" class="doc" id="hasDeclaration14"><pre>Matches a node if the declaration associated with that node 4230matches the given matcher. 4231 4232The associated declaration is: 4233- for type nodes, the declaration of the underlying type 4234- for CallExpr, the declaration of the callee 4235- for MemberExpr, the declaration of the referenced member 4236- for CXXConstructExpr, the declaration of the constructor 4237 4238Also usable as Matcher<T> for any T supporting the getDecl() member 4239function. e.g. various subtypes of clang::Type and various expressions. 4240 4241Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 4242 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 4243 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, 4244 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 4245 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 4246 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 4247</pre></td></tr> 4248 4249 4250<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 4251<tr><td colspan="4" class="doc" id="hasCaseConstant0"><pre>If the given case statement does not use the GNU case range 4252extension, matches the constant given in the statement. 4253 4254Given 4255 switch (1) { case 1: case 1+1: case 3 ... 4: ; } 4256caseStmt(hasCaseConstant(integerLiteral())) 4257 matches "case 1:" 4258</pre></td></tr> 4259 4260 4261<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 4262<tr><td colspan="4" class="doc" id="hasSourceExpression0"><pre></pre></td></tr> 4263 4264 4265<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr> 4266<tr><td colspan="4" class="doc" id="hasAnyTemplateArgument0"><pre>Matches classTemplateSpecializations, templateSpecializationType and 4267functionDecl that have at least one TemplateArgument matching the given 4268InnerMatcher. 4269 4270Given 4271 template<typename T> class A {}; 4272 template<> class A<double> {}; 4273 A<int> a; 4274 4275 template<typename T> f() {}; 4276 void func() { f<int>(); }; 4277 4278classTemplateSpecializationDecl(hasAnyTemplateArgument( 4279 refersToType(asString("int")))) 4280 matches the specialization A<int> 4281 4282functionDecl(hasAnyTemplateArgument(refersToType(asString("int")))) 4283 matches the specialization f<int> 4284</pre></td></tr> 4285 4286 4287<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr> 4288<tr><td colspan="4" class="doc" id="hasTemplateArgument0"><pre>Matches classTemplateSpecializations, templateSpecializationType and 4289functionDecl where the n'th TemplateArgument matches the given InnerMatcher. 4290 4291Given 4292 template<typename T, typename U> class A {}; 4293 A<bool, int> b; 4294 A<int, bool> c; 4295 4296 template<typename T> f() {}; 4297 void func() { f<int>(); }; 4298classTemplateSpecializationDecl(hasTemplateArgument( 4299 1, refersToType(asString("int")))) 4300 matches the specialization A<bool, int> 4301 4302functionDecl(hasTemplateArgument(0, refersToType(asString("int")))) 4303 matches the specialization f<int> 4304</pre></td></tr> 4305 4306 4307<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ComplexTypeLoc.html">ComplexTypeLoc</a>></td><td class="name" onclick="toggle('hasElementTypeLoc1')"><a name="hasElementTypeLoc1Anchor">hasElementTypeLoc</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td></tr> 4308<tr><td colspan="4" class="doc" id="hasElementTypeLoc1"><pre>Matches arrays and C99 complex types that have a specific element 4309type. 4310 4311Given 4312 struct A {}; 4313 A a[7]; 4314 int b[7]; 4315arrayType(hasElementType(builtinType())) 4316 matches "int b[7]" 4317 4318Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ArrayType.html">ArrayType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ComplexType.html">ComplexType</a>> 4319</pre></td></tr> 4320 4321 4322<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr> 4323<tr><td colspan="4" class="doc" id="hasElementType1"><pre>Matches arrays and C99 complex types that have a specific element 4324type. 4325 4326Given 4327 struct A {}; 4328 A a[7]; 4329 int b[7]; 4330arrayType(hasElementType(builtinType())) 4331 matches "int b[7]" 4332 4333Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ArrayType.html">ArrayType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ComplexType.html">ComplexType</a>> 4334</pre></td></tr> 4335 4336 4337<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr> 4338<tr><td colspan="4" class="doc" id="hasAnySubstatement0"><pre>Matches compound statements where at least one substatement matches 4339a given matcher. Also matches StmtExprs that have CompoundStmt as children. 4340 4341Given 4342 { {}; 1+2; } 4343hasAnySubstatement(compoundStmt()) 4344 matches '{ {}; 1+2; }' 4345with compoundStmt() 4346 matching '{}' 4347</pre></td></tr> 4348 4349 4350<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerType</td></tr> 4351<tr><td colspan="4" class="doc" id="hasDecayedType0"><pre>Matches the decayed type, whos decayed type matches InnerMatcher 4352</pre></td></tr> 4353 4354 4355<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>></td><td class="name" onclick="toggle('hasDeclaration12')"><a name="hasDeclaration12Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 4356<tr><td colspan="4" class="doc" id="hasDeclaration12"><pre>Matches a node if the declaration associated with that node 4357matches the given matcher. 4358 4359The associated declaration is: 4360- for type nodes, the declaration of the underlying type 4361- for CallExpr, the declaration of the callee 4362- for MemberExpr, the declaration of the referenced member 4363- for CXXConstructExpr, the declaration of the constructor 4364 4365Also usable as Matcher<T> for any T supporting the getDecl() member 4366function. e.g. various subtypes of clang::Type and various expressions. 4367 4368Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 4369 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 4370 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, 4371 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 4372 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 4373 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 4374</pre></td></tr> 4375 4376 4377<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1UsingShadowDecl.html">UsingShadowDecl</a>> InnerMatcher</td></tr> 4378<tr><td colspan="4" class="doc" id="throughUsingDecl0"><pre>Matches a DeclRefExpr that refers to a declaration through a 4379specific using shadow declaration. 4380 4381Given 4382 namespace a { void f() {} } 4383 using a::f; 4384 void g() { 4385 f(); Matches this .. 4386 a::f(); .. but not this. 4387 } 4388declRefExpr(throughUsingDecl(anything())) 4389 matches f() 4390</pre></td></tr> 4391 4392 4393<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 4394<tr><td colspan="4" class="doc" id="to0"><pre>Matches a DeclRefExpr that refers to a declaration that matches the 4395specified matcher. 4396 4397Example matches x in if(x) 4398 (matcher = declRefExpr(to(varDecl(hasName("x"))))) 4399 bool x; 4400 if (x) {} 4401</pre></td></tr> 4402 4403 4404<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 4405<tr><td colspan="4" class="doc" id="containsDeclaration0"><pre>Matches the n'th declaration of a declaration statement. 4406 4407Note that this does not work for global declarations because the AST 4408breaks up multiple-declaration DeclStmt's into multiple single-declaration 4409DeclStmt's. 4410Example: Given non-global declarations 4411 int a, b = 0; 4412 int c; 4413 int d = 2, e; 4414declStmt(containsDeclaration( 4415 0, varDecl(hasInitializer(anything())))) 4416 matches only 'int d = 2, e;', and 4417declStmt(containsDeclaration(1, varDecl())) 4418 matches 'int a, b = 0' as well as 'int d = 2, e;' 4419 but 'int c;' is not matched. 4420</pre></td></tr> 4421 4422 4423<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 4424<tr><td colspan="4" class="doc" id="hasSingleDecl0"><pre>Matches the Decl of a DeclStmt which has a single declaration. 4425 4426Given 4427 int a, b; 4428 int c; 4429declStmt(hasSingleDecl(anything())) 4430 matches 'int c;' but not 'int a, b;'. 4431</pre></td></tr> 4432 4433 4434<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> Inner</td></tr> 4435<tr><td colspan="4" class="doc" id="hasTypeLoc0"><pre>Matches if the type location of the declarator decl's type matches 4436the inner matcher. 4437 4438Given 4439 int x; 4440declaratorDecl(hasTypeLoc(loc(asString("int")))) 4441 matches int x 4442</pre></td></tr> 4443 4444 4445<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 4446<tr><td colspan="4" class="doc" id="hasDeclContext0"><pre>Matches declarations whose declaration context, interpreted as a 4447Decl, matches InnerMatcher. 4448 4449Given 4450 namespace N { 4451 namespace M { 4452 class D {}; 4453 } 4454 } 4455 4456cxxRcordDecl(hasDeclContext(namedDecl(hasName("M")))) matches the 4457declaration of class D. 4458</pre></td></tr> 4459 4460 4461<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr> 4462<tr><td colspan="4" class="doc" id="hasBody0"><pre>Matches a 'for', 'while', 'do while' statement or a function 4463definition that has a given body. 4464 4465Given 4466 for (;;) {} 4467hasBody(compoundStmt()) 4468 matches 'for (;;) {}' 4469with compoundStmt() 4470 matching '{}' 4471</pre></td></tr> 4472 4473 4474<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 4475<tr><td colspan="4" class="doc" id="hasCondition3"><pre>Matches the condition expression of an if statement, for loop, 4476switch statement or conditional operator. 4477 4478Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true)))) 4479 if (true) {} 4480</pre></td></tr> 4481 4482 4483<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifier.html">NestedNameSpecifier</a>> InnerMatcher</td></tr> 4484<tr><td colspan="4" class="doc" id="hasQualifier0"><pre>Matches ElaboratedTypes whose qualifier, a NestedNameSpecifier, 4485matches InnerMatcher if the qualifier exists. 4486 4487Given 4488 namespace N { 4489 namespace M { 4490 class D {}; 4491 } 4492 } 4493 N::M::D d; 4494 4495elaboratedType(hasQualifier(hasPrefix(specifiesNamespace(hasName("N")))) 4496matches the type of the variable declaration of d. 4497</pre></td></tr> 4498 4499 4500<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 4501<tr><td colspan="4" class="doc" id="namesType0"><pre>Matches ElaboratedTypes whose named type matches InnerMatcher. 4502 4503Given 4504 namespace N { 4505 namespace M { 4506 class D {}; 4507 } 4508 } 4509 N::M::D d; 4510 4511elaboratedType(namesType(recordType( 4512hasDeclaration(namedDecl(hasName("D")))))) matches the type of the variable 4513declaration of d. 4514</pre></td></tr> 4515 4516 4517<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>></td><td class="name" onclick="toggle('hasDeclaration11')"><a name="hasDeclaration11Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 4518<tr><td colspan="4" class="doc" id="hasDeclaration11"><pre>Matches a node if the declaration associated with that node 4519matches the given matcher. 4520 4521The associated declaration is: 4522- for type nodes, the declaration of the underlying type 4523- for CallExpr, the declaration of the callee 4524- for MemberExpr, the declaration of the referenced member 4525- for CXXConstructExpr, the declaration of the constructor 4526 4527Also usable as Matcher<T> for any T supporting the getDecl() member 4528function. e.g. various subtypes of clang::Type and various expressions. 4529 4530Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 4531 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 4532 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, 4533 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 4534 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 4535 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 4536</pre></td></tr> 4537 4538 4539<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 4540<tr><td colspan="4" class="doc" id="hasDestinationType0"><pre>Matches casts whose destination type matches a given matcher. 4541 4542(Note: Clang's AST refers to other conversions as "casts" too, and calls 4543actual casts "explicit" casts.) 4544</pre></td></tr> 4545 4546 4547<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>></td><td class="name" onclick="toggle('hasType3')"><a name="hasType3Anchor">hasType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 4548<tr><td colspan="4" class="doc" id="hasType3"><pre>Overloaded to match the declaration of the expression's or value 4549declaration's type. 4550 4551In case of a value declaration (for example a variable declaration), 4552this resolves one layer of indirection. For example, in the value 4553declaration "X x;", cxxRecordDecl(hasName("X")) matches the declaration of 4554X, while varDecl(hasType(cxxRecordDecl(hasName("X")))) matches the 4555declaration of x. 4556 4557Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) 4558 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) 4559 class X {}; 4560 void y(X &x) { x; X z; } 4561 4562Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</a>> 4563</pre></td></tr> 4564 4565 4566<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 4567<tr><td colspan="4" class="doc" id="hasType0"><pre>Matches if the expression's or declaration's type matches a type 4568matcher. 4569 4570Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) 4571 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) 4572 and U (matcher = typedefDecl(hasType(asString("int"))) 4573 class X {}; 4574 void y(X &x) { x; X z; } 4575 typedef int U; 4576</pre></td></tr> 4577 4578 4579<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 4580<tr><td colspan="4" class="doc" id="ignoringImpCasts0"><pre>Matches expressions that match InnerMatcher after any implicit casts 4581are stripped off. 4582 4583Parentheses and explicit casts are not discarded. 4584Given 4585 int arr[5]; 4586 int a = 0; 4587 char b = 0; 4588 const int c = a; 4589 int *d = arr; 4590 long e = (long) 0l; 4591The matchers 4592 varDecl(hasInitializer(ignoringImpCasts(integerLiteral()))) 4593 varDecl(hasInitializer(ignoringImpCasts(declRefExpr()))) 4594would match the declarations for a, b, c, and d, but not e. 4595While 4596 varDecl(hasInitializer(integerLiteral())) 4597 varDecl(hasInitializer(declRefExpr())) 4598only match the declarations for b, c, and d. 4599</pre></td></tr> 4600 4601 4602<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>></td><td class="name" onclick="toggle('ignoringImplicit0')"><a name="ignoringImplicit0Anchor">ignoringImplicit</a></td><td>ast_matchers::Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 4603<tr><td colspan="4" class="doc" id="ignoringImplicit0"><pre>Matches expressions that match InnerMatcher after any implicit AST 4604nodes are stripped off. 4605 4606Parentheses and explicit casts are not discarded. 4607Given 4608 class C {}; 4609 C a = C(); 4610 C b; 4611 C c = b; 4612The matchers 4613 varDecl(hasInitializer(ignoringImplicit(cxxConstructExpr()))) 4614would match the declarations for a, b, and c. 4615While 4616 varDecl(hasInitializer(cxxConstructExpr())) 4617only match the declarations for b and c. 4618</pre></td></tr> 4619 4620 4621<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 4622<tr><td colspan="4" class="doc" id="ignoringParenCasts0"><pre>Matches expressions that match InnerMatcher after parentheses and 4623casts are stripped off. 4624 4625Implicit and non-C Style casts are also discarded. 4626Given 4627 int a = 0; 4628 char b = (0); 4629 void* c = reinterpret_cast<char*>(0); 4630 char d = char(0); 4631The matcher 4632 varDecl(hasInitializer(ignoringParenCasts(integerLiteral()))) 4633would match the declarations for a, b, c, and d. 4634while 4635 varDecl(hasInitializer(integerLiteral())) 4636only match the declaration for a. 4637</pre></td></tr> 4638 4639 4640<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 4641<tr><td colspan="4" class="doc" id="ignoringParenImpCasts0"><pre>Matches expressions that match InnerMatcher after implicit casts and 4642parentheses are stripped off. 4643 4644Explicit casts are not discarded. 4645Given 4646 int arr[5]; 4647 int a = 0; 4648 char b = (0); 4649 const int c = a; 4650 int *d = (arr); 4651 long e = ((long) 0l); 4652The matchers 4653 varDecl(hasInitializer(ignoringParenImpCasts(integerLiteral()))) 4654 varDecl(hasInitializer(ignoringParenImpCasts(declRefExpr()))) 4655would match the declarations for a, b, c, and d, but not e. 4656while 4657 varDecl(hasInitializer(integerLiteral())) 4658 varDecl(hasInitializer(declRefExpr())) 4659would only match the declaration for a. 4660</pre></td></tr> 4661 4662 4663<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr> 4664<tr><td colspan="4" class="doc" id="hasBody1"><pre>Matches a 'for', 'while', 'do while' statement or a function 4665definition that has a given body. 4666 4667Given 4668 for (;;) {} 4669hasBody(compoundStmt()) 4670 matches 'for (;;) {}' 4671with compoundStmt() 4672 matching '{}' 4673</pre></td></tr> 4674 4675 4676<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 4677<tr><td colspan="4" class="doc" id="hasCondition1"><pre>Matches the condition expression of an if statement, for loop, 4678switch statement or conditional operator. 4679 4680Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true)))) 4681 if (true) {} 4682</pre></td></tr> 4683 4684 4685<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr> 4686<tr><td colspan="4" class="doc" id="hasIncrement0"><pre>Matches the increment statement of a for loop. 4687 4688Example: 4689 forStmt(hasIncrement(unaryOperator(hasOperatorName("++")))) 4690matches '++x' in 4691 for (x; x < N; ++x) { } 4692</pre></td></tr> 4693 4694 4695<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr> 4696<tr><td colspan="4" class="doc" id="hasLoopInit0"><pre>Matches the initialization statement of a for loop. 4697 4698Example: 4699 forStmt(hasLoopInit(declStmt())) 4700matches 'int x = 0' in 4701 for (int x = 0; x < N; ++x) { } 4702</pre></td></tr> 4703 4704 4705<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html">ParmVarDecl</a>> InnerMatcher</td></tr> 4706<tr><td colspan="4" class="doc" id="hasAnyParameter0"><pre>Matches any parameter of a function declaration. 4707 4708Does not match the 'this' parameter of a method. 4709 4710Given 4711 class X { void f(int x, int y, int z) {} }; 4712cxxMethodDecl(hasAnyParameter(hasName("y"))) 4713 matches f(int x, int y, int z) {} 4714with hasAnyParameter(...) 4715 matching int y 4716</pre></td></tr> 4717 4718 4719<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr> 4720<tr><td colspan="4" class="doc" id="hasAnyTemplateArgument2"><pre>Matches classTemplateSpecializations, templateSpecializationType and 4721functionDecl that have at least one TemplateArgument matching the given 4722InnerMatcher. 4723 4724Given 4725 template<typename T> class A {}; 4726 template<> class A<double> {}; 4727 A<int> a; 4728 4729 template<typename T> f() {}; 4730 void func() { f<int>(); }; 4731 4732classTemplateSpecializationDecl(hasAnyTemplateArgument( 4733 refersToType(asString("int")))) 4734 matches the specialization A<int> 4735 4736functionDecl(hasAnyTemplateArgument(refersToType(asString("int")))) 4737 matches the specialization f<int> 4738</pre></td></tr> 4739 4740 4741<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr> 4742<tr><td colspan="4" class="doc" id="hasBody4"><pre>Matches a 'for', 'while', 'do while' statement or a function 4743definition that has a given body. 4744 4745Given 4746 for (;;) {} 4747hasBody(compoundStmt()) 4748 matches 'for (;;) {}' 4749with compoundStmt() 4750 matching '{}' 4751</pre></td></tr> 4752 4753 4754<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html">ParmVarDecl</a>> InnerMatcher</td></tr> 4755<tr><td colspan="4" class="doc" id="hasParameter0"><pre>Matches the n'th parameter of a function declaration. 4756 4757Given 4758 class X { void f(int x) {} }; 4759cxxMethodDecl(hasParameter(0, hasType(varDecl()))) 4760 matches f(int x) {} 4761with hasParameter(...) 4762 matching int x 4763</pre></td></tr> 4764 4765 4766<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr> 4767<tr><td colspan="4" class="doc" id="hasTemplateArgument2"><pre>Matches classTemplateSpecializations, templateSpecializationType and 4768functionDecl where the n'th TemplateArgument matches the given InnerMatcher. 4769 4770Given 4771 template<typename T, typename U> class A {}; 4772 A<bool, int> b; 4773 A<int, bool> c; 4774 4775 template<typename T> f() {}; 4776 void func() { f<int>(); }; 4777classTemplateSpecializationDecl(hasTemplateArgument( 4778 1, refersToType(asString("int")))) 4779 matches the specialization A<bool, int> 4780 4781functionDecl(hasTemplateArgument(0, refersToType(asString("int")))) 4782 matches the specialization f<int> 4783</pre></td></tr> 4784 4785 4786<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 4787<tr><td colspan="4" class="doc" id="returns0"><pre>Matches the return type of a function declaration. 4788 4789Given: 4790 class X { int f() { return 1; } }; 4791cxxMethodDecl(returns(asString("int"))) 4792 matches int f() { return 1; } 4793</pre></td></tr> 4794 4795 4796<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 4797<tr><td colspan="4" class="doc" id="hasCondition0"><pre>Matches the condition expression of an if statement, for loop, 4798switch statement or conditional operator. 4799 4800Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true)))) 4801 if (true) {} 4802</pre></td></tr> 4803 4804 4805<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1DeclStmt.html">DeclStmt</a>> InnerMatcher</td></tr> 4806<tr><td colspan="4" class="doc" id="hasConditionVariableStatement0"><pre>Matches the condition variable statement in an if statement. 4807 4808Given 4809 if (A* a = GetAPointer()) {} 4810hasConditionVariableStatement(...) 4811 matches 'A* a = GetAPointer()'. 4812</pre></td></tr> 4813 4814 4815<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr> 4816<tr><td colspan="4" class="doc" id="hasElse0"><pre>Matches the else-statement of an if statement. 4817 4818Examples matches the if statement 4819 (matcher = ifStmt(hasElse(cxxBoolLiteral(equals(true))))) 4820 if (false) false; else true; 4821</pre></td></tr> 4822 4823 4824<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr> 4825<tr><td colspan="4" class="doc" id="hasThen0"><pre>Matches the then-statement of an if statement. 4826 4827Examples matches the if statement 4828 (matcher = ifStmt(hasThen(cxxBoolLiteral(equals(true))))) 4829 if (false) true; else false; 4830</pre></td></tr> 4831 4832 4833<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 4834<tr><td colspan="4" class="doc" id="hasImplicitDestinationType0"><pre>Matches implicit casts whose destination type matches a given 4835matcher. 4836 4837FIXME: Unit test this matcher 4838</pre></td></tr> 4839 4840 4841<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 4842<tr><td colspan="4" class="doc" id="hasSyntacticForm0"><pre>Matches the syntactic form of init list expressions 4843(if expression have it). 4844</pre></td></tr> 4845 4846 4847<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>></td><td class="name" onclick="toggle('hasDeclaration10')"><a name="hasDeclaration10Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 4848<tr><td colspan="4" class="doc" id="hasDeclaration10"><pre>Matches a node if the declaration associated with that node 4849matches the given matcher. 4850 4851The associated declaration is: 4852- for type nodes, the declaration of the underlying type 4853- for CallExpr, the declaration of the callee 4854- for MemberExpr, the declaration of the referenced member 4855- for CXXConstructExpr, the declaration of the constructor 4856 4857Also usable as Matcher<T> for any T supporting the getDecl() member 4858function. e.g. various subtypes of clang::Type and various expressions. 4859 4860Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 4861 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 4862 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, 4863 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 4864 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 4865 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 4866</pre></td></tr> 4867 4868 4869<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>></td><td class="name" onclick="toggle('hasDeclaration9')"><a name="hasDeclaration9Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 4870<tr><td colspan="4" class="doc" id="hasDeclaration9"><pre>Matches a node if the declaration associated with that node 4871matches the given matcher. 4872 4873The associated declaration is: 4874- for type nodes, the declaration of the underlying type 4875- for CallExpr, the declaration of the callee 4876- for MemberExpr, the declaration of the referenced member 4877- for CXXConstructExpr, the declaration of the constructor 4878 4879Also usable as Matcher<T> for any T supporting the getDecl() member 4880function. e.g. various subtypes of clang::Type and various expressions. 4881 4882Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 4883 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 4884 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, 4885 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 4886 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 4887 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 4888</pre></td></tr> 4889 4890 4891<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>></td><td class="name" onclick="toggle('hasDeclaration7')"><a name="hasDeclaration7Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 4892<tr><td colspan="4" class="doc" id="hasDeclaration7"><pre>Matches a node if the declaration associated with that node 4893matches the given matcher. 4894 4895The associated declaration is: 4896- for type nodes, the declaration of the underlying type 4897- for CallExpr, the declaration of the callee 4898- for MemberExpr, the declaration of the referenced member 4899- for CXXConstructExpr, the declaration of the constructor 4900 4901Also usable as Matcher<T> for any T supporting the getDecl() member 4902function. e.g. various subtypes of clang::Type and various expressions. 4903 4904Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 4905 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 4906 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, 4907 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 4908 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 4909 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 4910</pre></td></tr> 4911 4912 4913<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 4914<tr><td colspan="4" class="doc" id="hasObjectExpression0"><pre>Matches a member expression where the object expression is 4915matched by a given matcher. 4916 4917Given 4918 struct X { int m; }; 4919 void f(X x) { x.m; m; } 4920memberExpr(hasObjectExpression(hasType(cxxRecordDecl(hasName("X"))))))) 4921 matches "x.m" and "m" 4922with hasObjectExpression(...) 4923 matching "x" and the implicit object expression of "m" which has type X*. 4924</pre></td></tr> 4925 4926 4927<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</a>> InnerMatcher</td></tr> 4928<tr><td colspan="4" class="doc" id="member0"><pre>Matches a member expression where the member is matched by a 4929given matcher. 4930 4931Given 4932 struct { int first, second; } first, second; 4933 int i(second.first); 4934 int j(first.second); 4935memberExpr(member(hasName("first"))) 4936 matches second.first 4937 but not first.second (because the member name there is "second"). 4938</pre></td></tr> 4939 4940 4941<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberPointerTypeLoc.html">MemberPointerTypeLoc</a>></td><td class="name" onclick="toggle('pointeeLoc1')"><a name="pointeeLoc1Anchor">pointeeLoc</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td></tr> 4942<tr><td colspan="4" class="doc" id="pointeeLoc1"><pre>Narrows PointerType (and similar) matchers to those where the 4943pointee matches a given matcher. 4944 4945Given 4946 int *a; 4947 int const *b; 4948 float const *f; 4949pointerType(pointee(isConstQualified(), isInteger())) 4950 matches "int const *b" 4951 4952Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BlockPointerType.html">BlockPointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberPointerType.html">MemberPointerType</a>>, 4953 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1PointerType.html">PointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ReferenceType.html">ReferenceType</a>> 4954</pre></td></tr> 4955 4956 4957<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr> 4958<tr><td colspan="4" class="doc" id="pointee1"><pre>Narrows PointerType (and similar) matchers to those where the 4959pointee matches a given matcher. 4960 4961Given 4962 int *a; 4963 int const *b; 4964 float const *f; 4965pointerType(pointee(isConstQualified(), isInteger())) 4966 matches "int const *b" 4967 4968Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BlockPointerType.html">BlockPointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberPointerType.html">MemberPointerType</a>>, 4969 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1PointerType.html">PointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ReferenceType.html">ReferenceType</a>> 4970</pre></td></tr> 4971 4972 4973<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>> InnerMatcher</td></tr> 4974<tr><td colspan="4" class="doc" id="hasUnderlyingDecl0"><pre>Matches a NamedDecl whose underlying declaration matches the given 4975matcher. 4976 4977Given 4978 namespace N { template<class T> void f(T t); } 4979 template <class T> void g() { using N::f; f(T()); } 4980unresolvedLookupExpr(hasAnyDeclaration( 4981 namedDecl(hasUnderlyingDecl(hasName("::N::f"))))) 4982 matches the use of f in g() . 4983</pre></td></tr> 4984 4985 4986<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifierLoc.html">NestedNameSpecifierLoc</a>> InnerMatcher</td></tr> 4987<tr><td colspan="4" class="doc" id="hasPrefix1"><pre>Matches on the prefix of a NestedNameSpecifierLoc. 4988 4989Given 4990 struct A { struct B { struct C {}; }; }; 4991 A::B::C c; 4992nestedNameSpecifierLoc(hasPrefix(loc(specifiesType(asString("struct A"))))) 4993 matches "A::" 4994</pre></td></tr> 4995 4996 4997<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>> InnerMatcher</td></tr> 4998<tr><td colspan="4" class="doc" id="specifiesTypeLoc0"><pre>Matches nested name specifier locs that specify a type matching the 4999given TypeLoc. 5000 5001Given 5002 struct A { struct B { struct C {}; }; }; 5003 A::B::C c; 5004nestedNameSpecifierLoc(specifiesTypeLoc(loc(type( 5005 hasDeclaration(cxxRecordDecl(hasName("A"))))))) 5006 matches "A::" 5007</pre></td></tr> 5008 5009 5010<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifier.html">NestedNameSpecifier</a>> InnerMatcher</td></tr> 5011<tr><td colspan="4" class="doc" id="hasPrefix0"><pre>Matches on the prefix of a NestedNameSpecifier. 5012 5013Given 5014 struct A { struct B { struct C {}; }; }; 5015 A::B::C c; 5016nestedNameSpecifier(hasPrefix(specifiesType(asString("struct A")))) and 5017 matches "A::" 5018</pre></td></tr> 5019 5020 5021<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1NamespaceDecl.html">NamespaceDecl</a>> InnerMatcher</td></tr> 5022<tr><td colspan="4" class="doc" id="specifiesNamespace0"><pre>Matches nested name specifiers that specify a namespace matching the 5023given namespace matcher. 5024 5025Given 5026 namespace ns { struct A {}; } 5027 ns::A a; 5028nestedNameSpecifier(specifiesNamespace(hasName("ns"))) 5029 matches "ns::" 5030</pre></td></tr> 5031 5032 5033<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 5034<tr><td colspan="4" class="doc" id="specifiesType0"><pre>Matches nested name specifiers that specify a type matching the 5035given QualType matcher without qualifiers. 5036 5037Given 5038 struct A { struct B { struct C {}; }; }; 5039 A::B::C c; 5040nestedNameSpecifier(specifiesType( 5041 hasDeclaration(cxxRecordDecl(hasName("A"))) 5042)) 5043 matches "A::" 5044</pre></td></tr> 5045 5046 5047<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 5048<tr><td colspan="4" class="doc" id="hasArgument2"><pre>Matches the n'th argument of a call expression or a constructor 5049call expression. 5050 5051Example matches y in x(y) 5052 (matcher = callExpr(hasArgument(0, declRefExpr()))) 5053 void x(int) { int y; x(y); } 5054</pre></td></tr> 5055 5056 5057<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 5058<tr><td colspan="4" class="doc" id="hasReceiverType0"><pre>Matches on the receiver of an ObjectiveC Message expression. 5059 5060Example 5061matcher = objCMessageExpr(hasRecieverType(asString("UIWebView *"))); 5062matches the [webView ...] message invocation. 5063 NSString *webViewJavaScript = ... 5064 UIWebView *webView = ... 5065 [webView stringByEvaluatingJavaScriptFromString:webViewJavascript]; 5066</pre></td></tr> 5067 5068 5069<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 5070<tr><td colspan="4" class="doc" id="hasSourceExpression1"><pre></pre></td></tr> 5071 5072 5073<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 5074<tr><td colspan="4" class="doc" id="hasAnyDeclaration0"><pre>Matches an OverloadExpr if any of the declarations in the set of 5075overloads matches the given matcher. 5076 5077Given 5078 template <typename T> void foo(T); 5079 template <typename T> void bar(T); 5080 template <typename T> void baz(T t) { 5081 foo(t); 5082 bar(t); 5083 } 5084unresolvedLookupExpr(hasAnyDeclaration( 5085 functionTemplateDecl(hasName("foo")))) 5086 matches foo in foo(t); but not bar in bar(t); 5087</pre></td></tr> 5088 5089 5090<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr> 5091<tr><td colspan="4" class="doc" id="innerType0"><pre>Matches ParenType nodes where the inner type is a specific type. 5092 5093Given 5094 int (*ptr_to_array)[4]; 5095 int (*ptr_to_func)(int); 5096 5097varDecl(hasType(pointsTo(parenType(innerType(functionType()))))) matches 5098ptr_to_func but not ptr_to_array. 5099 5100Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ParenType.html">ParenType</a>> 5101</pre></td></tr> 5102 5103 5104<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1PointerTypeLoc.html">PointerTypeLoc</a>></td><td class="name" onclick="toggle('pointeeLoc2')"><a name="pointeeLoc2Anchor">pointeeLoc</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td></tr> 5105<tr><td colspan="4" class="doc" id="pointeeLoc2"><pre>Narrows PointerType (and similar) matchers to those where the 5106pointee matches a given matcher. 5107 5108Given 5109 int *a; 5110 int const *b; 5111 float const *f; 5112pointerType(pointee(isConstQualified(), isInteger())) 5113 matches "int const *b" 5114 5115Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BlockPointerType.html">BlockPointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberPointerType.html">MemberPointerType</a>>, 5116 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1PointerType.html">PointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ReferenceType.html">ReferenceType</a>> 5117</pre></td></tr> 5118 5119 5120<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr> 5121<tr><td colspan="4" class="doc" id="pointee2"><pre>Narrows PointerType (and similar) matchers to those where the 5122pointee matches a given matcher. 5123 5124Given 5125 int *a; 5126 int const *b; 5127 float const *f; 5128pointerType(pointee(isConstQualified(), isInteger())) 5129 matches "int const *b" 5130 5131Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BlockPointerType.html">BlockPointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberPointerType.html">MemberPointerType</a>>, 5132 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1PointerType.html">PointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ReferenceType.html">ReferenceType</a>> 5133</pre></td></tr> 5134 5135 5136<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 5137<tr><td colspan="4" class="doc" id="hasCanonicalType0"><pre>Matches QualTypes whose canonical type matches InnerMatcher. 5138 5139Given: 5140 typedef int &int_ref; 5141 int a; 5142 int_ref b = a; 5143 5144varDecl(hasType(qualType(referenceType()))))) will not match the 5145declaration of b but varDecl(hasType(qualType(hasCanonicalType(referenceType())))))) does. 5146</pre></td></tr> 5147 5148 5149<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('hasDeclaration6')"><a name="hasDeclaration6Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 5150<tr><td colspan="4" class="doc" id="hasDeclaration6"><pre>Matches a node if the declaration associated with that node 5151matches the given matcher. 5152 5153The associated declaration is: 5154- for type nodes, the declaration of the underlying type 5155- for CallExpr, the declaration of the callee 5156- for MemberExpr, the declaration of the referenced member 5157- for CXXConstructExpr, the declaration of the constructor 5158 5159Also usable as Matcher<T> for any T supporting the getDecl() member 5160function. e.g. various subtypes of clang::Type and various expressions. 5161 5162Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 5163 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 5164 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, 5165 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 5166 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 5167 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 5168</pre></td></tr> 5169 5170 5171<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 5172<tr><td colspan="4" class="doc" id="ignoringParens0"><pre>Matches types that match InnerMatcher after any parens are stripped. 5173 5174Given 5175 void (*fp)(void); 5176The matcher 5177 varDecl(hasType(pointerType(pointee(ignoringParens(functionType()))))) 5178would match the declaration for fp. 5179</pre></td></tr> 5180 5181 5182<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 5183<tr><td colspan="4" class="doc" id="pointsTo1"><pre>Overloaded to match the pointee type's declaration. 5184</pre></td></tr> 5185 5186 5187<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 5188<tr><td colspan="4" class="doc" id="pointsTo0"><pre>Matches if the matched type is a pointer type and the pointee type 5189matches the specified matcher. 5190 5191Example matches y->x() 5192 (matcher = cxxMemberCallExpr(on(hasType(pointsTo 5193 cxxRecordDecl(hasName("Y"))))))) 5194 class Y { public: void x(); }; 5195 void z() { Y *y; y->x(); } 5196</pre></td></tr> 5197 5198 5199<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 5200<tr><td colspan="4" class="doc" id="references1"><pre>Overloaded to match the referenced type's declaration. 5201</pre></td></tr> 5202 5203 5204<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 5205<tr><td colspan="4" class="doc" id="references0"><pre>Matches if the matched type is a reference type and the referenced 5206type matches the specified matcher. 5207 5208Example matches X &x and const X &y 5209 (matcher = varDecl(hasType(references(cxxRecordDecl(hasName("X")))))) 5210 class X { 5211 void a(X b) { 5212 X &x = b; 5213 const X &y = b; 5214 } 5215 }; 5216</pre></td></tr> 5217 5218 5219<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>></td><td class="name" onclick="toggle('hasDeclaration5')"><a name="hasDeclaration5Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 5220<tr><td colspan="4" class="doc" id="hasDeclaration5"><pre>Matches a node if the declaration associated with that node 5221matches the given matcher. 5222 5223The associated declaration is: 5224- for type nodes, the declaration of the underlying type 5225- for CallExpr, the declaration of the callee 5226- for MemberExpr, the declaration of the referenced member 5227- for CXXConstructExpr, the declaration of the constructor 5228 5229Also usable as Matcher<T> for any T supporting the getDecl() member 5230function. e.g. various subtypes of clang::Type and various expressions. 5231 5232Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 5233 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 5234 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, 5235 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 5236 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 5237 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 5238</pre></td></tr> 5239 5240 5241<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ReferenceTypeLoc.html">ReferenceTypeLoc</a>></td><td class="name" onclick="toggle('pointeeLoc3')"><a name="pointeeLoc3Anchor">pointeeLoc</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>></td></tr> 5242<tr><td colspan="4" class="doc" id="pointeeLoc3"><pre>Narrows PointerType (and similar) matchers to those where the 5243pointee matches a given matcher. 5244 5245Given 5246 int *a; 5247 int const *b; 5248 float const *f; 5249pointerType(pointee(isConstQualified(), isInteger())) 5250 matches "int const *b" 5251 5252Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BlockPointerType.html">BlockPointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberPointerType.html">MemberPointerType</a>>, 5253 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1PointerType.html">PointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ReferenceType.html">ReferenceType</a>> 5254</pre></td></tr> 5255 5256 5257<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr> 5258<tr><td colspan="4" class="doc" id="pointee3"><pre>Narrows PointerType (and similar) matchers to those where the 5259pointee matches a given matcher. 5260 5261Given 5262 int *a; 5263 int const *b; 5264 float const *f; 5265pointerType(pointee(isConstQualified(), isInteger())) 5266 matches "int const *b" 5267 5268Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BlockPointerType.html">BlockPointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberPointerType.html">MemberPointerType</a>>, 5269 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1PointerType.html">PointerType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ReferenceType.html">ReferenceType</a>> 5270</pre></td></tr> 5271 5272 5273<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 5274<tr><td colspan="4" class="doc" id="hasReturnValue0"><pre>Matches the return value expression of a return statement 5275 5276Given 5277 return a + b; 5278hasReturnValue(binaryOperator()) 5279 matches 'return a + b' 5280with binaryOperator() 5281 matching 'a + b' 5282</pre></td></tr> 5283 5284 5285<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr> 5286<tr><td colspan="4" class="doc" id="hasAnySubstatement1"><pre>Matches compound statements where at least one substatement matches 5287a given matcher. Also matches StmtExprs that have CompoundStmt as children. 5288 5289Given 5290 { {}; 1+2; } 5291hasAnySubstatement(compoundStmt()) 5292 matches '{ {}; 1+2; }' 5293with compoundStmt() 5294 matching '{}' 5295</pre></td></tr> 5296 5297 5298<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('alignOfExpr0')"><a name="alignOfExpr0Anchor">alignOfExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html">UnaryExprOrTypeTraitExpr</a>> InnerMatcher</td></tr> 5299<tr><td colspan="4" class="doc" id="alignOfExpr0"><pre>Same as unaryExprOrTypeTraitExpr, but only matching 5300alignof. 5301</pre></td></tr> 5302 5303 5304<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>> InnerMatcher</td></tr> 5305<tr><td colspan="4" class="doc" id="forFunction0"><pre>Matches declaration of the function the statemenet belongs to 5306 5307Given: 5308F& operator=(const F& o) { 5309 std::copy_if(o.begin(), o.end(), begin(), [](V v) { return v > 0; }); 5310 return *this; 5311} 5312returnStmt(forFunction(hasName("operator="))) 5313 matches 'return *this' 5314 but does match 'return > 0' 5315</pre></td></tr> 5316 5317 5318<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('sizeOfExpr0')"><a name="sizeOfExpr0Anchor">sizeOfExpr</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html">UnaryExprOrTypeTraitExpr</a>> InnerMatcher</td></tr> 5319<tr><td colspan="4" class="doc" id="sizeOfExpr0"><pre>Same as unaryExprOrTypeTraitExpr, but only matching 5320sizeof. 5321</pre></td></tr> 5322 5323 5324<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1SwitchCase.html">SwitchCase</a>> InnerMatcher</td></tr> 5325<tr><td colspan="4" class="doc" id="forEachSwitchCase0"><pre>Matches each case or default statement belonging to the given switch 5326statement. This matcher may produce multiple matches. 5327 5328Given 5329 switch (1) { case 1: case 2: default: switch (2) { case 3: case 4: ; } } 5330switchStmt(forEachSwitchCase(caseStmt().bind("c"))).bind("s") 5331 matches four times, with "c" binding each of "case 1:", "case 2:", 5332"case 3:" and "case 4:", and "s" respectively binding "switch (1)", 5333"switch (1)", "switch (2)" and "switch (2)". 5334</pre></td></tr> 5335 5336 5337<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 5338<tr><td colspan="4" class="doc" id="hasCondition4"><pre>Matches the condition expression of an if statement, for loop, 5339switch statement or conditional operator. 5340 5341Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true)))) 5342 if (true) {} 5343</pre></td></tr> 5344 5345 5346<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>></td><td class="name" onclick="toggle('hasDeclaration4')"><a name="hasDeclaration4Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 5347<tr><td colspan="4" class="doc" id="hasDeclaration4"><pre>Matches a node if the declaration associated with that node 5348matches the given matcher. 5349 5350The associated declaration is: 5351- for type nodes, the declaration of the underlying type 5352- for CallExpr, the declaration of the callee 5353- for MemberExpr, the declaration of the referenced member 5354- for CXXConstructExpr, the declaration of the constructor 5355 5356Also usable as Matcher<T> for any T supporting the getDecl() member 5357function. e.g. various subtypes of clang::Type and various expressions. 5358 5359Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 5360 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 5361 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, 5362 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 5363 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 5364 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 5365</pre></td></tr> 5366 5367 5368<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 5369<tr><td colspan="4" class="doc" id="isExpr0"><pre>Matches a sugar TemplateArgument that refers to a certain expression. 5370 5371Given 5372 template<typename T> struct A {}; 5373 struct B { B* next; }; 5374 A<&B::next> a; 5375templateSpecializationType(hasAnyTemplateArgument( 5376 isExpr(hasDescendant(declRefExpr(to(fieldDecl(hasName("next")))))))) 5377 matches the specialization A<&B::next> with fieldDecl(...) matching 5378 B::next 5379</pre></td></tr> 5380 5381 5382<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 5383<tr><td colspan="4" class="doc" id="refersToDeclaration0"><pre>Matches a canonical TemplateArgument that refers to a certain 5384declaration. 5385 5386Given 5387 template<typename T> struct A {}; 5388 struct B { B* next; }; 5389 A<&B::next> a; 5390classTemplateSpecializationDecl(hasAnyTemplateArgument( 5391 refersToDeclaration(fieldDecl(hasName("next")))) 5392 matches the specialization A<&B::next> with fieldDecl(...) matching 5393 B::next 5394</pre></td></tr> 5395 5396 5397<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 5398<tr><td colspan="4" class="doc" id="refersToIntegralType0"><pre>Matches a TemplateArgument that referes to an integral type. 5399 5400Given 5401 template<int T> struct A {}; 5402 C<42> c; 5403classTemplateSpecializationDecl( 5404 hasAnyTemplateArgument(refersToIntegralType(asString("int")))) 5405 matches the implicit instantiation of C in C<42>. 5406</pre></td></tr> 5407 5408 5409<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1TemplateName.html">TemplateName</a>> InnerMatcher</td></tr> 5410<tr><td colspan="4" class="doc" id="refersToTemplate0"><pre>Matches a TemplateArgument that refers to a certain template. 5411 5412Given 5413 template<template <typename> class S> class X {}; 5414 template<typename T> class Y {};" 5415 X<Y> xi; 5416classTemplateSpecializationDecl(hasAnyTemplateArgument( 5417 refersToTemplate(templateName()))) 5418 matches the specialization X<Y> 5419</pre></td></tr> 5420 5421 5422<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 5423<tr><td colspan="4" class="doc" id="refersToType0"><pre>Matches a TemplateArgument that refers to a certain type. 5424 5425Given 5426 struct X {}; 5427 template<typename T> struct A {}; 5428 A<X> a; 5429classTemplateSpecializationDecl(hasAnyTemplateArgument( 5430 refersToType(class(hasName("X"))))) 5431 matches the specialization A<X> 5432</pre></td></tr> 5433 5434 5435<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr> 5436<tr><td colspan="4" class="doc" id="hasAnyTemplateArgument1"><pre>Matches classTemplateSpecializations, templateSpecializationType and 5437functionDecl that have at least one TemplateArgument matching the given 5438InnerMatcher. 5439 5440Given 5441 template<typename T> class A {}; 5442 template<> class A<double> {}; 5443 A<int> a; 5444 5445 template<typename T> f() {}; 5446 void func() { f<int>(); }; 5447 5448classTemplateSpecializationDecl(hasAnyTemplateArgument( 5449 refersToType(asString("int")))) 5450 matches the specialization A<int> 5451 5452functionDecl(hasAnyTemplateArgument(refersToType(asString("int")))) 5453 matches the specialization f<int> 5454</pre></td></tr> 5455 5456 5457<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>></td><td class="name" onclick="toggle('hasDeclaration3')"><a name="hasDeclaration3Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 5458<tr><td colspan="4" class="doc" id="hasDeclaration3"><pre>Matches a node if the declaration associated with that node 5459matches the given matcher. 5460 5461The associated declaration is: 5462- for type nodes, the declaration of the underlying type 5463- for CallExpr, the declaration of the callee 5464- for MemberExpr, the declaration of the referenced member 5465- for CXXConstructExpr, the declaration of the constructor 5466 5467Also usable as Matcher<T> for any T supporting the getDecl() member 5468function. e.g. various subtypes of clang::Type and various expressions. 5469 5470Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 5471 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 5472 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, 5473 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 5474 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 5475 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 5476</pre></td></tr> 5477 5478 5479<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html">TemplateArgument</a>> InnerMatcher</td></tr> 5480<tr><td colspan="4" class="doc" id="hasTemplateArgument1"><pre>Matches classTemplateSpecializations, templateSpecializationType and 5481functionDecl where the n'th TemplateArgument matches the given InnerMatcher. 5482 5483Given 5484 template<typename T, typename U> class A {}; 5485 A<bool, int> b; 5486 A<int, bool> c; 5487 5488 template<typename T> f() {}; 5489 void func() { f<int>(); }; 5490classTemplateSpecializationDecl(hasTemplateArgument( 5491 1, refersToType(asString("int")))) 5492 matches the specialization A<bool, int> 5493 5494functionDecl(hasTemplateArgument(0, refersToType(asString("int")))) 5495 matches the specialization f<int> 5496</pre></td></tr> 5497 5498 5499<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>></td><td class="name" onclick="toggle('hasDeclaration2')"><a name="hasDeclaration2Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 5500<tr><td colspan="4" class="doc" id="hasDeclaration2"><pre>Matches a node if the declaration associated with that node 5501matches the given matcher. 5502 5503The associated declaration is: 5504- for type nodes, the declaration of the underlying type 5505- for CallExpr, the declaration of the callee 5506- for MemberExpr, the declaration of the referenced member 5507- for CXXConstructExpr, the declaration of the constructor 5508 5509Also usable as Matcher<T> for any T supporting the getDecl() member 5510function. e.g. various subtypes of clang::Type and various expressions. 5511 5512Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 5513 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 5514 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, 5515 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 5516 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 5517 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 5518</pre></td></tr> 5519 5520 5521<tr><td>Matcher<T></td><td class="name" onclick="toggle('findAll0')"><a name="findAll0Anchor">findAll</a></td><td>Matcher<T> Matcher</td></tr> 5522<tr><td colspan="4" class="doc" id="findAll0"><pre>Matches if the node or any descendant matches. 5523 5524Generates results for each match. 5525 5526For example, in: 5527 class A { class B {}; class C {}; }; 5528The matcher: 5529 cxxRecordDecl(hasName("::A"), 5530 findAll(cxxRecordDecl(isDefinition()).bind("m"))) 5531will generate results for A, B and C. 5532 5533Usable as: Any Matcher 5534</pre></td></tr> 5535 5536 5537<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefNameDecl.html">TypedefNameDecl</a>></td><td class="name" onclick="toggle('hasType1')"><a name="hasType1Anchor">hasType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 5538<tr><td colspan="4" class="doc" id="hasType1"><pre>Matches if the expression's or declaration's type matches a type 5539matcher. 5540 5541Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) 5542 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) 5543 and U (matcher = typedefDecl(hasType(asString("int"))) 5544 class X {}; 5545 void y(X &x) { x; X z; } 5546 typedef int U; 5547</pre></td></tr> 5548 5549 5550<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>></td><td class="name" onclick="toggle('hasDeclaration1')"><a name="hasDeclaration1Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 5551<tr><td colspan="4" class="doc" id="hasDeclaration1"><pre>Matches a node if the declaration associated with that node 5552matches the given matcher. 5553 5554The associated declaration is: 5555- for type nodes, the declaration of the underlying type 5556- for CallExpr, the declaration of the callee 5557- for MemberExpr, the declaration of the referenced member 5558- for CXXConstructExpr, the declaration of the constructor 5559 5560Also usable as Matcher<T> for any T supporting the getDecl() member 5561function. e.g. various subtypes of clang::Type and various expressions. 5562 5563Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 5564 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 5565 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, 5566 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 5567 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 5568 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 5569</pre></td></tr> 5570 5571 5572<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 5573<tr><td colspan="4" class="doc" id="hasArgumentOfType0"><pre>Matches unary expressions that have a specific type of argument. 5574 5575Given 5576 int a, c; float b; int s = sizeof(a) + sizeof(b) + alignof(c); 5577unaryExprOrTypeTraitExpr(hasArgumentOfType(asString("int")) 5578 matches sizeof(a) and alignof(c) 5579</pre></td></tr> 5580 5581 5582<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 5583<tr><td colspan="4" class="doc" id="hasUnaryOperand0"><pre>Matches if the operand of a unary operator matches. 5584 5585Example matches true (matcher = hasUnaryOperand( 5586 cxxBoolLiteral(equals(true)))) 5587 !true 5588</pre></td></tr> 5589 5590 5591<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>></td><td class="name" onclick="toggle('hasDeclaration0')"><a name="hasDeclaration0Anchor">hasDeclaration</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 5592<tr><td colspan="4" class="doc" id="hasDeclaration0"><pre>Matches a node if the declaration associated with that node 5593matches the given matcher. 5594 5595The associated declaration is: 5596- for type nodes, the declaration of the underlying type 5597- for CallExpr, the declaration of the callee 5598- for MemberExpr, the declaration of the referenced member 5599- for CXXConstructExpr, the declaration of the constructor 5600 5601Also usable as Matcher<T> for any T supporting the getDecl() member 5602function. e.g. various subtypes of clang::Type and various expressions. 5603 5604Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CallExpr.html">CallExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html">CXXConstructExpr</a>>, 5605 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1DeclRefExpr.html">DeclRefExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumType.html">EnumType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1InjectedClassNameType.html">InjectedClassNameType</a>>, 5606 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1LabelStmt.html">LabelStmt</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1AddrLabelExpr.html">AddrLabelExpr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html">MemberExpr</a>>, 5607 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1RecordType.html">RecordType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagType.html">TagType</a>>, 5608 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html">TemplateSpecializationType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateTypeParmType.html">TemplateTypeParmType</a>>, 5609 Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TypedefType.html">TypedefType</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedUsingType.html">UnresolvedUsingType</a>> 5610</pre></td></tr> 5611 5612 5613<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1UsingShadowDecl.html">UsingShadowDecl</a>> InnerMatcher</td></tr> 5614<tr><td colspan="4" class="doc" id="hasAnyUsingShadowDecl0"><pre>Matches any using shadow declaration. 5615 5616Given 5617 namespace X { void b(); } 5618 using X::b; 5619usingDecl(hasAnyUsingShadowDecl(hasName("b")))) 5620 matches using X::b </pre></td></tr> 5621 5622 5623<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>> InnerMatcher</td></tr> 5624<tr><td colspan="4" class="doc" id="hasTargetDecl0"><pre>Matches a using shadow declaration where the target declaration is 5625matched by the given matcher. 5626 5627Given 5628 namespace X { int a; void b(); } 5629 using X::a; 5630 using X::b; 5631usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(functionDecl()))) 5632 matches using X::b but not using X::a </pre></td></tr> 5633 5634 5635<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</a>></td><td class="name" onclick="toggle('hasType4')"><a name="hasType4Anchor">hasType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>> InnerMatcher</td></tr> 5636<tr><td colspan="4" class="doc" id="hasType4"><pre>Overloaded to match the declaration of the expression's or value 5637declaration's type. 5638 5639In case of a value declaration (for example a variable declaration), 5640this resolves one layer of indirection. For example, in the value 5641declaration "X x;", cxxRecordDecl(hasName("X")) matches the declaration of 5642X, while varDecl(hasType(cxxRecordDecl(hasName("X")))) matches the 5643declaration of x. 5644 5645Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) 5646 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) 5647 class X {}; 5648 void y(X &x) { x; X z; } 5649 5650Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>>, Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</a>> 5651</pre></td></tr> 5652 5653 5654<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ValueDecl.html">ValueDecl</a>></td><td class="name" onclick="toggle('hasType2')"><a name="hasType2Anchor">hasType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 5655<tr><td colspan="4" class="doc" id="hasType2"><pre>Matches if the expression's or declaration's type matches a type 5656matcher. 5657 5658Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) 5659 and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) 5660 and U (matcher = typedefDecl(hasType(asString("int"))) 5661 class X {}; 5662 void y(X &x) { x; X z; } 5663 typedef int U; 5664</pre></td></tr> 5665 5666 5667<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 5668<tr><td colspan="4" class="doc" id="hasInitializer0"><pre>Matches a variable declaration that has an initializer expression 5669that matches the given matcher. 5670 5671Example matches x (matcher = varDecl(hasInitializer(callExpr()))) 5672 bool y() { return true; } 5673 bool x = y(); 5674</pre></td></tr> 5675 5676 5677<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 5678<tr><td colspan="4" class="doc" id="hasSizeExpr0"><pre>Matches VariableArrayType nodes that have a specific size 5679expression. 5680 5681Given 5682 void f(int b) { 5683 int a[b]; 5684 } 5685variableArrayType(hasSizeExpr(ignoringImpCasts(declRefExpr(to( 5686 varDecl(hasName("b"))))))) 5687 matches "int a[b]" 5688</pre></td></tr> 5689 5690 5691<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>> InnerMatcher</td></tr> 5692<tr><td colspan="4" class="doc" id="hasBody2"><pre>Matches a 'for', 'while', 'do while' statement or a function 5693definition that has a given body. 5694 5695Given 5696 for (;;) {} 5697hasBody(compoundStmt()) 5698 matches 'for (;;) {}' 5699with compoundStmt() 5700 matching '{}' 5701</pre></td></tr> 5702 5703 5704<tr><td>Matcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> 5705<tr><td colspan="4" class="doc" id="hasCondition2"><pre>Matches the condition expression of an if statement, for loop, 5706switch statement or conditional operator. 5707 5708Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true)))) 5709 if (true) {} 5710</pre></td></tr> 5711 5712 5713<tr><td>Matcher<internal::BindableMatcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifier.html">NestedNameSpecifier</a>> InnerMatcher</td></tr> 5714<tr><td colspan="4" class="doc" id="loc1"><pre>Matches NestedNameSpecifierLocs for which the given inner 5715NestedNameSpecifier-matcher matches. 5716</pre></td></tr> 5717 5718 5719<tr><td>Matcher<internal::BindableMatcher<<a href="http://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="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>> InnerMatcher</td></tr> 5720<tr><td colspan="4" class="doc" id="loc0"><pre>Matches TypeLocs for which the given inner 5721QualType-matcher matches. 5722</pre></td></tr> 5723 5724<!--END_TRAVERSAL_MATCHERS --> 5725</table> 5726 5727</div> 5728</body> 5729</html> 5730 5731 5732