diff options
author | Dmitri Gribenko <gribozavr@gmail.com> | 2019-08-30 09:29:34 +0000 |
---|---|---|
committer | Dmitri Gribenko <gribozavr@gmail.com> | 2019-08-30 09:29:34 +0000 |
commit | b22804b35464049ca92107d45042d2a5bbd292f6 (patch) | |
tree | 4e29b283156209efc4945de2129c9f8ad878d28f /clang/unittests | |
parent | 12a7e6c09cda7fd0259be85c949cf87b040bf1b7 (diff) | |
download | llvm-b22804b35464049ca92107d45042d2a5bbd292f6.zip llvm-b22804b35464049ca92107d45042d2a5bbd292f6.tar.gz llvm-b22804b35464049ca92107d45042d2a5bbd292f6.tar.bz2 |
[Tooling] Migrated APIs that take ownership of objects to unique_ptr
Subscribers: jkorous, arphaman, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66960
llvm-svn: 370451
Diffstat (limited to 'clang/unittests')
-rw-r--r-- | clang/unittests/AST/EvaluateAsRValueTest.cpp | 34 | ||||
-rw-r--r-- | clang/unittests/AST/RecursiveASTVisitorTest.cpp | 2 | ||||
-rw-r--r-- | clang/unittests/CrossTU/CrossTranslationUnitTest.cpp | 8 | ||||
-rw-r--r-- | clang/unittests/Index/IndexTests.cpp | 23 | ||||
-rw-r--r-- | clang/unittests/Sema/CodeCompleteTest.cpp | 8 | ||||
-rw-r--r-- | clang/unittests/Sema/ExternalSemaSourceTest.cpp | 30 | ||||
-rw-r--r-- | clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp | 24 | ||||
-rw-r--r-- | clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp | 3 | ||||
-rw-r--r-- | clang/unittests/StaticAnalyzer/StoreTest.cpp | 4 | ||||
-rw-r--r-- | clang/unittests/StaticAnalyzer/SymbolReaperTest.cpp | 5 | ||||
-rw-r--r-- | clang/unittests/Tooling/CommentHandlerTest.cpp | 4 | ||||
-rw-r--r-- | clang/unittests/Tooling/RefactoringTest.cpp | 2 | ||||
-rw-r--r-- | clang/unittests/Tooling/TestVisitor.h | 4 | ||||
-rw-r--r-- | clang/unittests/Tooling/ToolingTest.cpp | 96 |
14 files changed, 123 insertions, 124 deletions
diff --git a/clang/unittests/AST/EvaluateAsRValueTest.cpp b/clang/unittests/AST/EvaluateAsRValueTest.cpp index 4eabb2c..0475330 100644 --- a/clang/unittests/AST/EvaluateAsRValueTest.cpp +++ b/clang/unittests/AST/EvaluateAsRValueTest.cpp @@ -89,22 +89,22 @@ TEST(EvaluateAsRValue, FailsGracefullyForUnknownTypes) { std::vector<std::string> Args(1, Mode); Args.push_back("-fno-delayed-template-parsing"); ASSERT_TRUE(runToolOnCodeWithArgs( - new EvaluateConstantInitializersAction(), - "template <typename T>" - "struct vector {" - " explicit vector(int size);" - "};" - "template <typename R>" - "struct S {" - " vector<R> intervals() const {" - " vector<R> Dependent(2);" - " return Dependent;" - " }" - "};" - "void doSomething() {" - " int Constant = 2 + 2;" - " (void) Constant;" - "}", - Args)); + std::make_unique<EvaluateConstantInitializersAction>(), + "template <typename T>" + "struct vector {" + " explicit vector(int size);" + "};" + "template <typename R>" + "struct S {" + " vector<R> intervals() const {" + " vector<R> Dependent(2);" + " return Dependent;" + " }" + "};" + "void doSomething() {" + " int Constant = 2 + 2;" + " (void) Constant;" + "}", + Args)); } } diff --git a/clang/unittests/AST/RecursiveASTVisitorTest.cpp b/clang/unittests/AST/RecursiveASTVisitorTest.cpp index 988a8ce..aa87565 100644 --- a/clang/unittests/AST/RecursiveASTVisitorTest.cpp +++ b/clang/unittests/AST/RecursiveASTVisitorTest.cpp @@ -84,7 +84,7 @@ private: std::vector<VisitEvent> collectEvents(llvm::StringRef Code) { CollectInterestingEvents Visitor; clang::tooling::runToolOnCode( - new ProcessASTAction( + std::make_unique<ProcessASTAction>( [&](clang::ASTContext &Ctx) { Visitor.TraverseAST(Ctx); }), Code); return std::move(Visitor).takeEvents(); diff --git a/clang/unittests/CrossTU/CrossTranslationUnitTest.cpp b/clang/unittests/CrossTU/CrossTranslationUnitTest.cpp index 3cea339..86ede5e 100644 --- a/clang/unittests/CrossTU/CrossTranslationUnitTest.cpp +++ b/clang/unittests/CrossTU/CrossTranslationUnitTest.cpp @@ -134,15 +134,15 @@ private: TEST(CrossTranslationUnit, CanLoadFunctionDefinition) { bool Success = false; - EXPECT_TRUE( - tooling::runToolOnCode(new CTUAction(&Success, 1u), "int f(int);")); + EXPECT_TRUE(tooling::runToolOnCode(std::make_unique<CTUAction>(&Success, 1u), + "int f(int);")); EXPECT_TRUE(Success); } TEST(CrossTranslationUnit, RespectsLoadThreshold) { bool Success = false; - EXPECT_TRUE( - tooling::runToolOnCode(new CTUAction(&Success, 0u), "int f(int);")); + EXPECT_TRUE(tooling::runToolOnCode(std::make_unique<CTUAction>(&Success, 0u), + "int f(int);")); EXPECT_FALSE(Success); } diff --git a/clang/unittests/Index/IndexTests.cpp b/clang/unittests/Index/IndexTests.cpp index bf0418c..752dab8 100644 --- a/clang/unittests/Index/IndexTests.cpp +++ b/clang/unittests/Index/IndexTests.cpp @@ -155,7 +155,8 @@ MATCHER_P(HasRole, Role, "") { return arg.Roles & static_cast<unsigned>(Role); } TEST(IndexTest, Simple) { auto Index = std::make_shared<Indexer>(); - tooling::runToolOnCode(new IndexAction(Index), "class X {}; void f() {}"); + tooling::runToolOnCode(std::make_unique<IndexAction>(Index), + "class X {}; void f() {}"); EXPECT_THAT(Index->Symbols, UnorderedElementsAre(QName("X"), QName("f"))); } @@ -164,12 +165,12 @@ TEST(IndexTest, IndexPreprocessorMacros) { auto Index = std::make_shared<Indexer>(); IndexingOptions Opts; Opts.IndexMacrosInPreprocessor = true; - tooling::runToolOnCode(new IndexAction(Index, Opts), Code); + tooling::runToolOnCode(std::make_unique<IndexAction>(Index, Opts), Code); EXPECT_THAT(Index->Symbols, Contains(QName("INDEX_MAC"))); Opts.IndexMacrosInPreprocessor = false; Index->Symbols.clear(); - tooling::runToolOnCode(new IndexAction(Index, Opts), Code); + tooling::runToolOnCode(std::make_unique<IndexAction>(Index, Opts), Code); EXPECT_THAT(Index->Symbols, UnorderedElementsAre()); } @@ -179,12 +180,12 @@ TEST(IndexTest, IndexParametersInDecls) { IndexingOptions Opts; Opts.IndexFunctionLocals = true; Opts.IndexParametersInDeclarations = true; - tooling::runToolOnCode(new IndexAction(Index, Opts), Code); + tooling::runToolOnCode(std::make_unique<IndexAction>(Index, Opts), Code); EXPECT_THAT(Index->Symbols, Contains(QName("bar"))); Opts.IndexParametersInDeclarations = false; Index->Symbols.clear(); - tooling::runToolOnCode(new IndexAction(Index, Opts), Code); + tooling::runToolOnCode(std::make_unique<IndexAction>(Index, Opts), Code); EXPECT_THAT(Index->Symbols, Not(Contains(QName("bar")))); } @@ -201,7 +202,7 @@ TEST(IndexTest, IndexExplicitTemplateInstantiation) { )cpp"; auto Index = std::make_shared<Indexer>(); IndexingOptions Opts; - tooling::runToolOnCode(new IndexAction(Index, Opts), Code); + tooling::runToolOnCode(std::make_unique<IndexAction>(Index, Opts), Code); EXPECT_THAT(Index->Symbols, AllOf(Contains(AllOf(QName("Foo"), WrittenAt(Position(8, 7)), DeclAt(Position(5, 12)))), @@ -222,7 +223,7 @@ TEST(IndexTest, IndexTemplateInstantiationPartial) { )cpp"; auto Index = std::make_shared<Indexer>(); IndexingOptions Opts; - tooling::runToolOnCode(new IndexAction(Index, Opts), Code); + tooling::runToolOnCode(std::make_unique<IndexAction>(Index, Opts), Code); EXPECT_THAT(Index->Symbols, Contains(AllOf(QName("Foo"), WrittenAt(Position(8, 7)), DeclAt(Position(5, 12))))); @@ -238,7 +239,7 @@ TEST(IndexTest, IndexTypeParmDecls) { )cpp"; auto Index = std::make_shared<Indexer>(); IndexingOptions Opts; - tooling::runToolOnCode(new IndexAction(Index, Opts), Code); + tooling::runToolOnCode(std::make_unique<IndexAction>(Index, Opts), Code); EXPECT_THAT(Index->Symbols, AllOf(Not(Contains(QName("Foo::T"))), Not(Contains(QName("Foo::I"))), Not(Contains(QName("Foo::C"))), @@ -246,7 +247,7 @@ TEST(IndexTest, IndexTypeParmDecls) { Opts.IndexTemplateParameters = true; Index->Symbols.clear(); - tooling::runToolOnCode(new IndexAction(Index, Opts), Code); + tooling::runToolOnCode(std::make_unique<IndexAction>(Index, Opts), Code); EXPECT_THAT(Index->Symbols, AllOf(Contains(QName("Foo::T")), Contains(QName("Foo::I")), Contains(QName("Foo::C")), Contains(QName("Foo::NoRef")))); @@ -261,7 +262,7 @@ TEST(IndexTest, UsingDecls) { )cpp"; auto Index = std::make_shared<Indexer>(); IndexingOptions Opts; - tooling::runToolOnCode(new IndexAction(Index, Opts), Code); + tooling::runToolOnCode(std::make_unique<IndexAction>(Index, Opts), Code); EXPECT_THAT(Index->Symbols, Contains(AllOf(QName("std::foo"), Kind(SymbolKind::Using)))); } @@ -275,7 +276,7 @@ TEST(IndexTest, Constructors) { )cpp"; auto Index = std::make_shared<Indexer>(); IndexingOptions Opts; - tooling::runToolOnCode(new IndexAction(Index, Opts), Code); + tooling::runToolOnCode(std::make_unique<IndexAction>(Index, Opts), Code); EXPECT_THAT( Index->Symbols, UnorderedElementsAre( diff --git a/clang/unittests/Sema/CodeCompleteTest.cpp b/clang/unittests/Sema/CodeCompleteTest.cpp index dc0f7e0..ab1792b 100644 --- a/clang/unittests/Sema/CodeCompleteTest.cpp +++ b/clang/unittests/Sema/CodeCompleteTest.cpp @@ -101,10 +101,10 @@ ParsedSourceLocation offsetToPosition(llvm::StringRef Code, size_t Offset) { CompletionContext runCompletion(StringRef Code, size_t Offset) { CompletionContext ResultCtx; - auto Action = std::make_unique<CodeCompleteAction>( - offsetToPosition(Code, Offset), ResultCtx); - clang::tooling::runToolOnCodeWithArgs(Action.release(), Code, {"-std=c++11"}, - TestCCName); + clang::tooling::runToolOnCodeWithArgs( + std::make_unique<CodeCompleteAction>(offsetToPosition(Code, Offset), + ResultCtx), + Code, {"-std=c++11"}, TestCCName); return ResultCtx; } diff --git a/clang/unittests/Sema/ExternalSemaSourceTest.cpp b/clang/unittests/Sema/ExternalSemaSourceTest.cpp index edf91c9..44006e3 100644 --- a/clang/unittests/Sema/ExternalSemaSourceTest.cpp +++ b/clang/unittests/Sema/ExternalSemaSourceTest.cpp @@ -220,28 +220,26 @@ public: // Make sure that the DiagnosticWatcher is not miscounting. TEST(ExternalSemaSource, SanityCheck) { - std::unique_ptr<ExternalSemaSourceInstaller> Installer( - new ExternalSemaSourceInstaller); + auto Installer = std::make_unique<ExternalSemaSourceInstaller>(); DiagnosticWatcher Watcher("AAB", "BBB"); Installer->PushWatcher(&Watcher); std::vector<std::string> Args(1, "-std=c++11"); ASSERT_TRUE(clang::tooling::runToolOnCodeWithArgs( - Installer.release(), "namespace AAA { } using namespace AAB;", Args)); + std::move(Installer), "namespace AAA { } using namespace AAB;", Args)); ASSERT_EQ(0, Watcher.SeenCount); } // Check that when we add a NamespaceTypeProvider, we use that suggestion // instead of the usual suggestion we would use above. TEST(ExternalSemaSource, ExternalTypoCorrectionPrioritized) { - std::unique_ptr<ExternalSemaSourceInstaller> Installer( - new ExternalSemaSourceInstaller); + auto Installer = std::make_unique<ExternalSemaSourceInstaller>(); NamespaceTypoProvider Provider("AAB", "BBB"); DiagnosticWatcher Watcher("AAB", "BBB"); Installer->PushSource(&Provider); Installer->PushWatcher(&Watcher); std::vector<std::string> Args(1, "-std=c++11"); ASSERT_TRUE(clang::tooling::runToolOnCodeWithArgs( - Installer.release(), "namespace AAA { } using namespace AAB;", Args)); + std::move(Installer), "namespace AAA { } using namespace AAB;", Args)); ASSERT_LE(0, Provider.CallCount); ASSERT_EQ(1, Watcher.SeenCount); } @@ -249,8 +247,7 @@ TEST(ExternalSemaSource, ExternalTypoCorrectionPrioritized) { // Check that we use the first successful TypoCorrection returned from an // ExternalSemaSource. TEST(ExternalSemaSource, ExternalTypoCorrectionOrdering) { - std::unique_ptr<ExternalSemaSourceInstaller> Installer( - new ExternalSemaSourceInstaller); + auto Installer = std::make_unique<ExternalSemaSourceInstaller>(); NamespaceTypoProvider First("XXX", "BBB"); NamespaceTypoProvider Second("AAB", "CCC"); NamespaceTypoProvider Third("AAB", "DDD"); @@ -261,7 +258,7 @@ TEST(ExternalSemaSource, ExternalTypoCorrectionOrdering) { Installer->PushWatcher(&Watcher); std::vector<std::string> Args(1, "-std=c++11"); ASSERT_TRUE(clang::tooling::runToolOnCodeWithArgs( - Installer.release(), "namespace AAA { } using namespace AAB;", Args)); + std::move(Installer), "namespace AAA { } using namespace AAB;", Args)); ASSERT_LE(1, First.CallCount); ASSERT_LE(1, Second.CallCount); ASSERT_EQ(0, Third.CallCount); @@ -269,15 +266,14 @@ TEST(ExternalSemaSource, ExternalTypoCorrectionOrdering) { } TEST(ExternalSemaSource, ExternalDelayedTypoCorrection) { - std::unique_ptr<ExternalSemaSourceInstaller> Installer( - new ExternalSemaSourceInstaller); + auto Installer = std::make_unique<ExternalSemaSourceInstaller>(); FunctionTypoProvider Provider("aaa", "bbb"); DiagnosticWatcher Watcher("aaa", "bbb"); Installer->PushSource(&Provider); Installer->PushWatcher(&Watcher); std::vector<std::string> Args(1, "-std=c++11"); ASSERT_TRUE(clang::tooling::runToolOnCodeWithArgs( - Installer.release(), "namespace AAA { } void foo() { AAA::aaa(); }", + std::move(Installer), "namespace AAA { } void foo() { AAA::aaa(); }", Args)); ASSERT_LE(0, Provider.CallCount); ASSERT_EQ(1, Watcher.SeenCount); @@ -286,15 +282,14 @@ TEST(ExternalSemaSource, ExternalDelayedTypoCorrection) { // We should only try MaybeDiagnoseMissingCompleteType if we can't otherwise // solve the problem. TEST(ExternalSemaSource, TryOtherTacticsBeforeDiagnosing) { - std::unique_ptr<ExternalSemaSourceInstaller> Installer( - new ExternalSemaSourceInstaller); + auto Installer = std::make_unique<ExternalSemaSourceInstaller>(); CompleteTypeDiagnoser Diagnoser(false); Installer->PushSource(&Diagnoser); std::vector<std::string> Args(1, "-std=c++11"); // This code hits the class template specialization/class member of a class // template specialization checks in Sema::RequireCompleteTypeImpl. ASSERT_TRUE(clang::tooling::runToolOnCodeWithArgs( - Installer.release(), + std::move(Installer), "template <typename T> struct S { class C { }; }; S<char>::C SCInst;", Args)); ASSERT_EQ(0, Diagnoser.CallCount); @@ -303,8 +298,7 @@ TEST(ExternalSemaSource, TryOtherTacticsBeforeDiagnosing) { // The first ExternalSemaSource where MaybeDiagnoseMissingCompleteType returns // true should be the last one called. TEST(ExternalSemaSource, FirstDiagnoserTaken) { - std::unique_ptr<ExternalSemaSourceInstaller> Installer( - new ExternalSemaSourceInstaller); + auto Installer = std::make_unique<ExternalSemaSourceInstaller>(); CompleteTypeDiagnoser First(false); CompleteTypeDiagnoser Second(true); CompleteTypeDiagnoser Third(true); @@ -313,7 +307,7 @@ TEST(ExternalSemaSource, FirstDiagnoserTaken) { Installer->PushSource(&Third); std::vector<std::string> Args(1, "-std=c++11"); ASSERT_FALSE(clang::tooling::runToolOnCodeWithArgs( - Installer.release(), "class Incomplete; Incomplete IncompleteInstance;", + std::move(Installer), "class Incomplete; Incomplete IncompleteInstance;", Args)); ASSERT_EQ(1, First.CallCount); ASSERT_EQ(1, Second.CallCount); diff --git a/clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp b/clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp index 86cd6a4..2ebaa46 100644 --- a/clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp +++ b/clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp @@ -100,30 +100,30 @@ public: TEST(CallEvent, CallDescription) { // Test simple name matching. EXPECT_TRUE(tooling::runToolOnCode( - new CallDescriptionAction({ + std::unique_ptr<CallDescriptionAction>(new CallDescriptionAction({ {{"bar"}, false}, // false: there's no call to 'bar' in this code. {{"foo"}, true}, // true: there's a call to 'foo' in this code. - }), "void foo(); void bar() { foo(); }")); + })), "void foo(); void bar() { foo(); }")); // Test arguments check. EXPECT_TRUE(tooling::runToolOnCode( - new CallDescriptionAction({ + std::unique_ptr<CallDescriptionAction>(new CallDescriptionAction({ {{"foo", 1}, true}, {{"foo", 2}, false}, - }), "void foo(int); void foo(int, int); void bar() { foo(1); }")); + })), "void foo(int); void foo(int, int); void bar() { foo(1); }")); // Test lack of arguments check. EXPECT_TRUE(tooling::runToolOnCode( - new CallDescriptionAction({ + std::unique_ptr<CallDescriptionAction>(new CallDescriptionAction({ {{"foo", None}, true}, {{"foo", 2}, false}, - }), "void foo(int); void foo(int, int); void bar() { foo(1); }")); + })), "void foo(int); void foo(int, int); void bar() { foo(1); }")); // Test qualified names. EXPECT_TRUE(tooling::runToolOnCode( - new CallDescriptionAction({ + std::unique_ptr<CallDescriptionAction>(new CallDescriptionAction({ {{{"std", "basic_string", "c_str"}}, true}, - }), + })), "namespace std { inline namespace __1 {" " template<typename T> class basic_string {" " public:" @@ -138,18 +138,18 @@ TEST(CallEvent, CallDescription) { // A negative test for qualified names. EXPECT_TRUE(tooling::runToolOnCode( - new CallDescriptionAction({ + std::unique_ptr<CallDescriptionAction>(new CallDescriptionAction({ {{{"foo", "bar"}}, false}, {{{"bar", "foo"}}, false}, {{"foo"}, true}, - }), "void foo(); struct bar { void foo(); }; void test() { foo(); }")); + })), "void foo(); struct bar { void foo(); }; void test() { foo(); }")); // Test CDF_MaybeBuiltin - a flag that allows matching weird builtins. EXPECT_TRUE(tooling::runToolOnCode( - new CallDescriptionAction({ + std::unique_ptr<CallDescriptionAction>(new CallDescriptionAction({ {{"memset", 3}, false}, {{CDF_MaybeBuiltin, "memset", 3}, true} - }), + })), "void foo() {" " int x;" " __builtin___memset_chk(&x, 0, sizeof(x)," diff --git a/clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp b/clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp index 109e7628..4773852 100644 --- a/clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp +++ b/clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp @@ -58,7 +58,8 @@ public: template <typename CheckerT> bool runCheckerOnCode(const std::string &Code, std::string &Diags) { llvm::raw_string_ostream OS(Diags); - return tooling::runToolOnCode(new TestAction<CheckerT>(OS), Code); + return tooling::runToolOnCode(std::make_unique<TestAction<CheckerT>>(OS), + Code); } template <typename CheckerT> bool runCheckerOnCode(const std::string &Code) { diff --git a/clang/unittests/StaticAnalyzer/StoreTest.cpp b/clang/unittests/StaticAnalyzer/StoreTest.cpp index 0cbe7d4..c8b930b 100644 --- a/clang/unittests/StaticAnalyzer/StoreTest.cpp +++ b/clang/unittests/StaticAnalyzer/StoreTest.cpp @@ -96,8 +96,8 @@ public: }; TEST(Store, VariableBind) { - EXPECT_TRUE(tooling::runToolOnCode( - new VariableBindAction, "void foo() { int x0, y0, z0, x1, y1; }")); + EXPECT_TRUE(tooling::runToolOnCode(std::make_unique<VariableBindAction>(), + "void foo() { int x0, y0, z0, x1, y1; }")); } } // namespace diff --git a/clang/unittests/StaticAnalyzer/SymbolReaperTest.cpp b/clang/unittests/StaticAnalyzer/SymbolReaperTest.cpp index bd11303..bbbf688 100644 --- a/clang/unittests/StaticAnalyzer/SymbolReaperTest.cpp +++ b/clang/unittests/StaticAnalyzer/SymbolReaperTest.cpp @@ -61,8 +61,9 @@ public: // Test that marking s.x as live would also make s live. TEST(SymbolReaper, SuperRegionLiveness) { - EXPECT_TRUE(tooling::runToolOnCode(new SuperRegionLivenessAction, - "void foo() { struct S { int x; } s; }")); + EXPECT_TRUE( + tooling::runToolOnCode(std::make_unique<SuperRegionLivenessAction>(), + "void foo() { struct S { int x; } s; }")); } } // namespace diff --git a/clang/unittests/Tooling/CommentHandlerTest.cpp b/clang/unittests/Tooling/CommentHandlerTest.cpp index 5ceed95..7eb11cc 100644 --- a/clang/unittests/Tooling/CommentHandlerTest.cpp +++ b/clang/unittests/Tooling/CommentHandlerTest.cpp @@ -55,8 +55,8 @@ public: CommentVerifier GetVerifier(); protected: - ASTFrontendAction *CreateTestAction() override { - return new CommentHandlerAction(this); + std::unique_ptr<ASTFrontendAction> CreateTestAction() override { + return std::make_unique<CommentHandlerAction>(this); } private: diff --git a/clang/unittests/Tooling/RefactoringTest.cpp b/clang/unittests/Tooling/RefactoringTest.cpp index b5c56e90..5949c53 100644 --- a/clang/unittests/Tooling/RefactoringTest.cpp +++ b/clang/unittests/Tooling/RefactoringTest.cpp @@ -650,7 +650,7 @@ template <typename T> class TestVisitor : public clang::RecursiveASTVisitor<T> { public: bool runOver(StringRef Code) { - return runToolOnCode(new TestAction(this), Code); + return runToolOnCode(std::make_unique<TestAction>(this), Code); } protected: diff --git a/clang/unittests/Tooling/TestVisitor.h b/clang/unittests/Tooling/TestVisitor.h index 95252b8..751ca74 100644 --- a/clang/unittests/Tooling/TestVisitor.h +++ b/clang/unittests/Tooling/TestVisitor.h @@ -85,8 +85,8 @@ public: } protected: - virtual ASTFrontendAction* CreateTestAction() { - return new TestAction(this); + virtual std::unique_ptr<ASTFrontendAction> CreateTestAction() { + return std::make_unique<TestAction>(this); } class FindConsumer : public ASTConsumer { diff --git a/clang/unittests/Tooling/ToolingTest.cpp b/clang/unittests/Tooling/ToolingTest.cpp index 447b997..c22d0bd 100644 --- a/clang/unittests/Tooling/ToolingTest.cpp +++ b/clang/unittests/Tooling/ToolingTest.cpp @@ -62,10 +62,10 @@ class FindTopLevelDeclConsumer : public clang::ASTConsumer { TEST(runToolOnCode, FindsNoTopLevelDeclOnEmptyCode) { bool FoundTopLevelDecl = false; - EXPECT_TRUE( - runToolOnCode(new TestAction(std::make_unique<FindTopLevelDeclConsumer>( - &FoundTopLevelDecl)), - "")); + EXPECT_TRUE(runToolOnCode( + std::make_unique<TestAction>( + std::make_unique<FindTopLevelDeclConsumer>(&FoundTopLevelDecl)), + "")); EXPECT_FALSE(FoundTopLevelDecl); } @@ -102,17 +102,17 @@ bool FindClassDeclX(ASTUnit *AST) { TEST(runToolOnCode, FindsClassDecl) { bool FoundClassDeclX = false; - EXPECT_TRUE( - runToolOnCode(new TestAction(std::make_unique<FindClassDeclXConsumer>( - &FoundClassDeclX)), - "class X;")); + EXPECT_TRUE(runToolOnCode( + std::make_unique<TestAction>( + std::make_unique<FindClassDeclXConsumer>(&FoundClassDeclX)), + "class X;")); EXPECT_TRUE(FoundClassDeclX); FoundClassDeclX = false; - EXPECT_TRUE( - runToolOnCode(new TestAction(std::make_unique<FindClassDeclXConsumer>( - &FoundClassDeclX)), - "class Y;")); + EXPECT_TRUE(runToolOnCode( + std::make_unique<TestAction>( + std::make_unique<FindClassDeclXConsumer>(&FoundClassDeclX)), + "class Y;")); EXPECT_FALSE(FoundClassDeclX); } @@ -160,8 +160,8 @@ TEST(ToolInvocation, TestMapVirtualFile) { Args.push_back("-Idef"); Args.push_back("-fsyntax-only"); Args.push_back("test.cpp"); - clang::tooling::ToolInvocation Invocation(Args, new SyntaxOnlyAction, - Files.get()); + clang::tooling::ToolInvocation Invocation( + Args, std::make_unique<SyntaxOnlyAction>(), Files.get()); InMemoryFileSystem->addFile( "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("#include <abc>\n")); InMemoryFileSystem->addFile("def/abc", 0, @@ -186,8 +186,8 @@ TEST(ToolInvocation, TestVirtualModulesCompilation) { Args.push_back("-Idef"); Args.push_back("-fsyntax-only"); Args.push_back("test.cpp"); - clang::tooling::ToolInvocation Invocation(Args, new SyntaxOnlyAction, - Files.get()); + clang::tooling::ToolInvocation Invocation( + Args, std::make_unique<SyntaxOnlyAction>(), Files.get()); InMemoryFileSystem->addFile( "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("#include <abc>\n")); InMemoryFileSystem->addFile("def/abc", 0, @@ -257,61 +257,61 @@ TEST(runToolOnCode, TestSkipFunctionBody) { std::vector<std::string> Args = {"-std=c++11"}; std::vector<std::string> Args2 = {"-fno-delayed-template-parsing"}; - EXPECT_TRUE(runToolOnCode(new SkipBodyAction, + EXPECT_TRUE(runToolOnCode(std::make_unique<SkipBodyAction>(), "int skipMe() { an_error_here }")); - EXPECT_FALSE(runToolOnCode(new SkipBodyAction, + EXPECT_FALSE(runToolOnCode(std::make_unique<SkipBodyAction>(), "int skipMeNot() { an_error_here }")); // Test constructors with initializers EXPECT_TRUE(runToolOnCodeWithArgs( - new SkipBodyAction, + std::make_unique<SkipBodyAction>(), "struct skipMe { skipMe() : an_error() { more error } };", Args)); EXPECT_TRUE(runToolOnCodeWithArgs( - new SkipBodyAction, "struct skipMe { skipMe(); };" + std::make_unique<SkipBodyAction>(), "struct skipMe { skipMe(); };" "skipMe::skipMe() : an_error([](){;}) { more error }", Args)); EXPECT_TRUE(runToolOnCodeWithArgs( - new SkipBodyAction, "struct skipMe { skipMe(); };" + std::make_unique<SkipBodyAction>(), "struct skipMe { skipMe(); };" "skipMe::skipMe() : an_error{[](){;}} { more error }", Args)); EXPECT_TRUE(runToolOnCodeWithArgs( - new SkipBodyAction, + std::make_unique<SkipBodyAction>(), "struct skipMe { skipMe(); };" "skipMe::skipMe() : a<b<c>(e)>>(), f{}, g() { error }", Args)); EXPECT_TRUE(runToolOnCodeWithArgs( - new SkipBodyAction, "struct skipMe { skipMe() : bases()... { error } };", + std::make_unique<SkipBodyAction>(), "struct skipMe { skipMe() : bases()... { error } };", Args)); EXPECT_FALSE(runToolOnCodeWithArgs( - new SkipBodyAction, "struct skipMeNot { skipMeNot() : an_error() { } };", + std::make_unique<SkipBodyAction>(), "struct skipMeNot { skipMeNot() : an_error() { } };", Args)); - EXPECT_FALSE(runToolOnCodeWithArgs(new SkipBodyAction, + EXPECT_FALSE(runToolOnCodeWithArgs(std::make_unique<SkipBodyAction>(), "struct skipMeNot { skipMeNot(); };" "skipMeNot::skipMeNot() : an_error() { }", Args)); // Try/catch EXPECT_TRUE(runToolOnCode( - new SkipBodyAction, + std::make_unique<SkipBodyAction>(), "void skipMe() try { an_error() } catch(error) { error };")); EXPECT_TRUE(runToolOnCode( - new SkipBodyAction, + std::make_unique<SkipBodyAction>(), "struct S { void skipMe() try { an_error() } catch(error) { error } };")); EXPECT_TRUE( - runToolOnCode(new SkipBodyAction, + runToolOnCode(std::make_unique<SkipBodyAction>(), "void skipMe() try { an_error() } catch(error) { error; }" "catch(error) { error } catch (error) { }")); EXPECT_FALSE(runToolOnCode( - new SkipBodyAction, + std::make_unique<SkipBodyAction>(), "void skipMe() try something;")); // don't crash while parsing // Template EXPECT_TRUE(runToolOnCode( - new SkipBodyAction, "template<typename T> int skipMe() { an_error_here }" + std::make_unique<SkipBodyAction>(), "template<typename T> int skipMe() { an_error_here }" "int x = skipMe<int>();")); EXPECT_FALSE(runToolOnCodeWithArgs( - new SkipBodyAction, + std::make_unique<SkipBodyAction>(), "template<typename T> int skipMeNot() { an_error_here }", Args2)); } @@ -325,7 +325,7 @@ TEST(runToolOnCodeWithArgs, TestNoDepFile) { Args.push_back(DepFilePath.str()); Args.push_back("-MF"); Args.push_back(DepFilePath.str()); - EXPECT_TRUE(runToolOnCodeWithArgs(new SkipBodyAction, "", Args)); + EXPECT_TRUE(runToolOnCodeWithArgs(std::make_unique<SkipBodyAction>(), "", Args)); EXPECT_FALSE(llvm::sys::fs::exists(DepFilePath.str())); EXPECT_FALSE(llvm::sys::fs::remove(DepFilePath.str())); } @@ -348,24 +348,26 @@ private: }; TEST(runToolOnCodeWithArgs, DiagnosticsColor) { - - EXPECT_TRUE(runToolOnCodeWithArgs(new CheckColoredDiagnosticsAction(true), "", - {"-fcolor-diagnostics"})); - EXPECT_TRUE(runToolOnCodeWithArgs(new CheckColoredDiagnosticsAction(false), - "", {"-fno-color-diagnostics"})); - EXPECT_TRUE( - runToolOnCodeWithArgs(new CheckColoredDiagnosticsAction(true), "", - {"-fno-color-diagnostics", "-fcolor-diagnostics"})); - EXPECT_TRUE( - runToolOnCodeWithArgs(new CheckColoredDiagnosticsAction(false), "", - {"-fcolor-diagnostics", "-fno-color-diagnostics"})); EXPECT_TRUE(runToolOnCodeWithArgs( - new CheckColoredDiagnosticsAction(true), "", + std::make_unique<CheckColoredDiagnosticsAction>(true), "", + {"-fcolor-diagnostics"})); + EXPECT_TRUE(runToolOnCodeWithArgs( + std::make_unique<CheckColoredDiagnosticsAction>(false), "", + {"-fno-color-diagnostics"})); + EXPECT_TRUE(runToolOnCodeWithArgs( + std::make_unique<CheckColoredDiagnosticsAction>(true), "", + {"-fno-color-diagnostics", "-fcolor-diagnostics"})); + EXPECT_TRUE(runToolOnCodeWithArgs( + std::make_unique<CheckColoredDiagnosticsAction>(false), "", + {"-fcolor-diagnostics", "-fno-color-diagnostics"})); + EXPECT_TRUE(runToolOnCodeWithArgs( + std::make_unique<CheckColoredDiagnosticsAction>(true), "", {"-fno-color-diagnostics", "-fdiagnostics-color=always"})); // Check that this test would fail if ShowColors is not what it should. - EXPECT_FALSE(runToolOnCodeWithArgs(new CheckColoredDiagnosticsAction(false), - "", {"-fcolor-diagnostics"})); + EXPECT_FALSE(runToolOnCodeWithArgs( + std::make_unique<CheckColoredDiagnosticsAction>(false), "", + {"-fcolor-diagnostics"})); } TEST(ClangToolTest, ArgumentAdjusters) { @@ -657,7 +659,7 @@ TEST(runToolOnCode, TestResetDiagnostics) { // Should not crash EXPECT_FALSE( - runToolOnCode(new ResetDiagnosticAction, + runToolOnCode(std::make_unique<ResetDiagnosticAction>(), "struct Foo { Foo(int); ~Foo(); struct Fwd _fwd; };" "void func() { long x; Foo f(x); }")); } |