diff --git a/clang-tools-extra/clangd/unittests/IndexActionTests.cpp b/clang-tools-extra/clangd/unittests/IndexActionTests.cpp --- a/clang-tools-extra/clangd/unittests/IndexActionTests.cpp +++ b/clang-tools-extra/clangd/unittests/IndexActionTests.cpp @@ -88,7 +88,7 @@ Args.push_back(MainFilePath); tooling::ToolInvocation Invocation( - Args, Action.release(), Files.get(), + Args, std::move(Action), Files.get(), std::make_shared()); Invocation.run(); diff --git a/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h b/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h --- a/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h +++ b/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h @@ -117,7 +117,9 @@ SmallVector, 1> Checks; tooling::ToolInvocation Invocation( - Args, new TestClangTidyAction(Checks, Finder, Context), + Args, + std::make_unique>(Checks, Finder, + Context), Files.get()); InMemoryFileSystem->addFile(Filename, 0, llvm::MemoryBuffer::getMemBuffer(Code)); diff --git a/clang/include/clang/Tooling/Tooling.h b/clang/include/clang/Tooling/Tooling.h --- a/clang/include/clang/Tooling/Tooling.h +++ b/clang/include/clang/Tooling/Tooling.h @@ -154,19 +154,11 @@ /// clang modules. /// /// \return - True if 'ToolAction' was successfully executed. -bool runToolOnCode(FrontendAction *ToolAction, const Twine &Code, +bool runToolOnCode(std::unique_ptr ToolAction, const Twine &Code, const Twine &FileName = "input.cc", std::shared_ptr PCHContainerOps = std::make_shared()); -inline bool -runToolOnCode(std::unique_ptr ToolAction, const Twine &Code, - const Twine &FileName = "input.cc", - std::shared_ptr PCHContainerOps = - std::make_shared()) { - return runToolOnCode(ToolAction.release(), Code, FileName, PCHContainerOps); -} - /// The first part of the pair is the filename, the second part the /// file-content. using FileContentMappings = std::vector>; @@ -185,43 +177,21 @@ /// /// \return - True if 'ToolAction' was successfully executed. bool runToolOnCodeWithArgs( - FrontendAction *ToolAction, const Twine &Code, - const std::vector &Args, const Twine &FileName = "input.cc", - const Twine &ToolName = "clang-tool", - std::shared_ptr PCHContainerOps = - std::make_shared(), - const FileContentMappings &VirtualMappedFiles = FileContentMappings()); - -inline bool runToolOnCodeWithArgs( std::unique_ptr ToolAction, const Twine &Code, const std::vector &Args, const Twine &FileName = "input.cc", const Twine &ToolName = "clang-tool", std::shared_ptr PCHContainerOps = std::make_shared(), - const FileContentMappings &VirtualMappedFiles = FileContentMappings()) { - return runToolOnCodeWithArgs(ToolAction.release(), Code, Args, FileName, - ToolName, PCHContainerOps, VirtualMappedFiles); -} + const FileContentMappings &VirtualMappedFiles = FileContentMappings()); // Similar to the overload except this takes a VFS. bool runToolOnCodeWithArgs( - FrontendAction *ToolAction, const Twine &Code, - llvm::IntrusiveRefCntPtr VFS, - const std::vector &Args, const Twine &FileName = "input.cc", - const Twine &ToolName = "clang-tool", - std::shared_ptr PCHContainerOps = - std::make_shared()); - -inline bool runToolOnCodeWithArgs( std::unique_ptr ToolAction, const Twine &Code, llvm::IntrusiveRefCntPtr VFS, const std::vector &Args, const Twine &FileName = "input.cc", const Twine &ToolName = "clang-tool", std::shared_ptr PCHContainerOps = - std::make_shared()) { - return runToolOnCodeWithArgs(ToolAction.release(), Code, VFS, Args, FileName, - ToolName, PCHContainerOps); -} + std::make_shared()); /// Builds an AST for 'Code'. /// @@ -265,22 +235,15 @@ /// uses its binary name (CommandLine[0]) to locate its builtin headers. /// Callers have to ensure that they are installed in a compatible location /// (see clang driver implementation) or mapped in via mapVirtualFile. - /// \param FAction The action to be executed. Class takes ownership. + /// \param FAction The action to be executed. /// \param Files The FileManager used for the execution. Class does not take /// ownership. /// \param PCHContainerOps The PCHContainerOperations for loading and creating /// clang modules. - ToolInvocation(std::vector CommandLine, FrontendAction *FAction, - FileManager *Files, - std::shared_ptr PCHContainerOps = - std::make_shared()); - ToolInvocation(std::vector CommandLine, std::unique_ptr FAction, FileManager *Files, std::shared_ptr PCHContainerOps = - std::make_shared()) - : ToolInvocation(std::move(CommandLine), FAction.release(), Files, - PCHContainerOps) {} + std::make_shared()); /// Create a tool invocation. /// diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp --- a/clang/lib/Tooling/Tooling.cpp +++ b/clang/lib/Tooling/Tooling.cpp @@ -124,12 +124,12 @@ return Invocation; } -bool runToolOnCode(FrontendAction *ToolAction, const Twine &Code, - const Twine &FileName, +bool runToolOnCode(std::unique_ptr ToolAction, + const Twine &Code, const Twine &FileName, std::shared_ptr PCHContainerOps) { - return runToolOnCodeWithArgs(ToolAction, Code, std::vector(), - FileName, "clang-tool", - std::move(PCHContainerOps)); + return runToolOnCodeWithArgs(std::move(ToolAction), Code, + std::vector(), FileName, + "clang-tool", std::move(PCHContainerOps)); } } // namespace tooling @@ -151,7 +151,7 @@ namespace tooling { bool runToolOnCodeWithArgs( - FrontendAction *ToolAction, const Twine &Code, + std::unique_ptr ToolAction, const Twine &Code, llvm::IntrusiveRefCntPtr VFS, const std::vector &Args, const Twine &FileName, const Twine &ToolName, @@ -164,13 +164,12 @@ ArgumentsAdjuster Adjuster = getClangStripDependencyFileAdjuster(); ToolInvocation Invocation( getSyntaxOnlyToolArgs(ToolName, Adjuster(Args, FileNameRef), FileNameRef), - ToolAction, Files.get(), - std::move(PCHContainerOps)); + std::move(ToolAction), Files.get(), std::move(PCHContainerOps)); return Invocation.run(); } bool runToolOnCodeWithArgs( - FrontendAction *ToolAction, const Twine &Code, + std::unique_ptr ToolAction, const Twine &Code, const std::vector &Args, const Twine &FileName, const Twine &ToolName, std::shared_ptr PCHContainerOps, @@ -192,8 +191,8 @@ llvm::MemoryBuffer::getMemBuffer(FilenameWithContent.second)); } - return runToolOnCodeWithArgs(ToolAction, Code, OverlayFileSystem, Args, - FileName, ToolName); + return runToolOnCodeWithArgs(std::move(ToolAction), Code, OverlayFileSystem, + Args, FileName, ToolName); } llvm::Expected getAbsolutePath(llvm::vfs::FileSystem &FS, @@ -267,11 +266,11 @@ Files(Files), PCHContainerOps(std::move(PCHContainerOps)) {} ToolInvocation::ToolInvocation( - std::vector CommandLine, FrontendAction *FAction, - FileManager *Files, std::shared_ptr PCHContainerOps) + std::vector CommandLine, + std::unique_ptr FAction, FileManager *Files, + std::shared_ptr PCHContainerOps) : CommandLine(std::move(CommandLine)), - Action(new SingleFrontendActionFactory( - std::unique_ptr(FAction))), + Action(new SingleFrontendActionFactory(std::move(FAction))), OwnsAction(true), Files(Files), PCHContainerOps(std::move(PCHContainerOps)) {} diff --git a/clang/unittests/AST/EvaluateAsRValueTest.cpp b/clang/unittests/AST/EvaluateAsRValueTest.cpp --- a/clang/unittests/AST/EvaluateAsRValueTest.cpp +++ b/clang/unittests/AST/EvaluateAsRValueTest.cpp @@ -89,22 +89,22 @@ std::vector Args(1, Mode); Args.push_back("-fno-delayed-template-parsing"); ASSERT_TRUE(runToolOnCodeWithArgs( - new EvaluateConstantInitializersAction(), - "template " - "struct vector {" - " explicit vector(int size);" - "};" - "template " - "struct S {" - " vector intervals() const {" - " vector Dependent(2);" - " return Dependent;" - " }" - "};" - "void doSomething() {" - " int Constant = 2 + 2;" - " (void) Constant;" - "}", - Args)); + std::make_unique(), + "template " + "struct vector {" + " explicit vector(int size);" + "};" + "template " + "struct S {" + " vector intervals() const {" + " vector 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 --- a/clang/unittests/AST/RecursiveASTVisitorTest.cpp +++ b/clang/unittests/AST/RecursiveASTVisitorTest.cpp @@ -84,7 +84,7 @@ std::vector collectEvents(llvm::StringRef Code) { CollectInterestingEvents Visitor; clang::tooling::runToolOnCode( - new ProcessASTAction( + std::make_unique( [&](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 --- a/clang/unittests/CrossTU/CrossTranslationUnitTest.cpp +++ b/clang/unittests/CrossTU/CrossTranslationUnitTest.cpp @@ -134,15 +134,15 @@ TEST(CrossTranslationUnit, CanLoadFunctionDefinition) { bool Success = false; - EXPECT_TRUE( - tooling::runToolOnCode(new CTUAction(&Success, 1u), "int f(int);")); + EXPECT_TRUE(tooling::runToolOnCode(std::make_unique(&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(&Success, 0u), + "int f(int);")); EXPECT_FALSE(Success); } diff --git a/clang/unittests/Index/IndexTests.cpp b/clang/unittests/Index/IndexTests.cpp --- a/clang/unittests/Index/IndexTests.cpp +++ b/clang/unittests/Index/IndexTests.cpp @@ -155,7 +155,8 @@ TEST(IndexTest, Simple) { auto Index = std::make_shared(); - tooling::runToolOnCode(new IndexAction(Index), "class X {}; void f() {}"); + tooling::runToolOnCode(std::make_unique(Index), + "class X {}; void f() {}"); EXPECT_THAT(Index->Symbols, UnorderedElementsAre(QName("X"), QName("f"))); } @@ -164,12 +165,12 @@ auto Index = std::make_shared(); IndexingOptions Opts; Opts.IndexMacrosInPreprocessor = true; - tooling::runToolOnCode(new IndexAction(Index, Opts), Code); + tooling::runToolOnCode(std::make_unique(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(Index, Opts), Code); EXPECT_THAT(Index->Symbols, UnorderedElementsAre()); } @@ -179,12 +180,12 @@ IndexingOptions Opts; Opts.IndexFunctionLocals = true; Opts.IndexParametersInDeclarations = true; - tooling::runToolOnCode(new IndexAction(Index, Opts), Code); + tooling::runToolOnCode(std::make_unique(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(Index, Opts), Code); EXPECT_THAT(Index->Symbols, Not(Contains(QName("bar")))); } @@ -201,7 +202,7 @@ )cpp"; auto Index = std::make_shared(); IndexingOptions Opts; - tooling::runToolOnCode(new IndexAction(Index, Opts), Code); + tooling::runToolOnCode(std::make_unique(Index, Opts), Code); EXPECT_THAT(Index->Symbols, AllOf(Contains(AllOf(QName("Foo"), WrittenAt(Position(8, 7)), DeclAt(Position(5, 12)))), @@ -222,7 +223,7 @@ )cpp"; auto Index = std::make_shared(); IndexingOptions Opts; - tooling::runToolOnCode(new IndexAction(Index, Opts), Code); + tooling::runToolOnCode(std::make_unique(Index, Opts), Code); EXPECT_THAT(Index->Symbols, Contains(AllOf(QName("Foo"), WrittenAt(Position(8, 7)), DeclAt(Position(5, 12))))); @@ -238,7 +239,7 @@ )cpp"; auto Index = std::make_shared(); IndexingOptions Opts; - tooling::runToolOnCode(new IndexAction(Index, Opts), Code); + tooling::runToolOnCode(std::make_unique(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 @@ Opts.IndexTemplateParameters = true; Index->Symbols.clear(); - tooling::runToolOnCode(new IndexAction(Index, Opts), Code); + tooling::runToolOnCode(std::make_unique(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 @@ )cpp"; auto Index = std::make_shared(); IndexingOptions Opts; - tooling::runToolOnCode(new IndexAction(Index, Opts), Code); + tooling::runToolOnCode(std::make_unique(Index, Opts), Code); EXPECT_THAT(Index->Symbols, Contains(AllOf(QName("std::foo"), Kind(SymbolKind::Using)))); } @@ -275,7 +276,7 @@ )cpp"; auto Index = std::make_shared(); IndexingOptions Opts; - tooling::runToolOnCode(new IndexAction(Index, Opts), Code); + tooling::runToolOnCode(std::make_unique(Index, Opts), Code); EXPECT_THAT( Index->Symbols, UnorderedElementsAre( diff --git a/clang/unittests/Sema/CodeCompleteTest.cpp b/clang/unittests/Sema/CodeCompleteTest.cpp --- a/clang/unittests/Sema/CodeCompleteTest.cpp +++ b/clang/unittests/Sema/CodeCompleteTest.cpp @@ -101,10 +101,10 @@ CompletionContext runCompletion(StringRef Code, size_t Offset) { CompletionContext ResultCtx; - auto Action = std::make_unique( - offsetToPosition(Code, Offset), ResultCtx); - clang::tooling::runToolOnCodeWithArgs(Action.release(), Code, {"-std=c++11"}, - TestCCName); + clang::tooling::runToolOnCodeWithArgs( + std::make_unique(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 --- a/clang/unittests/Sema/ExternalSemaSourceTest.cpp +++ b/clang/unittests/Sema/ExternalSemaSourceTest.cpp @@ -220,28 +220,26 @@ // Make sure that the DiagnosticWatcher is not miscounting. TEST(ExternalSemaSource, SanityCheck) { - std::unique_ptr Installer( - new ExternalSemaSourceInstaller); + auto Installer = std::make_unique(); DiagnosticWatcher Watcher("AAB", "BBB"); Installer->PushWatcher(&Watcher); std::vector 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 Installer( - new ExternalSemaSourceInstaller); + auto Installer = std::make_unique(); NamespaceTypoProvider Provider("AAB", "BBB"); DiagnosticWatcher Watcher("AAB", "BBB"); Installer->PushSource(&Provider); Installer->PushWatcher(&Watcher); std::vector 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 @@ // Check that we use the first successful TypoCorrection returned from an // ExternalSemaSource. TEST(ExternalSemaSource, ExternalTypoCorrectionOrdering) { - std::unique_ptr Installer( - new ExternalSemaSourceInstaller); + auto Installer = std::make_unique(); NamespaceTypoProvider First("XXX", "BBB"); NamespaceTypoProvider Second("AAB", "CCC"); NamespaceTypoProvider Third("AAB", "DDD"); @@ -261,7 +258,7 @@ Installer->PushWatcher(&Watcher); std::vector 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, ExternalDelayedTypoCorrection) { - std::unique_ptr Installer( - new ExternalSemaSourceInstaller); + auto Installer = std::make_unique(); FunctionTypoProvider Provider("aaa", "bbb"); DiagnosticWatcher Watcher("aaa", "bbb"); Installer->PushSource(&Provider); Installer->PushWatcher(&Watcher); std::vector 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 @@ // We should only try MaybeDiagnoseMissingCompleteType if we can't otherwise // solve the problem. TEST(ExternalSemaSource, TryOtherTacticsBeforeDiagnosing) { - std::unique_ptr Installer( - new ExternalSemaSourceInstaller); + auto Installer = std::make_unique(); CompleteTypeDiagnoser Diagnoser(false); Installer->PushSource(&Diagnoser); std::vector 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 struct S { class C { }; }; S::C SCInst;", Args)); ASSERT_EQ(0, Diagnoser.CallCount); @@ -303,8 +298,7 @@ // The first ExternalSemaSource where MaybeDiagnoseMissingCompleteType returns // true should be the last one called. TEST(ExternalSemaSource, FirstDiagnoserTaken) { - std::unique_ptr Installer( - new ExternalSemaSourceInstaller); + auto Installer = std::make_unique(); CompleteTypeDiagnoser First(false); CompleteTypeDiagnoser Second(true); CompleteTypeDiagnoser Third(true); @@ -313,7 +307,7 @@ Installer->PushSource(&Third); std::vector 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 --- a/clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp +++ b/clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp @@ -100,30 +100,30 @@ TEST(CallEvent, CallDescription) { // Test simple name matching. EXPECT_TRUE(tooling::runToolOnCode( - new CallDescriptionAction({ + std::unique_ptr(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(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(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(new CallDescriptionAction({ {{{"std", "basic_string", "c_str"}}, true}, - }), + })), "namespace std { inline namespace __1 {" " template class basic_string {" " public:" @@ -138,18 +138,18 @@ // A negative test for qualified names. EXPECT_TRUE(tooling::runToolOnCode( - new CallDescriptionAction({ + std::unique_ptr(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(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 --- a/clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp +++ b/clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp @@ -58,7 +58,8 @@ template bool runCheckerOnCode(const std::string &Code, std::string &Diags) { llvm::raw_string_ostream OS(Diags); - return tooling::runToolOnCode(new TestAction(OS), Code); + return tooling::runToolOnCode(std::make_unique>(OS), + Code); } template bool runCheckerOnCode(const std::string &Code) { diff --git a/clang/unittests/StaticAnalyzer/StoreTest.cpp b/clang/unittests/StaticAnalyzer/StoreTest.cpp --- a/clang/unittests/StaticAnalyzer/StoreTest.cpp +++ b/clang/unittests/StaticAnalyzer/StoreTest.cpp @@ -96,8 +96,8 @@ }; TEST(Store, VariableBind) { - EXPECT_TRUE(tooling::runToolOnCode( - new VariableBindAction, "void foo() { int x0, y0, z0, x1, y1; }")); + EXPECT_TRUE(tooling::runToolOnCode(std::make_unique(), + "void foo() { int x0, y0, z0, x1, y1; }")); } } // namespace diff --git a/clang/unittests/StaticAnalyzer/SymbolReaperTest.cpp b/clang/unittests/StaticAnalyzer/SymbolReaperTest.cpp --- a/clang/unittests/StaticAnalyzer/SymbolReaperTest.cpp +++ b/clang/unittests/StaticAnalyzer/SymbolReaperTest.cpp @@ -61,8 +61,9 @@ // 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(), + "void foo() { struct S { int x; } s; }")); } } // namespace diff --git a/clang/unittests/Tooling/CommentHandlerTest.cpp b/clang/unittests/Tooling/CommentHandlerTest.cpp --- a/clang/unittests/Tooling/CommentHandlerTest.cpp +++ b/clang/unittests/Tooling/CommentHandlerTest.cpp @@ -55,8 +55,8 @@ CommentVerifier GetVerifier(); protected: - ASTFrontendAction *CreateTestAction() override { - return new CommentHandlerAction(this); + std::unique_ptr CreateTestAction() override { + return std::make_unique(this); } private: diff --git a/clang/unittests/Tooling/RefactoringTest.cpp b/clang/unittests/Tooling/RefactoringTest.cpp --- a/clang/unittests/Tooling/RefactoringTest.cpp +++ b/clang/unittests/Tooling/RefactoringTest.cpp @@ -650,7 +650,7 @@ class TestVisitor : public clang::RecursiveASTVisitor { public: bool runOver(StringRef Code) { - return runToolOnCode(new TestAction(this), Code); + return runToolOnCode(std::make_unique(this), Code); } protected: diff --git a/clang/unittests/Tooling/TestVisitor.h b/clang/unittests/Tooling/TestVisitor.h --- a/clang/unittests/Tooling/TestVisitor.h +++ b/clang/unittests/Tooling/TestVisitor.h @@ -85,8 +85,8 @@ } protected: - virtual ASTFrontendAction* CreateTestAction() { - return new TestAction(this); + virtual std::unique_ptr CreateTestAction() { + return std::make_unique(this); } class FindConsumer : public ASTConsumer { diff --git a/clang/unittests/Tooling/ToolingTest.cpp b/clang/unittests/Tooling/ToolingTest.cpp --- a/clang/unittests/Tooling/ToolingTest.cpp +++ b/clang/unittests/Tooling/ToolingTest.cpp @@ -62,10 +62,10 @@ TEST(runToolOnCode, FindsNoTopLevelDeclOnEmptyCode) { bool FoundTopLevelDecl = false; - EXPECT_TRUE( - runToolOnCode(new TestAction(std::make_unique( - &FoundTopLevelDecl)), - "")); + EXPECT_TRUE(runToolOnCode( + std::make_unique( + std::make_unique(&FoundTopLevelDecl)), + "")); EXPECT_FALSE(FoundTopLevelDecl); } @@ -102,17 +102,17 @@ TEST(runToolOnCode, FindsClassDecl) { bool FoundClassDeclX = false; - EXPECT_TRUE( - runToolOnCode(new TestAction(std::make_unique( - &FoundClassDeclX)), - "class X;")); + EXPECT_TRUE(runToolOnCode( + std::make_unique( + std::make_unique(&FoundClassDeclX)), + "class X;")); EXPECT_TRUE(FoundClassDeclX); FoundClassDeclX = false; - EXPECT_TRUE( - runToolOnCode(new TestAction(std::make_unique( - &FoundClassDeclX)), - "class Y;")); + EXPECT_TRUE(runToolOnCode( + std::make_unique( + std::make_unique(&FoundClassDeclX)), + "class Y;")); EXPECT_FALSE(FoundClassDeclX); } @@ -160,8 +160,8 @@ 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(), Files.get()); InMemoryFileSystem->addFile( "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("#include \n")); InMemoryFileSystem->addFile("def/abc", 0, @@ -186,8 +186,8 @@ 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(), Files.get()); InMemoryFileSystem->addFile( "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("#include \n")); InMemoryFileSystem->addFile("def/abc", 0, @@ -257,61 +257,61 @@ std::vector Args = {"-std=c++11"}; std::vector Args2 = {"-fno-delayed-template-parsing"}; - EXPECT_TRUE(runToolOnCode(new SkipBodyAction, + EXPECT_TRUE(runToolOnCode(std::make_unique(), "int skipMe() { an_error_here }")); - EXPECT_FALSE(runToolOnCode(new SkipBodyAction, + EXPECT_FALSE(runToolOnCode(std::make_unique(), "int skipMeNot() { an_error_here }")); // Test constructors with initializers EXPECT_TRUE(runToolOnCodeWithArgs( - new SkipBodyAction, + std::make_unique(), "struct skipMe { skipMe() : an_error() { more error } };", Args)); EXPECT_TRUE(runToolOnCodeWithArgs( - new SkipBodyAction, "struct skipMe { skipMe(); };" + std::make_unique(), "struct skipMe { skipMe(); };" "skipMe::skipMe() : an_error([](){;}) { more error }", Args)); EXPECT_TRUE(runToolOnCodeWithArgs( - new SkipBodyAction, "struct skipMe { skipMe(); };" + std::make_unique(), "struct skipMe { skipMe(); };" "skipMe::skipMe() : an_error{[](){;}} { more error }", Args)); EXPECT_TRUE(runToolOnCodeWithArgs( - new SkipBodyAction, + std::make_unique(), "struct skipMe { skipMe(); };" "skipMe::skipMe() : a(e)>>(), f{}, g() { error }", Args)); EXPECT_TRUE(runToolOnCodeWithArgs( - new SkipBodyAction, "struct skipMe { skipMe() : bases()... { error } };", + std::make_unique(), "struct skipMe { skipMe() : bases()... { error } };", Args)); EXPECT_FALSE(runToolOnCodeWithArgs( - new SkipBodyAction, "struct skipMeNot { skipMeNot() : an_error() { } };", + std::make_unique(), "struct skipMeNot { skipMeNot() : an_error() { } };", Args)); - EXPECT_FALSE(runToolOnCodeWithArgs(new SkipBodyAction, + EXPECT_FALSE(runToolOnCodeWithArgs(std::make_unique(), "struct skipMeNot { skipMeNot(); };" "skipMeNot::skipMeNot() : an_error() { }", Args)); // Try/catch EXPECT_TRUE(runToolOnCode( - new SkipBodyAction, + std::make_unique(), "void skipMe() try { an_error() } catch(error) { error };")); EXPECT_TRUE(runToolOnCode( - new SkipBodyAction, + std::make_unique(), "struct S { void skipMe() try { an_error() } catch(error) { error } };")); EXPECT_TRUE( - runToolOnCode(new SkipBodyAction, + runToolOnCode(std::make_unique(), "void skipMe() try { an_error() } catch(error) { error; }" "catch(error) { error } catch (error) { }")); EXPECT_FALSE(runToolOnCode( - new SkipBodyAction, + std::make_unique(), "void skipMe() try something;")); // don't crash while parsing // Template EXPECT_TRUE(runToolOnCode( - new SkipBodyAction, "template int skipMe() { an_error_here }" + std::make_unique(), "template int skipMe() { an_error_here }" "int x = skipMe();")); EXPECT_FALSE(runToolOnCodeWithArgs( - new SkipBodyAction, + std::make_unique(), "template int skipMeNot() { an_error_here }", Args2)); } @@ -325,7 +325,7 @@ 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(), "", Args)); EXPECT_FALSE(llvm::sys::fs::exists(DepFilePath.str())); EXPECT_FALSE(llvm::sys::fs::remove(DepFilePath.str())); } @@ -348,24 +348,26 @@ }; 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(true), "", + {"-fcolor-diagnostics"})); + EXPECT_TRUE(runToolOnCodeWithArgs( + std::make_unique(false), "", + {"-fno-color-diagnostics"})); + EXPECT_TRUE(runToolOnCodeWithArgs( + std::make_unique(true), "", + {"-fno-color-diagnostics", "-fcolor-diagnostics"})); + EXPECT_TRUE(runToolOnCodeWithArgs( + std::make_unique(false), "", + {"-fcolor-diagnostics", "-fno-color-diagnostics"})); + EXPECT_TRUE(runToolOnCodeWithArgs( + std::make_unique(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(false), "", + {"-fcolor-diagnostics"})); } TEST(ClangToolTest, ArgumentAdjusters) { @@ -657,7 +659,7 @@ // Should not crash EXPECT_FALSE( - runToolOnCode(new ResetDiagnosticAction, + runToolOnCode(std::make_unique(), "struct Foo { Foo(int); ~Foo(); struct Fwd _fwd; };" "void func() { long x; Foo f(x); }")); }