[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / clang / unittests / Tooling / RecursiveASTVisitorTests / ImplicitCtorInitializer.cpp
blobae952c33bfe78b26a23172cd1b21b772bc5df2bb
1 //=- unittest/Tooling/RecursiveASTVisitorTests/ImplicitCtorInitializer.cpp -=//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 #include "TestVisitor.h"
11 using namespace clang;
13 namespace {
15 class CXXCtorInitializerVisitor : public ExpectedLocationVisitor {
16 public:
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
33 // visited.
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(
39 class A {};
40 class B : public A {
41 B() {};
43 class C : public A {
44 C() : A() {}
46 )cpp";
47 EXPECT_TRUE(Visitor.runOver(Code, CXXCtorInitializerVisitor::Lang_CXX));
48 EXPECT_EQ(Visitor.VisitedImplicitInitializer, VisitImplCode);
51 } // end anonymous namespace