1 //=- unittest/Tooling/RecursiveASTVisitorTests/ImplicitCtorInitializer.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 CXXCtorInitializerVisitor
16 : public ExpectedLocationVisitor
<CXXCtorInitializerVisitor
> {
18 CXXCtorInitializerVisitor(bool VisitImplicitCode
)
19 : VisitImplicitCode(VisitImplicitCode
) {}
21 bool shouldVisitImplicitCode() const { return VisitImplicitCode
; }
23 bool TraverseConstructorInitializer(CXXCtorInitializer
*Init
) {
24 if (!Init
->isWritten())
25 VisitedImplicitInitializer
= true;
26 Match("initializer", Init
->getSourceLocation());
27 return ExpectedLocationVisitor
<
28 CXXCtorInitializerVisitor
>::TraverseConstructorInitializer(Init
);
31 bool VisitedImplicitInitializer
= false;
34 bool VisitImplicitCode
;
37 // Check to ensure that CXXCtorInitializer is not visited when implicit code
38 // should not be visited and that it is visited when implicit code should be
40 TEST(RecursiveASTVisitor
, CXXCtorInitializerVisitNoImplicit
) {
41 for (bool VisitImplCode
: {true, false}) {
42 CXXCtorInitializerVisitor
Visitor(VisitImplCode
);
43 Visitor
.ExpectMatch("initializer", 7, 17);
44 llvm::StringRef Code
= R
"cpp(
53 EXPECT_TRUE(Visitor
.runOver(Code
, CXXCtorInitializerVisitor::Lang_CXX
));
54 EXPECT_EQ(Visitor
.VisitedImplicitInitializer
, VisitImplCode
);
57 } // end anonymous namespace