1 //===- unittest/Tooling/RecursiveASTVisitorTests/CXXMemberCall.cpp --------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "TestVisitor.h"
11 using namespace clang
;
15 class CXXMemberCallVisitor
16 : public ExpectedLocationVisitor
<CXXMemberCallVisitor
> {
18 bool VisitCXXMemberCallExpr(CXXMemberCallExpr
*Call
) {
19 Match(Call
->getMethodDecl()->getQualifiedNameAsString(),
25 TEST(RecursiveASTVisitor
, VisitsCallInTemplateInstantiation
) {
26 CXXMemberCallVisitor Visitor
;
27 Visitor
.ExpectMatch("Y::x", 3, 3);
28 EXPECT_TRUE(Visitor
.runOver(
29 "struct Y { void x(); };\n"
30 "template<typename T> void y(T t) {\n"
33 "void foo() { y<Y>(Y()); }"));
36 TEST(RecursiveASTVisitor
, VisitsCallInNestedFunctionTemplateInstantiation
) {
37 CXXMemberCallVisitor Visitor
;
38 Visitor
.ExpectMatch("Y::x", 4, 5);
39 EXPECT_TRUE(Visitor
.runOver(
40 "struct Y { void x(); };\n"
41 "template<typename T> struct Z {\n"
42 " template<typename U> static void f() {\n"
46 "void foo() { Z<Y>::f<int>(); }"));
49 TEST(RecursiveASTVisitor
, VisitsCallInNestedClassTemplateInstantiation
) {
50 CXXMemberCallVisitor Visitor
;
51 Visitor
.ExpectMatch("A::x", 5, 7);
52 EXPECT_TRUE(Visitor
.runOver(
53 "template <typename T1> struct X {\n"
54 " template <typename T2> struct Y {\n"
61 "struct A { void x(); };\n"
63 " (new X<A>::Y<A>())->f();\n"
67 TEST(RecursiveASTVisitor
, VisitsCallInPartialTemplateSpecialization
) {
68 CXXMemberCallVisitor Visitor
;
69 Visitor
.ExpectMatch("A::x", 6, 20);
70 EXPECT_TRUE(Visitor
.runOver(
71 "template <typename T1> struct X {\n"
72 " template <typename T2, bool B> struct Y { void g(); };\n"
74 "template <typename T1> template <typename T2>\n"
75 "struct X<T1>::Y<T2, true> {\n"
76 " void f() { T2 y; y.x(); }\n"
78 "struct A { void x(); };\n"
80 " (new X<A>::Y<A, true>())->f();\n"
84 TEST(RecursiveASTVisitor
, VisitsExplicitTemplateSpecialization
) {
85 CXXMemberCallVisitor Visitor
;
86 Visitor
.ExpectMatch("A::f", 4, 5);
87 EXPECT_TRUE(Visitor
.runOver(
89 " void f() const {}\n"
90 " template<class T> void g(const T& t) const {\n"
94 "template void A::g(const A& a) const;\n"));
97 } // end anonymous namespace