1 //===- unittest/AST/SourceLocationTest.cpp - AST source loc unit tests ----===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains tests for SourceLocation and SourceRange fields
11 // in AST nodes.
12 //
13 // FIXME: In the long-term, when we test more than source locations, we may
14 // want to have a unit test file for an AST node (or group of related nodes),
15 // rather than a unit test file for source locations for all AST nodes.
16 //
17 //===----------------------------------------------------------------------===//
18 
19 #include "clang/AST/ASTContext.h"
20 #include "MatchVerifier.h"
21 #include "clang/ASTMatchers/ASTMatchFinder.h"
22 #include "clang/ASTMatchers/ASTMatchers.h"
23 #include "clang/Tooling/Tooling.h"
24 #include "gtest/gtest.h"
25 
26 namespace clang {
27 namespace ast_matchers {
28 
29 // FIXME: Pull the *Verifier tests into their own test file.
30 
TEST(MatchVerifier,ParseError)31 TEST(MatchVerifier, ParseError) {
32   LocationVerifier<VarDecl> Verifier;
33   Verifier.expectLocation(1, 1);
34   EXPECT_FALSE(Verifier.match("int i", varDecl()));
35 }
36 
TEST(MatchVerifier,NoMatch)37 TEST(MatchVerifier, NoMatch) {
38   LocationVerifier<VarDecl> Verifier;
39   Verifier.expectLocation(1, 1);
40   EXPECT_FALSE(Verifier.match("int i;", recordDecl()));
41 }
42 
TEST(MatchVerifier,WrongType)43 TEST(MatchVerifier, WrongType) {
44   LocationVerifier<RecordDecl> Verifier;
45   Verifier.expectLocation(1, 1);
46   EXPECT_FALSE(Verifier.match("int i;", varDecl()));
47 }
48 
TEST(LocationVerifier,WrongLocation)49 TEST(LocationVerifier, WrongLocation) {
50   LocationVerifier<VarDecl> Verifier;
51   Verifier.expectLocation(1, 1);
52   EXPECT_FALSE(Verifier.match("int i;", varDecl()));
53 }
54 
TEST(RangeVerifier,WrongRange)55 TEST(RangeVerifier, WrongRange) {
56   RangeVerifier<VarDecl> Verifier;
57   Verifier.expectRange(1, 1, 1, 1);
58   EXPECT_FALSE(Verifier.match("int i;", varDecl()));
59 }
60 
61 class LabelDeclRangeVerifier : public RangeVerifier<LabelStmt> {
62 protected:
getRange(const LabelStmt & Node)63   SourceRange getRange(const LabelStmt &Node) override {
64     return Node.getDecl()->getSourceRange();
65   }
66 };
67 
TEST(LabelDecl,Range)68 TEST(LabelDecl, Range) {
69   LabelDeclRangeVerifier Verifier;
70   Verifier.expectRange(1, 12, 1, 12);
71   EXPECT_TRUE(Verifier.match("void f() { l: return; }", labelStmt()));
72 }
73 
TEST(LabelStmt,Range)74 TEST(LabelStmt, Range) {
75   RangeVerifier<LabelStmt> Verifier;
76   Verifier.expectRange(1, 12, 1, 15);
77   EXPECT_TRUE(Verifier.match("void f() { l: return; }", labelStmt()));
78 }
79 
TEST(ParmVarDecl,KNRLocation)80 TEST(ParmVarDecl, KNRLocation) {
81   LocationVerifier<ParmVarDecl> Verifier;
82   Verifier.expectLocation(1, 8);
83   EXPECT_TRUE(Verifier.match("void f(i) {}", varDecl(), Lang_C));
84 }
85 
TEST(ParmVarDecl,KNRRange)86 TEST(ParmVarDecl, KNRRange) {
87   RangeVerifier<ParmVarDecl> Verifier;
88   Verifier.expectRange(1, 8, 1, 8);
89   EXPECT_TRUE(Verifier.match("void f(i) {}", varDecl(), Lang_C));
90 }
91 
TEST(CXXNewExpr,ArrayRange)92 TEST(CXXNewExpr, ArrayRange) {
93   RangeVerifier<CXXNewExpr> Verifier;
94   Verifier.expectRange(1, 12, 1, 22);
95   EXPECT_TRUE(Verifier.match("void f() { new int[10]; }", newExpr()));
96 }
97 
TEST(CXXNewExpr,ParenRange)98 TEST(CXXNewExpr, ParenRange) {
99   RangeVerifier<CXXNewExpr> Verifier;
100   Verifier.expectRange(1, 12, 1, 20);
101   EXPECT_TRUE(Verifier.match("void f() { new int(); }", newExpr()));
102 }
103 
TEST(MemberExpr,ImplicitMemberRange)104 TEST(MemberExpr, ImplicitMemberRange) {
105   RangeVerifier<MemberExpr> Verifier;
106   Verifier.expectRange(2, 30, 2, 30);
107   EXPECT_TRUE(Verifier.match("struct S { operator int() const; };\n"
108                              "int foo(const S& s) { return s; }",
109                              memberExpr()));
110 }
111 
112 class MemberExprArrowLocVerifier : public RangeVerifier<MemberExpr> {
113 protected:
getRange(const MemberExpr & Node)114   SourceRange getRange(const MemberExpr &Node) override {
115      return Node.getOperatorLoc();
116   }
117 };
118 
TEST(MemberExpr,ArrowRange)119 TEST(MemberExpr, ArrowRange) {
120   MemberExprArrowLocVerifier Verifier;
121   Verifier.expectRange(2, 19, 2, 19);
122   EXPECT_TRUE(Verifier.match("struct S { int x; };\n"
123                              "void foo(S *s) { s->x = 0; }",
124                              memberExpr()));
125 }
126 
TEST(MemberExpr,MacroArrowRange)127 TEST(MemberExpr, MacroArrowRange) {
128   MemberExprArrowLocVerifier Verifier;
129   Verifier.expectRange(1, 24, 1, 24);
130   EXPECT_TRUE(Verifier.match("#define MEMBER(a, b) (a->b)\n"
131                              "struct S { int x; };\n"
132                              "void foo(S *s) { MEMBER(s, x) = 0; }",
133                              memberExpr()));
134 }
135 
TEST(MemberExpr,ImplicitArrowRange)136 TEST(MemberExpr, ImplicitArrowRange) {
137   MemberExprArrowLocVerifier Verifier;
138   Verifier.expectRange(0, 0, 0, 0);
139   EXPECT_TRUE(Verifier.match("struct S { int x; void Test(); };\n"
140                              "void S::Test() { x = 1; }",
141                              memberExpr()));
142 }
143 
TEST(VarDecl,VMTypeFixedVarDeclRange)144 TEST(VarDecl, VMTypeFixedVarDeclRange) {
145   RangeVerifier<VarDecl> Verifier;
146   Verifier.expectRange(1, 1, 1, 23);
147   EXPECT_TRUE(Verifier.match("int a[(int)(void*)1234];",
148                              varDecl(), Lang_C89));
149 }
150 
TEST(CXXConstructorDecl,NoRetFunTypeLocRange)151 TEST(CXXConstructorDecl, NoRetFunTypeLocRange) {
152   RangeVerifier<CXXConstructorDecl> Verifier;
153   Verifier.expectRange(1, 11, 1, 13);
154   EXPECT_TRUE(Verifier.match("class C { C(); };", functionDecl()));
155 }
156 
TEST(CXXConstructorDecl,DefaultedCtorLocRange)157 TEST(CXXConstructorDecl, DefaultedCtorLocRange) {
158   RangeVerifier<CXXConstructorDecl> Verifier;
159   Verifier.expectRange(1, 11, 1, 23);
160   EXPECT_TRUE(Verifier.match("class C { C() = default; };", functionDecl()));
161 }
162 
TEST(CXXConstructorDecl,DeletedCtorLocRange)163 TEST(CXXConstructorDecl, DeletedCtorLocRange) {
164   RangeVerifier<CXXConstructorDecl> Verifier;
165   Verifier.expectRange(1, 11, 1, 22);
166   EXPECT_TRUE(Verifier.match("class C { C() = delete; };", functionDecl()));
167 }
168 
TEST(CompoundLiteralExpr,CompoundVectorLiteralRange)169 TEST(CompoundLiteralExpr, CompoundVectorLiteralRange) {
170   RangeVerifier<CompoundLiteralExpr> Verifier;
171   Verifier.expectRange(2, 11, 2, 22);
172   EXPECT_TRUE(Verifier.match(
173                   "typedef int int2 __attribute__((ext_vector_type(2)));\n"
174                   "int2 i2 = (int2){1, 2};", compoundLiteralExpr()));
175 }
176 
TEST(CompoundLiteralExpr,ParensCompoundVectorLiteralRange)177 TEST(CompoundLiteralExpr, ParensCompoundVectorLiteralRange) {
178   RangeVerifier<CompoundLiteralExpr> Verifier;
179   Verifier.expectRange(2, 20, 2, 31);
180   EXPECT_TRUE(Verifier.match(
181                   "typedef int int2 __attribute__((ext_vector_type(2)));\n"
182                   "constant int2 i2 = (int2)(1, 2);",
183                   compoundLiteralExpr(), Lang_OpenCL));
184 }
185 
TEST(InitListExpr,VectorLiteralListBraceRange)186 TEST(InitListExpr, VectorLiteralListBraceRange) {
187   RangeVerifier<InitListExpr> Verifier;
188   Verifier.expectRange(2, 17, 2, 22);
189   EXPECT_TRUE(Verifier.match(
190                   "typedef int int2 __attribute__((ext_vector_type(2)));\n"
191                   "int2 i2 = (int2){1, 2};", initListExpr()));
192 }
193 
TEST(InitListExpr,VectorLiteralInitListParens)194 TEST(InitListExpr, VectorLiteralInitListParens) {
195   RangeVerifier<InitListExpr> Verifier;
196   Verifier.expectRange(2, 26, 2, 31);
197   EXPECT_TRUE(Verifier.match(
198                   "typedef int int2 __attribute__((ext_vector_type(2)));\n"
199                   "constant int2 i2 = (int2)(1, 2);", initListExpr(), Lang_OpenCL));
200 }
201 
202 class TemplateAngleBracketLocRangeVerifier : public RangeVerifier<TypeLoc> {
203 protected:
getRange(const TypeLoc & Node)204   SourceRange getRange(const TypeLoc &Node) override {
205     TemplateSpecializationTypeLoc T =
206         Node.getUnqualifiedLoc().castAs<TemplateSpecializationTypeLoc>();
207     assert(!T.isNull());
208     return SourceRange(T.getLAngleLoc(), T.getRAngleLoc());
209   }
210 };
211 
TEST(TemplateSpecializationTypeLoc,AngleBracketLocations)212 TEST(TemplateSpecializationTypeLoc, AngleBracketLocations) {
213   TemplateAngleBracketLocRangeVerifier Verifier;
214   Verifier.expectRange(2, 8, 2, 10);
215   EXPECT_TRUE(Verifier.match(
216       "template<typename T> struct A {}; struct B{}; void f(\n"
217       "const A<B>&);",
218       loc(templateSpecializationType())));
219 }
220 
TEST(CXXNewExpr,TypeParenRange)221 TEST(CXXNewExpr, TypeParenRange) {
222   RangeVerifier<CXXNewExpr> Verifier;
223   Verifier.expectRange(1, 10, 1, 18);
224   EXPECT_TRUE(Verifier.match("int* a = new (int);", newExpr()));
225 }
226 
227 class UnaryTransformTypeLocParensRangeVerifier : public RangeVerifier<TypeLoc> {
228 protected:
getRange(const TypeLoc & Node)229   SourceRange getRange(const TypeLoc &Node) override {
230     UnaryTransformTypeLoc T =
231         Node.getUnqualifiedLoc().castAs<UnaryTransformTypeLoc>();
232     assert(!T.isNull());
233     return SourceRange(T.getLParenLoc(), T.getRParenLoc());
234   }
235 };
236 
TEST(UnaryTransformTypeLoc,ParensRange)237 TEST(UnaryTransformTypeLoc, ParensRange) {
238   UnaryTransformTypeLocParensRangeVerifier Verifier;
239   Verifier.expectRange(3, 26, 3, 28);
240   EXPECT_TRUE(Verifier.match(
241       "template <typename T>\n"
242       "struct S {\n"
243       "typedef __underlying_type(T) type;\n"
244       "};",
245       loc(unaryTransformType())));
246 }
247 
TEST(CXXFunctionalCastExpr,SourceRange)248 TEST(CXXFunctionalCastExpr, SourceRange) {
249   RangeVerifier<CXXFunctionalCastExpr> Verifier;
250   Verifier.expectRange(2, 10, 2, 14);
251   EXPECT_TRUE(Verifier.match(
252       "int foo() {\n"
253       "  return int{};\n"
254       "}",
255       functionalCastExpr(), Lang_CXX11));
256 }
257 
TEST(CXXConstructExpr,SourceRange)258 TEST(CXXConstructExpr, SourceRange) {
259   RangeVerifier<CXXConstructExpr> Verifier;
260   Verifier.expectRange(3, 14, 3, 19);
261   EXPECT_TRUE(Verifier.match(
262       "struct A { A(int, int); };\n"
263       "void f(A a);\n"
264       "void g() { f({0, 0}); }",
265       constructExpr(), Lang_CXX11));
266 }
267 
TEST(CXXTemporaryObjectExpr,SourceRange)268 TEST(CXXTemporaryObjectExpr, SourceRange) {
269   RangeVerifier<CXXTemporaryObjectExpr> Verifier;
270   Verifier.expectRange(2, 6, 2, 12);
271   EXPECT_TRUE(Verifier.match(
272       "struct A { A(int, int); };\n"
273       "A a( A{0, 0} );",
274       temporaryObjectExpr(), Lang_CXX11));
275 }
276 
TEST(CXXUnresolvedConstructExpr,SourceRange)277 TEST(CXXUnresolvedConstructExpr, SourceRange) {
278   RangeVerifier<CXXUnresolvedConstructExpr> Verifier;
279   Verifier.expectRange(3, 10, 3, 12);
280   std::vector<std::string> Args;
281   Args.push_back("-fno-delayed-template-parsing");
282   EXPECT_TRUE(Verifier.match(
283       "template <typename U>\n"
284       "U foo() {\n"
285       "  return U{};\n"
286       "}",
287       unresolvedConstructExpr(), Args, Lang_CXX11));
288 }
289 
TEST(UsingDecl,SourceRange)290 TEST(UsingDecl, SourceRange) {
291   RangeVerifier<UsingDecl> Verifier;
292   Verifier.expectRange(2, 22, 2, 25);
293   EXPECT_TRUE(Verifier.match(
294       "class B { protected: int i; };\n"
295       "class D : public B { B::i; };",
296       usingDecl()));
297 }
298 
TEST(UnresolvedUsingValueDecl,SourceRange)299 TEST(UnresolvedUsingValueDecl, SourceRange) {
300   RangeVerifier<UnresolvedUsingValueDecl> Verifier;
301   Verifier.expectRange(3, 3, 3, 6);
302   EXPECT_TRUE(Verifier.match(
303       "template <typename B>\n"
304       "class D : public B {\n"
305       "  B::i;\n"
306       "};",
307       unresolvedUsingValueDecl()));
308 }
309 
TEST(FriendDecl,FriendNonMemberFunctionLocation)310 TEST(FriendDecl, FriendNonMemberFunctionLocation) {
311   LocationVerifier<FriendDecl> Verifier;
312   Verifier.expectLocation(2, 13);
313   EXPECT_TRUE(Verifier.match("struct A {\n"
314                              "friend void f();\n"
315                              "};\n",
316                              friendDecl()));
317 }
318 
TEST(FriendDecl,FriendNonMemberFunctionRange)319 TEST(FriendDecl, FriendNonMemberFunctionRange) {
320   RangeVerifier<FriendDecl> Verifier;
321   Verifier.expectRange(2, 1, 2, 15);
322   EXPECT_TRUE(Verifier.match("struct A {\n"
323                              "friend void f();\n"
324                              "};\n",
325                              friendDecl()));
326 }
327 
TEST(FriendDecl,FriendNonMemberFunctionDefinitionLocation)328 TEST(FriendDecl, FriendNonMemberFunctionDefinitionLocation) {
329   LocationVerifier<FriendDecl> Verifier;
330   Verifier.expectLocation(2, 12);
331   EXPECT_TRUE(Verifier.match("struct A {\n"
332                              "friend int f() { return 0; }\n"
333                              "};\n",
334                              friendDecl()));
335 }
336 
TEST(FriendDecl,FriendNonMemberFunctionDefinitionRange)337 TEST(FriendDecl, FriendNonMemberFunctionDefinitionRange) {
338   RangeVerifier<FriendDecl> Verifier;
339   Verifier.expectRange(2, 1, 2, 28);
340   EXPECT_TRUE(Verifier.match("struct A {\n"
341                              "friend int f() { return 0; }\n"
342                              "};\n",
343                              friendDecl()));
344 }
345 
TEST(FriendDecl,FriendElaboratedTypeLocation)346 TEST(FriendDecl, FriendElaboratedTypeLocation) {
347   LocationVerifier<FriendDecl> Verifier;
348   Verifier.expectLocation(2, 8);
349   EXPECT_TRUE(Verifier.match("struct A {\n"
350                              "friend class B;\n"
351                              "};\n",
352                              friendDecl()));
353 }
354 
TEST(FriendDecl,FriendElaboratedTypeRange)355 TEST(FriendDecl, FriendElaboratedTypeRange) {
356   RangeVerifier<FriendDecl> Verifier;
357   Verifier.expectRange(2, 1, 2, 14);
358   EXPECT_TRUE(Verifier.match("struct A {\n"
359                              "friend class B;\n"
360                              "};\n",
361                              friendDecl()));
362 }
363 
TEST(FriendDecl,FriendSimpleTypeLocation)364 TEST(FriendDecl, FriendSimpleTypeLocation) {
365   LocationVerifier<FriendDecl> Verifier;
366   Verifier.expectLocation(3, 8);
367   EXPECT_TRUE(Verifier.match("class B;\n"
368                              "struct A {\n"
369                              "friend B;\n"
370                              "};\n",
371                              friendDecl(), Lang_CXX11));
372 }
373 
TEST(FriendDecl,FriendSimpleTypeRange)374 TEST(FriendDecl, FriendSimpleTypeRange) {
375   RangeVerifier<FriendDecl> Verifier;
376   Verifier.expectRange(3, 1, 3, 8);
377   EXPECT_TRUE(Verifier.match("class B;\n"
378                              "struct A {\n"
379                              "friend B;\n"
380                              "};\n",
381                              friendDecl(), Lang_CXX11));
382 }
383 
TEST(FriendDecl,FriendTemplateParameterLocation)384 TEST(FriendDecl, FriendTemplateParameterLocation) {
385   LocationVerifier<FriendDecl> Verifier;
386   Verifier.expectLocation(3, 8);
387   EXPECT_TRUE(Verifier.match("template <typename T>\n"
388                              "struct A {\n"
389                              "friend T;\n"
390                              "};\n",
391                              friendDecl(), Lang_CXX11));
392 }
393 
TEST(FriendDecl,FriendTemplateParameterRange)394 TEST(FriendDecl, FriendTemplateParameterRange) {
395   RangeVerifier<FriendDecl> Verifier;
396   Verifier.expectRange(3, 1, 3, 8);
397   EXPECT_TRUE(Verifier.match("template <typename T>\n"
398                              "struct A {\n"
399                              "friend T;\n"
400                              "};\n",
401                              friendDecl(), Lang_CXX11));
402 }
403 
TEST(FriendDecl,FriendDecltypeLocation)404 TEST(FriendDecl, FriendDecltypeLocation) {
405   LocationVerifier<FriendDecl> Verifier;
406   Verifier.expectLocation(4, 8);
407   EXPECT_TRUE(Verifier.match("struct A;\n"
408                              "A foo();\n"
409                              "struct A {\n"
410                              "friend decltype(foo());\n"
411                              "};\n",
412                              friendDecl(), Lang_CXX11));
413 }
414 
TEST(FriendDecl,FriendDecltypeRange)415 TEST(FriendDecl, FriendDecltypeRange) {
416   RangeVerifier<FriendDecl> Verifier;
417   Verifier.expectRange(4, 1, 4, 8);
418   EXPECT_TRUE(Verifier.match("struct A;\n"
419                              "A foo();\n"
420                              "struct A {\n"
421                              "friend decltype(foo());\n"
422                              "};\n",
423                              friendDecl(), Lang_CXX11));
424 }
425 
TEST(FriendDecl,FriendConstructorDestructorLocation)426 TEST(FriendDecl, FriendConstructorDestructorLocation) {
427   const std::string Code = "struct B {\n"
428                            "B();\n"
429                            "~B();\n"
430                            "};\n"
431                            "struct A {\n"
432                            "friend B::B(), B::~B();\n"
433                            "};\n";
434   LocationVerifier<FriendDecl> ConstructorVerifier;
435   ConstructorVerifier.expectLocation(6, 11);
436   EXPECT_TRUE(ConstructorVerifier.match(
437       Code, friendDecl(has(constructorDecl(ofClass(hasName("B")))))));
438   LocationVerifier<FriendDecl> DestructorVerifier;
439   DestructorVerifier.expectLocation(6, 19);
440   EXPECT_TRUE(DestructorVerifier.match(
441       Code, friendDecl(has(destructorDecl(ofClass(hasName("B")))))));
442 }
443 
TEST(FriendDecl,FriendConstructorDestructorRange)444 TEST(FriendDecl, FriendConstructorDestructorRange) {
445   const std::string Code = "struct B {\n"
446                            "B();\n"
447                            "~B();\n"
448                            "};\n"
449                            "struct A {\n"
450                            "friend B::B(), B::~B();\n"
451                            "};\n";
452   RangeVerifier<FriendDecl> ConstructorVerifier;
453   ConstructorVerifier.expectRange(6, 1, 6, 13);
454   EXPECT_TRUE(ConstructorVerifier.match(
455       Code, friendDecl(has(constructorDecl(ofClass(hasName("B")))))));
456   RangeVerifier<FriendDecl> DestructorVerifier;
457   DestructorVerifier.expectRange(6, 1, 6, 22);
458   EXPECT_TRUE(DestructorVerifier.match(
459       Code, friendDecl(has(destructorDecl(ofClass(hasName("B")))))));
460 }
461 
TEST(FriendDecl,FriendTemplateFunctionLocation)462 TEST(FriendDecl, FriendTemplateFunctionLocation) {
463   LocationVerifier<FriendDecl> Verifier;
464   Verifier.expectLocation(3, 13);
465   EXPECT_TRUE(Verifier.match("struct A {\n"
466                              "template <typename T>\n"
467                              "friend void f();\n"
468                              "};\n",
469                              friendDecl()));
470 }
471 
TEST(FriendDecl,FriendTemplateFunctionRange)472 TEST(FriendDecl, FriendTemplateFunctionRange) {
473   RangeVerifier<FriendDecl> Verifier;
474   Verifier.expectRange(2, 1, 3, 15);
475   EXPECT_TRUE(Verifier.match("struct A {\n"
476                              "template <typename T>\n"
477                              "friend void f();\n"
478                              "};\n",
479                              friendDecl()));
480 }
481 
TEST(FriendDecl,FriendTemplateClassLocation)482 TEST(FriendDecl, FriendTemplateClassLocation) {
483   LocationVerifier<FriendDecl> Verifier;
484   Verifier.expectLocation(3, 14);
485   EXPECT_TRUE(Verifier.match("struct A {\n"
486                              "template <typename T>\n"
487                              "friend class B;\n"
488                              "};\n",
489                              friendDecl()));
490 }
491 
TEST(FriendDecl,FriendTemplateClassRange)492 TEST(FriendDecl, FriendTemplateClassRange) {
493   RangeVerifier<FriendDecl> Verifier;
494   Verifier.expectRange(2, 1, 3, 14);
495   EXPECT_TRUE(Verifier.match("struct A {\n"
496                              "template <typename T>\n"
497                              "friend class B;\n"
498                              "};\n",
499                              friendDecl()));
500 }
501 
TEST(FriendDecl,FriendInlineFunctionLocation)502 TEST(FriendDecl, FriendInlineFunctionLocation) {
503   LocationVerifier<FriendDecl> Verifier;
504   Verifier.expectLocation(2, 19);
505   EXPECT_TRUE(Verifier.match("struct A {\n"
506                              "int inline friend f() { return 0; }"
507                              "};\n",
508                              friendDecl()));
509 }
510 
TEST(FriendDecl,FriendInlineFunctionRange)511 TEST(FriendDecl, FriendInlineFunctionRange) {
512   RangeVerifier<FriendDecl> Verifier;
513   Verifier.expectRange(2, 1, 2, 35);
514   EXPECT_TRUE(Verifier.match("struct A {\n"
515                              "int inline friend f() { return 0; }"
516                              "};\n",
517                              friendDecl(), Lang_CXX11));
518 }
519 
TEST(FriendDecl,InstantiationSourceRange)520 TEST(FriendDecl, InstantiationSourceRange) {
521   RangeVerifier<FriendDecl> Verifier;
522   Verifier.expectRange(4, 3, 4, 35);
523   EXPECT_TRUE(Verifier.match(
524       "template <typename T> class S;\n"
525       "template<class T> void operator+(S<T> x);\n"
526       "template<class T> struct S {\n"
527       "  friend void operator+<>(S<T> src);\n"
528       "};\n"
529       "void test(S<double> s) { +s; }",
530       friendDecl(hasParent(recordDecl(isTemplateInstantiation())))));
531 }
532 
TEST(ObjCMessageExpr,CXXConstructExprRange)533 TEST(ObjCMessageExpr, CXXConstructExprRange) {
534   RangeVerifier<CXXConstructExpr> Verifier;
535   Verifier.expectRange(5, 25, 5, 27);
536   EXPECT_TRUE(Verifier.match(
537       "struct A { int a; };\n"
538       "@interface B {}\n"
539       "+ (void) f1: (A)arg;\n"
540       "@end\n"
541       "void f2() { A a; [B f1: (a)]; }\n",
542       constructExpr(), Lang_OBJCXX));
543 }
544 
545 } // end namespace ast_matchers
546 } // end namespace clang
547