Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / unittests / Tooling / RecursiveASTVisitorTests / ImplicitCtorInitializer.cpp
blobc762e1cffc36864b2c5a382c1bbf72274e5b4663
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
16 : public ExpectedLocationVisitor<CXXCtorInitializerVisitor> {
17 public:
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;
33 private:
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
39 // visited.
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(
45 class A {};
46 class B : public A {
47 B() {};
49 class C : public A {
50 C() : A() {}
52 )cpp";
53 EXPECT_TRUE(Visitor.runOver(Code, CXXCtorInitializerVisitor::Lang_CXX));
54 EXPECT_EQ(Visitor.VisitedImplicitInitializer, VisitImplCode);
57 } // end anonymous namespace