From: Roman Lebedev Date: Tue, 27 Feb 2018 15:54:55 +0000 (+0000) Subject: Revert "[Tooling] [0/1] Refactor FrontendActionFactory::create() to return std::uniqu... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b2349051ab0cb25c90ba2fa80482e380d32a4263;p=clang Revert "[Tooling] [0/1] Refactor FrontendActionFactory::create() to return std::unique_ptr<>" This reverts commit rL326201 This broke gcc4.8 builds, compiler just segfaults:¬ http://lab.llvm.org:8011/builders/clang-atom-d525-fedora-rel/builds/14909¬ http://lab.llvm.org:8011/builders/clang-x86_64-linux-abi-test/builds/22673¬ git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326204 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/docs/LibTooling.rst b/docs/LibTooling.rst index 848fa79bb6..75ef6a0fe7 100644 --- a/docs/LibTooling.rst +++ b/docs/LibTooling.rst @@ -34,7 +34,7 @@ looked for. Let me give you an example: TEST(runToolOnCode, CanSyntaxCheckCode) { // runToolOnCode returns whether the action was correctly run over the // given code. - EXPECT_TRUE(runToolOnCode(llvm::make_unique(), "class X {};")); + EXPECT_TRUE(runToolOnCode(new clang::SyntaxOnlyAction, "class X {};")); } Writing a standalone tool diff --git a/docs/RAVFrontendAction.rst b/docs/RAVFrontendAction.rst index d62879ffd0..c37d3c0e81 100644 --- a/docs/RAVFrontendAction.rst +++ b/docs/RAVFrontendAction.rst @@ -196,7 +196,7 @@ Now we can combine all of the above into a small example program: int main(int argc, char **argv) { if (argc > 1) { - clang::tooling::runToolOnCode(llvm::make_unique(), argv[1]); + clang::tooling::runToolOnCode(new FindNamedClassAction, argv[1]); } } diff --git a/include/clang/Tooling/Tooling.h b/include/clang/Tooling/Tooling.h index 14cbf015b0..8ddfef3707 100644 --- a/include/clang/Tooling/Tooling.h +++ b/include/clang/Tooling/Tooling.h @@ -94,7 +94,7 @@ public: /// \brief Returns a new clang::FrontendAction. /// /// The caller takes ownership of the returned action. - virtual std::unique_ptr create() = 0; + virtual clang::FrontendAction *create() = 0; }; /// \brief Returns a new FrontendActionFactory for a given type. @@ -149,8 +149,8 @@ inline std::unique_ptr newFrontendActionFactory( /// clang modules. /// /// \return - True if 'ToolAction' was successfully executed. -bool runToolOnCode(std::unique_ptr ToolAction, - const Twine &Code, const Twine &FileName = "input.cc", +bool runToolOnCode(clang::FrontendAction *ToolAction, const Twine &Code, + const Twine &FileName = "input.cc", std::shared_ptr PCHContainerOps = std::make_shared()); @@ -172,7 +172,7 @@ typedef std::vector> FileContentMappings; /// /// \return - True if 'ToolAction' was successfully executed. bool runToolOnCodeWithArgs( - std::unique_ptr ToolAction, const Twine &Code, + clang::FrontendAction *ToolAction, const Twine &Code, const std::vector &Args, const Twine &FileName = "input.cc", const Twine &ToolName = "clang-tool", std::shared_ptr PCHContainerOps = @@ -226,8 +226,8 @@ public: /// ownership. /// \param PCHContainerOps The PCHContainerOperations for loading and creating /// clang modules. - ToolInvocation(std::vector CommandLine, - std::unique_ptr FAction, FileManager *Files, + ToolInvocation(std::vector CommandLine, FrontendAction *FAction, + FileManager *Files, std::shared_ptr PCHContainerOps = std::make_shared()); @@ -367,9 +367,7 @@ template std::unique_ptr newFrontendActionFactory() { class SimpleFrontendActionFactory : public FrontendActionFactory { public: - std::unique_ptr create() override { - return llvm::make_unique(); - } + clang::FrontendAction *create() override { return new T; } }; return std::unique_ptr( @@ -385,9 +383,8 @@ inline std::unique_ptr newFrontendActionFactory( SourceFileCallbacks *Callbacks) : ConsumerFactory(ConsumerFactory), Callbacks(Callbacks) {} - std::unique_ptr create() override { - return llvm::make_unique(ConsumerFactory, - Callbacks); + clang::FrontendAction *create() override { + return new ConsumerFactoryAdaptor(ConsumerFactory, Callbacks); } private: diff --git a/lib/Tooling/Tooling.cpp b/lib/Tooling/Tooling.cpp index 82abede803..7ae2950037 100644 --- a/lib/Tooling/Tooling.cpp +++ b/lib/Tooling/Tooling.cpp @@ -104,12 +104,12 @@ clang::CompilerInvocation *newInvocation( return Invocation; } -bool runToolOnCode(std::unique_ptr ToolAction, - const Twine &Code, const Twine &FileName, +bool runToolOnCode(clang::FrontendAction *ToolAction, const Twine &Code, + const Twine &FileName, std::shared_ptr PCHContainerOps) { - return runToolOnCodeWithArgs(std::move(ToolAction), Code, - std::vector(), FileName, - "clang-tool", std::move(PCHContainerOps)); + return runToolOnCodeWithArgs(ToolAction, Code, std::vector(), + FileName, "clang-tool", + std::move(PCHContainerOps)); } static std::vector @@ -125,7 +125,7 @@ getSyntaxOnlyToolArgs(const Twine &ToolName, } bool runToolOnCodeWithArgs( - std::unique_ptr ToolAction, const Twine &Code, + clang::FrontendAction *ToolAction, const Twine &Code, const std::vector &Args, const Twine &FileName, const Twine &ToolName, std::shared_ptr PCHContainerOps, @@ -143,7 +143,8 @@ bool runToolOnCodeWithArgs( ArgumentsAdjuster Adjuster = getClangStripDependencyFileAdjuster(); ToolInvocation Invocation( getSyntaxOnlyToolArgs(ToolName, Adjuster(Args, FileNameRef), FileNameRef), - std::move(ToolAction), Files.get(), std::move(PCHContainerOps)); + ToolAction, Files.get(), + std::move(PCHContainerOps)); SmallString<1024> CodeStorage; InMemoryFileSystem->addFile(FileNameRef, 0, @@ -203,18 +204,15 @@ void addTargetAndModeForProgramName(std::vector &CommandLine, namespace { class SingleFrontendActionFactory : public FrontendActionFactory { - std::unique_ptr Action; + FrontendAction *Action; public: - SingleFrontendActionFactory(std::unique_ptr Action) - : Action(std::move(Action)) {} + SingleFrontendActionFactory(FrontendAction *Action) : Action(Action) {} - std::unique_ptr create() override { - return std::move(Action); - } + FrontendAction *create() override { return Action; } }; -} // namespace +} ToolInvocation::ToolInvocation( std::vector CommandLine, ToolAction *Action, @@ -224,13 +222,12 @@ ToolInvocation::ToolInvocation( DiagConsumer(nullptr) {} ToolInvocation::ToolInvocation( - std::vector CommandLine, - std::unique_ptr FAction, FileManager *Files, - std::shared_ptr PCHContainerOps) + std::vector CommandLine, FrontendAction *FAction, + FileManager *Files, std::shared_ptr PCHContainerOps) : CommandLine(std::move(CommandLine)), - Action(new SingleFrontendActionFactory(std::move(FAction))), - OwnsAction(true), Files(Files), - PCHContainerOps(std::move(PCHContainerOps)), DiagConsumer(nullptr) {} + Action(new SingleFrontendActionFactory(FAction)), OwnsAction(true), + Files(Files), PCHContainerOps(std::move(PCHContainerOps)), + DiagConsumer(nullptr) {} ToolInvocation::~ToolInvocation() { if (OwnsAction) diff --git a/tools/clang-refactor/ClangRefactor.cpp b/tools/clang-refactor/ClangRefactor.cpp index 925bc908a4..950b80062c 100644 --- a/tools/clang-refactor/ClangRefactor.cpp +++ b/tools/clang-refactor/ClangRefactor.cpp @@ -462,9 +462,7 @@ public: ToolActionFactory(TUCallbackType Callback) : Callback(std::move(Callback)) {} - std::unique_ptr create() override { - return llvm::make_unique(Callback); - } + FrontendAction *create() override { return new ToolASTAction(Callback); } private: TUCallbackType Callback; diff --git a/unittests/AST/EvaluateAsRValueTest.cpp b/unittests/AST/EvaluateAsRValueTest.cpp index 27371cc72b..820edbc7c3 100644 --- a/unittests/AST/EvaluateAsRValueTest.cpp +++ b/unittests/AST/EvaluateAsRValueTest.cpp @@ -90,7 +90,7 @@ TEST(EvaluateAsRValue, FailsGracefullyForUnknownTypes) { std::vector Args(1, Mode); Args.push_back("-fno-delayed-template-parsing"); ASSERT_TRUE(runToolOnCodeWithArgs( - llvm::make_unique(), + new EvaluateConstantInitializersAction(), "template " "struct vector {" " explicit vector(int size);" diff --git a/unittests/CrossTU/CrossTranslationUnitTest.cpp b/unittests/CrossTU/CrossTranslationUnitTest.cpp index 886e7fb2e6..5fbf56ed43 100644 --- a/unittests/CrossTU/CrossTranslationUnitTest.cpp +++ b/unittests/CrossTU/CrossTranslationUnitTest.cpp @@ -103,8 +103,7 @@ private: TEST(CrossTranslationUnit, CanLoadFunctionDefinition) { bool Success = false; - EXPECT_TRUE(tooling::runToolOnCode(llvm::make_unique(&Success), - "int f(int);")); + EXPECT_TRUE(tooling::runToolOnCode(new CTUAction(&Success), "int f(int);")); EXPECT_TRUE(Success); } diff --git a/unittests/Sema/CodeCompleteTest.cpp b/unittests/Sema/CodeCompleteTest.cpp index 7eb776e8eb..8e888cbe52 100644 --- a/unittests/Sema/CodeCompleteTest.cpp +++ b/unittests/Sema/CodeCompleteTest.cpp @@ -100,7 +100,7 @@ VisitedContextResults runCodeCompleteOnCode(StringRef Code) { auto Action = llvm::make_unique( offsetToPosition(WithoutToken, TokenOffset), Results); - clang::tooling::runToolOnCodeWithArgs(std::move(Action), Code, {"-std=c++11"}, + clang::tooling::runToolOnCodeWithArgs(Action.release(), Code, {"-std=c++11"}, TestCCName); return Results; } diff --git a/unittests/Sema/ExternalSemaSourceTest.cpp b/unittests/Sema/ExternalSemaSourceTest.cpp index 840861fb85..d2cdd633fa 100644 --- a/unittests/Sema/ExternalSemaSourceTest.cpp +++ b/unittests/Sema/ExternalSemaSourceTest.cpp @@ -221,26 +221,28 @@ public: // Make sure that the DiagnosticWatcher is not miscounting. TEST(ExternalSemaSource, SanityCheck) { - auto Installer = llvm::make_unique(); + std::unique_ptr Installer( + new ExternalSemaSourceInstaller); DiagnosticWatcher Watcher("AAB", "BBB"); Installer->PushWatcher(&Watcher); std::vector Args(1, "-std=c++11"); ASSERT_TRUE(clang::tooling::runToolOnCodeWithArgs( - std::move(Installer), "namespace AAA { } using namespace AAB;", Args)); + Installer.release(), "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) { - auto Installer = llvm::make_unique(); + std::unique_ptr Installer( + new ExternalSemaSourceInstaller); 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( - std::move(Installer), "namespace AAA { } using namespace AAB;", Args)); + Installer.release(), "namespace AAA { } using namespace AAB;", Args)); ASSERT_LE(0, Provider.CallCount); ASSERT_EQ(1, Watcher.SeenCount); } @@ -248,7 +250,8 @@ TEST(ExternalSemaSource, ExternalTypoCorrectionPrioritized) { // Check that we use the first successful TypoCorrection returned from an // ExternalSemaSource. TEST(ExternalSemaSource, ExternalTypoCorrectionOrdering) { - auto Installer = llvm::make_unique(); + std::unique_ptr Installer( + new ExternalSemaSourceInstaller); NamespaceTypoProvider First("XXX", "BBB"); NamespaceTypoProvider Second("AAB", "CCC"); NamespaceTypoProvider Third("AAB", "DDD"); @@ -259,7 +262,7 @@ TEST(ExternalSemaSource, ExternalTypoCorrectionOrdering) { Installer->PushWatcher(&Watcher); std::vector Args(1, "-std=c++11"); ASSERT_TRUE(clang::tooling::runToolOnCodeWithArgs( - std::move(Installer), "namespace AAA { } using namespace AAB;", Args)); + Installer.release(), "namespace AAA { } using namespace AAB;", Args)); ASSERT_LE(1, First.CallCount); ASSERT_LE(1, Second.CallCount); ASSERT_EQ(0, Third.CallCount); @@ -267,14 +270,15 @@ TEST(ExternalSemaSource, ExternalTypoCorrectionOrdering) { } TEST(ExternalSemaSource, ExternalDelayedTypoCorrection) { - auto Installer = llvm::make_unique(); + std::unique_ptr Installer( + new ExternalSemaSourceInstaller); 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( - std::move(Installer), "namespace AAA { } void foo() { AAA::aaa(); }", + Installer.release(), "namespace AAA { } void foo() { AAA::aaa(); }", Args)); ASSERT_LE(0, Provider.CallCount); ASSERT_EQ(1, Watcher.SeenCount); @@ -283,14 +287,15 @@ TEST(ExternalSemaSource, ExternalDelayedTypoCorrection) { // We should only try MaybeDiagnoseMissingCompleteType if we can't otherwise // solve the problem. TEST(ExternalSemaSource, TryOtherTacticsBeforeDiagnosing) { - auto Installer = llvm::make_unique(); + std::unique_ptr Installer( + new ExternalSemaSourceInstaller); 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( - std::move(Installer), + Installer.release(), "template struct S { class C { }; }; S::C SCInst;", Args)); ASSERT_EQ(0, Diagnoser.CallCount); @@ -299,7 +304,8 @@ TEST(ExternalSemaSource, TryOtherTacticsBeforeDiagnosing) { // The first ExternalSemaSource where MaybeDiagnoseMissingCompleteType returns // true should be the last one called. TEST(ExternalSemaSource, FirstDiagnoserTaken) { - auto Installer = llvm::make_unique(); + std::unique_ptr Installer( + new ExternalSemaSourceInstaller); CompleteTypeDiagnoser First(false); CompleteTypeDiagnoser Second(true); CompleteTypeDiagnoser Third(true); @@ -308,7 +314,7 @@ TEST(ExternalSemaSource, FirstDiagnoserTaken) { Installer->PushSource(&Third); std::vector Args(1, "-std=c++11"); ASSERT_FALSE(clang::tooling::runToolOnCodeWithArgs( - std::move(Installer), "class Incomplete; Incomplete IncompleteInstance;", + Installer.release(), "class Incomplete; Incomplete IncompleteInstance;", Args)); ASSERT_EQ(1, First.CallCount); ASSERT_EQ(1, Second.CallCount); diff --git a/unittests/Tooling/CommentHandlerTest.cpp b/unittests/Tooling/CommentHandlerTest.cpp index 682f19e9b1..9c3abdc4b1 100644 --- a/unittests/Tooling/CommentHandlerTest.cpp +++ b/unittests/Tooling/CommentHandlerTest.cpp @@ -56,8 +56,8 @@ public: CommentVerifier GetVerifier(); protected: - std::unique_ptr CreateTestAction() override { - return llvm::make_unique(this); + ASTFrontendAction *CreateTestAction() override { + return new CommentHandlerAction(this); } private: diff --git a/unittests/Tooling/ExecutionTest.cpp b/unittests/Tooling/ExecutionTest.cpp index 19e5de7823..26db8c6d0e 100644 --- a/unittests/Tooling/ExecutionTest.cpp +++ b/unittests/Tooling/ExecutionTest.cpp @@ -79,9 +79,7 @@ private: class ReportResultActionFactory : public FrontendActionFactory { public: ReportResultActionFactory(ExecutionContext *Context) : Context(Context) {} - std::unique_ptr create() override { - return llvm::make_unique(Context); - } + FrontendAction *create() override { return new ReportResultAction(Context); } private: ExecutionContext *const Context; diff --git a/unittests/Tooling/RefactoringTest.cpp b/unittests/Tooling/RefactoringTest.cpp index d9d82eb43f..41836f11ee 100644 --- a/unittests/Tooling/RefactoringTest.cpp +++ b/unittests/Tooling/RefactoringTest.cpp @@ -650,7 +650,7 @@ template class TestVisitor : public clang::RecursiveASTVisitor { public: bool runOver(StringRef Code) { - return runToolOnCode(llvm::make_unique(this), Code); + return runToolOnCode(new TestAction(this), Code); } protected: diff --git a/unittests/Tooling/TestVisitor.h b/unittests/Tooling/TestVisitor.h index acaaabfac7..fb6a76ccad 100644 --- a/unittests/Tooling/TestVisitor.h +++ b/unittests/Tooling/TestVisitor.h @@ -82,8 +82,8 @@ public: } protected: - virtual std::unique_ptr CreateTestAction() { - return llvm::make_unique(this); + virtual ASTFrontendAction* CreateTestAction() { + return new TestAction(this); } class FindConsumer : public ASTConsumer { diff --git a/unittests/Tooling/ToolingTest.cpp b/unittests/Tooling/ToolingTest.cpp index a4fb579038..6dd0e53c4d 100644 --- a/unittests/Tooling/ToolingTest.cpp +++ b/unittests/Tooling/ToolingTest.cpp @@ -64,10 +64,10 @@ class FindTopLevelDeclConsumer : public clang::ASTConsumer { TEST(runToolOnCode, FindsNoTopLevelDeclOnEmptyCode) { bool FoundTopLevelDecl = false; - EXPECT_TRUE(runToolOnCode( - llvm::make_unique( - llvm::make_unique(&FoundTopLevelDecl)), - "")); + EXPECT_TRUE( + runToolOnCode(new TestAction(llvm::make_unique( + &FoundTopLevelDecl)), + "")); EXPECT_FALSE(FoundTopLevelDecl); } @@ -104,17 +104,17 @@ bool FindClassDeclX(ASTUnit *AST) { TEST(runToolOnCode, FindsClassDecl) { bool FoundClassDeclX = false; - EXPECT_TRUE(runToolOnCode( - llvm::make_unique( - llvm::make_unique(&FoundClassDeclX)), - "class X;")); + EXPECT_TRUE( + runToolOnCode(new TestAction(llvm::make_unique( + &FoundClassDeclX)), + "class X;")); EXPECT_TRUE(FoundClassDeclX); FoundClassDeclX = false; - EXPECT_TRUE(runToolOnCode( - llvm::make_unique( - llvm::make_unique(&FoundClassDeclX)), - "class Y;")); + EXPECT_TRUE( + runToolOnCode(new TestAction(llvm::make_unique( + &FoundClassDeclX)), + "class Y;")); EXPECT_FALSE(FoundClassDeclX); } @@ -162,8 +162,8 @@ TEST(ToolInvocation, TestMapVirtualFile) { Args.push_back("-Idef"); Args.push_back("-fsyntax-only"); Args.push_back("test.cpp"); - clang::tooling::ToolInvocation Invocation( - Args, llvm::make_unique(), Files.get()); + clang::tooling::ToolInvocation Invocation(Args, new SyntaxOnlyAction, + Files.get()); InMemoryFileSystem->addFile( "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("#include \n")); InMemoryFileSystem->addFile("def/abc", 0, @@ -188,8 +188,8 @@ TEST(ToolInvocation, TestVirtualModulesCompilation) { Args.push_back("-Idef"); Args.push_back("-fsyntax-only"); Args.push_back("test.cpp"); - clang::tooling::ToolInvocation Invocation( - Args, llvm::make_unique(), Files.get()); + clang::tooling::ToolInvocation Invocation(Args, new SyntaxOnlyAction, + Files.get()); InMemoryFileSystem->addFile( "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("#include \n")); InMemoryFileSystem->addFile("def/abc", 0, @@ -259,64 +259,61 @@ TEST(runToolOnCode, TestSkipFunctionBody) { std::vector Args = {"-std=c++11"}; std::vector Args2 = {"-fno-delayed-template-parsing"}; - EXPECT_TRUE(runToolOnCode(llvm::make_unique(), + EXPECT_TRUE(runToolOnCode(new SkipBodyAction, "int skipMe() { an_error_here }")); - EXPECT_FALSE(runToolOnCode(llvm::make_unique(), + EXPECT_FALSE(runToolOnCode(new SkipBodyAction, "int skipMeNot() { an_error_here }")); // Test constructors with initializers EXPECT_TRUE(runToolOnCodeWithArgs( - llvm::make_unique(), + new SkipBodyAction, "struct skipMe { skipMe() : an_error() { more error } };", Args)); EXPECT_TRUE(runToolOnCodeWithArgs( - llvm::make_unique(), - "struct skipMe { skipMe(); };" - "skipMe::skipMe() : an_error([](){;}) { more error }", + new SkipBodyAction, "struct skipMe { skipMe(); };" + "skipMe::skipMe() : an_error([](){;}) { more error }", Args)); EXPECT_TRUE(runToolOnCodeWithArgs( - llvm::make_unique(), - "struct skipMe { skipMe(); };" - "skipMe::skipMe() : an_error{[](){;}} { more error }", + new SkipBodyAction, "struct skipMe { skipMe(); };" + "skipMe::skipMe() : an_error{[](){;}} { more error }", Args)); EXPECT_TRUE(runToolOnCodeWithArgs( - llvm::make_unique(), + new SkipBodyAction, "struct skipMe { skipMe(); };" "skipMe::skipMe() : a(e)>>(), f{}, g() { error }", Args)); EXPECT_TRUE(runToolOnCodeWithArgs( - llvm::make_unique(), - "struct skipMe { skipMe() : bases()... { error } };", Args)); + new SkipBodyAction, "struct skipMe { skipMe() : bases()... { error } };", + Args)); EXPECT_FALSE(runToolOnCodeWithArgs( - llvm::make_unique(), - "struct skipMeNot { skipMeNot() : an_error() { } };", Args)); - EXPECT_FALSE(runToolOnCodeWithArgs(llvm::make_unique(), + new SkipBodyAction, "struct skipMeNot { skipMeNot() : an_error() { } };", + Args)); + EXPECT_FALSE(runToolOnCodeWithArgs(new SkipBodyAction, "struct skipMeNot { skipMeNot(); };" "skipMeNot::skipMeNot() : an_error() { }", Args)); // Try/catch EXPECT_TRUE(runToolOnCode( - llvm::make_unique(), + new SkipBodyAction, "void skipMe() try { an_error() } catch(error) { error };")); EXPECT_TRUE(runToolOnCode( - llvm::make_unique(), + new SkipBodyAction, "struct S { void skipMe() try { an_error() } catch(error) { error } };")); EXPECT_TRUE( - runToolOnCode(llvm::make_unique(), + runToolOnCode(new SkipBodyAction, "void skipMe() try { an_error() } catch(error) { error; }" "catch(error) { error } catch (error) { }")); EXPECT_FALSE(runToolOnCode( - llvm::make_unique(), + new SkipBodyAction, "void skipMe() try something;")); // don't crash while parsing // Template - EXPECT_TRUE( - runToolOnCode(llvm::make_unique(), - "template int skipMe() { an_error_here }" - "int x = skipMe();")); + EXPECT_TRUE(runToolOnCode( + new SkipBodyAction, "template int skipMe() { an_error_here }" + "int x = skipMe();")); EXPECT_FALSE(runToolOnCodeWithArgs( - llvm::make_unique(), + new SkipBodyAction, "template int skipMeNot() { an_error_here }", Args2)); } @@ -330,8 +327,7 @@ TEST(runToolOnCodeWithArgs, TestNoDepFile) { Args.push_back(DepFilePath.str()); Args.push_back("-MF"); Args.push_back(DepFilePath.str()); - EXPECT_TRUE( - runToolOnCodeWithArgs(llvm::make_unique(), "", Args)); + EXPECT_TRUE(runToolOnCodeWithArgs(new SkipBodyAction, "", Args)); EXPECT_FALSE(llvm::sys::fs::exists(DepFilePath.str())); EXPECT_FALSE(llvm::sys::fs::remove(DepFilePath.str())); } @@ -355,26 +351,23 @@ 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( - llvm::make_unique(true), "", - {"-fcolor-diagnostics"})); - EXPECT_TRUE(runToolOnCodeWithArgs( - llvm::make_unique(false), "", - {"-fno-color-diagnostics"})); - EXPECT_TRUE(runToolOnCodeWithArgs( - llvm::make_unique(true), "", - {"-fno-color-diagnostics", "-fcolor-diagnostics"})); - EXPECT_TRUE(runToolOnCodeWithArgs( - llvm::make_unique(false), "", - {"-fcolor-diagnostics", "-fno-color-diagnostics"})); - EXPECT_TRUE(runToolOnCodeWithArgs( - llvm::make_unique(true), "", + new CheckColoredDiagnosticsAction(true), "", {"-fno-color-diagnostics", "-fdiagnostics-color=always"})); // Check that this test would fail if ShowColors is not what it should. - EXPECT_FALSE(runToolOnCodeWithArgs( - llvm::make_unique(false), "", - {"-fcolor-diagnostics"})); + EXPECT_FALSE(runToolOnCodeWithArgs(new CheckColoredDiagnosticsAction(false), + "", {"-fcolor-diagnostics"})); } TEST(ClangToolTest, ArgumentAdjusters) { @@ -610,7 +603,7 @@ TEST(runToolOnCode, TestResetDiagnostics) { // Should not crash EXPECT_FALSE( - runToolOnCode(llvm::make_unique(), + runToolOnCode(new ResetDiagnosticAction, "struct Foo { Foo(int); ~Foo(); struct Fwd _fwd; };" "void func() { long x; Foo f(x); }")); }