1 //=------ unittest/Tooling/RecursiveASTVisitorTests/CXXMethodDecl.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"
10 #include "clang/AST/Expr.h"
12 using namespace clang
;
16 class CXXMethodDeclVisitor
: public ExpectedLocationVisitor
{
18 CXXMethodDeclVisitor(bool VisitImplicitCode
) {
19 ShouldVisitImplicitCode
= VisitImplicitCode
;
22 bool VisitDeclRefExpr(DeclRefExpr
*D
) override
{
23 Match("declref", D
->getLocation());
27 bool VisitParmVarDecl(ParmVarDecl
*P
) override
{
28 Match("parm", P
->getLocation());
33 TEST(RecursiveASTVisitor
, CXXMethodDeclNoDefaultBodyVisited
) {
34 for (bool VisitImplCode
: {false, true}) {
35 CXXMethodDeclVisitor
Visitor(VisitImplCode
);
37 Visitor
.ExpectMatch("declref", 8, 28);
39 Visitor
.DisallowMatch("declref", 8, 28);
41 Visitor
.ExpectMatch("parm", 8, 27);
42 llvm::StringRef Code
= R
"cpp(
49 A &A::operator=(A &&O) = default;
51 EXPECT_TRUE(Visitor
.runOver(Code
, CXXMethodDeclVisitor::Lang_CXX11
));
55 TEST(RecursiveASTVisitor
, FunctionDeclNoDefaultBodyVisited
) {
56 for (bool VisitImplCode
: {false, true}) {
57 CXXMethodDeclVisitor
Visitor(VisitImplCode
);
59 Visitor
.ExpectMatch("declref", 4, 58, /*Times=*/2);
61 Visitor
.DisallowMatch("declref", 4, 58);
62 llvm::StringRef Code
= R
"cpp(
65 friend auto operator==(s a, s b) -> bool = default;
67 bool k = s() == s(); // make sure clang generates the "==" definition.
69 EXPECT_TRUE(Visitor
.runOver(Code
, CXXMethodDeclVisitor::Lang_CXX2a
));
72 } // end anonymous namespace