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
: public ExpectedLocationVisitor
{
17 CXXCtorInitializerVisitor(bool VisitImplicitCode
) {
18 ShouldVisitImplicitCode
= VisitImplicitCode
;
21 bool TraverseConstructorInitializer(CXXCtorInitializer
*Init
) override
{
22 if (!Init
->isWritten())
23 VisitedImplicitInitializer
= true;
24 Match("initializer", Init
->getSourceLocation());
25 return ExpectedLocationVisitor::TraverseConstructorInitializer(Init
);
28 bool VisitedImplicitInitializer
= false;
31 // Check to ensure that CXXCtorInitializer is not visited when implicit code
32 // should not be visited and that it is visited when implicit code should be
34 TEST(RecursiveASTVisitor
, CXXCtorInitializerVisitNoImplicit
) {
35 for (bool VisitImplCode
: {true, false}) {
36 CXXCtorInitializerVisitor
Visitor(VisitImplCode
);
37 Visitor
.ExpectMatch("initializer", 7, 17);
38 llvm::StringRef Code
= R
"cpp(
47 EXPECT_TRUE(Visitor
.runOver(Code
, CXXCtorInitializerVisitor::Lang_CXX
));
48 EXPECT_EQ(Visitor
.VisitedImplicitInitializer
, VisitImplCode
);
51 } // end anonymous namespace