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
: public ExpectedLocationVisitor
{
17 bool VisitCXXMemberCallExpr(CXXMemberCallExpr
*Call
) override
{
18 Match(Call
->getMethodDecl()->getQualifiedNameAsString(),
24 TEST(RecursiveASTVisitor
, VisitsCallInTemplateInstantiation
) {
25 CXXMemberCallVisitor Visitor
;
26 Visitor
.ExpectMatch("Y::x", 3, 3);
27 EXPECT_TRUE(Visitor
.runOver(
28 "struct Y { void x(); };\n"
29 "template<typename T> void y(T t) {\n"
32 "void foo() { y<Y>(Y()); }"));
35 TEST(RecursiveASTVisitor
, VisitsCallInNestedFunctionTemplateInstantiation
) {
36 CXXMemberCallVisitor Visitor
;
37 Visitor
.ExpectMatch("Y::x", 4, 5);
38 EXPECT_TRUE(Visitor
.runOver(
39 "struct Y { void x(); };\n"
40 "template<typename T> struct Z {\n"
41 " template<typename U> static void f() {\n"
45 "void foo() { Z<Y>::f<int>(); }"));
48 TEST(RecursiveASTVisitor
, VisitsCallInNestedClassTemplateInstantiation
) {
49 CXXMemberCallVisitor Visitor
;
50 Visitor
.ExpectMatch("A::x", 5, 7);
51 EXPECT_TRUE(Visitor
.runOver(
52 "template <typename T1> struct X {\n"
53 " template <typename T2> struct Y {\n"
60 "struct A { void x(); };\n"
62 " (new X<A>::Y<A>())->f();\n"
66 TEST(RecursiveASTVisitor
, VisitsCallInPartialTemplateSpecialization
) {
67 CXXMemberCallVisitor Visitor
;
68 Visitor
.ExpectMatch("A::x", 6, 20);
69 EXPECT_TRUE(Visitor
.runOver(
70 "template <typename T1> struct X {\n"
71 " template <typename T2, bool B> struct Y { void g(); };\n"
73 "template <typename T1> template <typename T2>\n"
74 "struct X<T1>::Y<T2, true> {\n"
75 " void f() { T2 y; y.x(); }\n"
77 "struct A { void x(); };\n"
79 " (new X<A>::Y<A, true>())->f();\n"
83 TEST(RecursiveASTVisitor
, VisitsExplicitTemplateSpecialization
) {
84 CXXMemberCallVisitor Visitor
;
85 Visitor
.ExpectMatch("A::f", 4, 5);
86 EXPECT_TRUE(Visitor
.runOver(
88 " void f() const {}\n"
89 " template<class T> void g(const T& t) const {\n"
93 "template void A::g(const A& a) const;\n"));
96 } // end anonymous namespace