Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / unittests / Tooling / RecursiveASTVisitorTests / ImplicitCtor.cpp
blob27999e5ef8efcbfc20e513b4f739f947c13c963f
1 //===- unittest/Tooling/RecursiveASTVisitorTests/ImplicitCtor.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 // A visitor that visits implicit declarations and matches constructors.
16 class ImplicitCtorVisitor
17 : public ExpectedLocationVisitor<ImplicitCtorVisitor> {
18 public:
19 bool shouldVisitImplicitCode() const { return true; }
21 bool VisitCXXConstructorDecl(CXXConstructorDecl* Ctor) {
22 if (Ctor->isImplicit()) { // Was not written in source code
23 if (const CXXRecordDecl* Class = Ctor->getParent()) {
24 Match(Class->getName(), Ctor->getLocation());
27 return true;
31 TEST(RecursiveASTVisitor, VisitsImplicitCopyConstructors) {
32 ImplicitCtorVisitor Visitor;
33 Visitor.ExpectMatch("Simple", 2, 8);
34 // Note: Clang lazily instantiates implicit declarations, so we need
35 // to use them in order to force them to appear in the AST.
36 EXPECT_TRUE(Visitor.runOver(
37 "struct WithCtor { WithCtor(); }; \n"
38 "struct Simple { Simple(); WithCtor w; }; \n"
39 "int main() { Simple s; Simple t(s); }\n"));
42 } // end anonymous namespace