r370451 - [Tooling] Migrated APIs that take ownership of objects to unique_ptr

Dmitri Gribenko via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 30 02:29:35 PDT 2019


Author: gribozavr
Date: Fri Aug 30 02:29:34 2019
New Revision: 370451

URL: http://llvm.org/viewvc/llvm-project?rev=370451&view=rev
Log:
[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

Modified:
    cfe/trunk/docs/LibTooling.rst
    cfe/trunk/docs/RAVFrontendAction.rst
    cfe/trunk/docs/ReleaseNotes.rst
    cfe/trunk/include/clang/Tooling/Tooling.h
    cfe/trunk/lib/Tooling/Tooling.cpp
    cfe/trunk/unittests/AST/EvaluateAsRValueTest.cpp
    cfe/trunk/unittests/AST/RecursiveASTVisitorTest.cpp
    cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp
    cfe/trunk/unittests/Index/IndexTests.cpp
    cfe/trunk/unittests/Sema/CodeCompleteTest.cpp
    cfe/trunk/unittests/Sema/ExternalSemaSourceTest.cpp
    cfe/trunk/unittests/StaticAnalyzer/CallDescriptionTest.cpp
    cfe/trunk/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp
    cfe/trunk/unittests/StaticAnalyzer/StoreTest.cpp
    cfe/trunk/unittests/StaticAnalyzer/SymbolReaperTest.cpp
    cfe/trunk/unittests/Tooling/CommentHandlerTest.cpp
    cfe/trunk/unittests/Tooling/RefactoringTest.cpp
    cfe/trunk/unittests/Tooling/TestVisitor.h
    cfe/trunk/unittests/Tooling/ToolingTest.cpp

Modified: cfe/trunk/docs/LibTooling.rst
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibTooling.rst?rev=370451&r1=370450&r2=370451&view=diff
==============================================================================
--- cfe/trunk/docs/LibTooling.rst (original)
+++ cfe/trunk/docs/LibTooling.rst Fri Aug 30 02:29:34 2019
@@ -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(new clang::SyntaxOnlyAction, "class X {};"));
+    EXPECT_TRUE(runToolOnCode(std::make_unique<clang::SyntaxOnlyAction>(), "class X {};"));
   }
 
 Writing a standalone tool

Modified: cfe/trunk/docs/RAVFrontendAction.rst
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/RAVFrontendAction.rst?rev=370451&r1=370450&r2=370451&view=diff
==============================================================================
--- cfe/trunk/docs/RAVFrontendAction.rst (original)
+++ cfe/trunk/docs/RAVFrontendAction.rst Fri Aug 30 02:29:34 2019
@@ -196,7 +196,7 @@ Now we can combine all of the above into
 
       int main(int argc, char **argv) {
         if (argc > 1) {
-          clang::tooling::runToolOnCode(new FindNamedClassAction, argv[1]);
+          clang::tooling::runToolOnCode(std::make_unique<FindNamedClassAction>(), argv[1]);
         }
       }
 

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=370451&r1=370450&r2=370451&view=diff
==============================================================================
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Fri Aug 30 02:29:34 2019
@@ -148,6 +148,12 @@ These are major API changes that have ha
 Clang. If upgrading an external codebase that uses Clang as a library,
 this section should help get you past the largest hurdles of upgrading.
 
+- libTooling APIs that transfer ownership of `FrontendAction` objects now pass
+  them by `unique_ptr`, making the ownership transfer obvious in the type
+  system. `FrontendActionFactory::create()` now returns a
+  `unique_ptr<FrontendAction>`. `runToolOnCode`, `runToolOnCodeWithArgs`,
+  `ToolInvocation::ToolInvocation()` now take a `unique_ptr<FrontendAction>`.
+
 Build System Changes
 --------------------
 

Modified: cfe/trunk/include/clang/Tooling/Tooling.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Tooling.h?rev=370451&r1=370450&r2=370451&view=diff
==============================================================================
--- cfe/trunk/include/clang/Tooling/Tooling.h (original)
+++ cfe/trunk/include/clang/Tooling/Tooling.h Fri Aug 30 02:29:34 2019
@@ -154,19 +154,11 @@ inline std::unique_ptr<FrontendActionFac
 ///                         clang modules.
 ///
 /// \return - True if 'ToolAction' was successfully executed.
-bool runToolOnCode(FrontendAction *ToolAction, const Twine &Code,
+bool runToolOnCode(std::unique_ptr<FrontendAction> ToolAction, const Twine &Code,
                    const Twine &FileName = "input.cc",
                    std::shared_ptr<PCHContainerOperations> PCHContainerOps =
                        std::make_shared<PCHContainerOperations>());
 
-inline bool
-runToolOnCode(std::unique_ptr<FrontendAction> ToolAction, const Twine &Code,
-              const Twine &FileName = "input.cc",
-              std::shared_ptr<PCHContainerOperations> PCHContainerOps =
-                  std::make_shared<PCHContainerOperations>()) {
-  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<std::pair<std::string, std::string>>;
@@ -185,43 +177,21 @@ using FileContentMappings = std::vector<
 ///
 /// \return - True if 'ToolAction' was successfully executed.
 bool runToolOnCodeWithArgs(
-    FrontendAction *ToolAction, const Twine &Code,
-    const std::vector<std::string> &Args, const Twine &FileName = "input.cc",
-    const Twine &ToolName = "clang-tool",
-    std::shared_ptr<PCHContainerOperations> PCHContainerOps =
-        std::make_shared<PCHContainerOperations>(),
-    const FileContentMappings &VirtualMappedFiles = FileContentMappings());
-
-inline bool runToolOnCodeWithArgs(
     std::unique_ptr<FrontendAction> ToolAction, const Twine &Code,
     const std::vector<std::string> &Args, const Twine &FileName = "input.cc",
     const Twine &ToolName = "clang-tool",
     std::shared_ptr<PCHContainerOperations> PCHContainerOps =
         std::make_shared<PCHContainerOperations>(),
-    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<llvm::vfs::FileSystem> VFS,
-    const std::vector<std::string> &Args, const Twine &FileName = "input.cc",
-    const Twine &ToolName = "clang-tool",
-    std::shared_ptr<PCHContainerOperations> PCHContainerOps =
-        std::make_shared<PCHContainerOperations>());
-
-inline bool runToolOnCodeWithArgs(
     std::unique_ptr<FrontendAction> ToolAction, const Twine &Code,
     llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
     const std::vector<std::string> &Args, const Twine &FileName = "input.cc",
     const Twine &ToolName = "clang-tool",
     std::shared_ptr<PCHContainerOperations> PCHContainerOps =
-        std::make_shared<PCHContainerOperations>()) {
-  return runToolOnCodeWithArgs(ToolAction.release(), Code, VFS, Args, FileName,
-                               ToolName, PCHContainerOps);
-}
+        std::make_shared<PCHContainerOperations>());
 
 /// Builds an AST for 'Code'.
 ///
@@ -265,22 +235,15 @@ public:
   /// 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<std::string> CommandLine, FrontendAction *FAction,
-                 FileManager *Files,
-                 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
-                     std::make_shared<PCHContainerOperations>());
-
   ToolInvocation(std::vector<std::string> CommandLine,
                  std::unique_ptr<FrontendAction> FAction, FileManager *Files,
                  std::shared_ptr<PCHContainerOperations> PCHContainerOps =
-                     std::make_shared<PCHContainerOperations>())
-      : ToolInvocation(std::move(CommandLine), FAction.release(), Files,
-                       PCHContainerOps) {}
+                     std::make_shared<PCHContainerOperations>());
 
   /// Create a tool invocation.
   ///

Modified: cfe/trunk/lib/Tooling/Tooling.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Tooling.cpp?rev=370451&r1=370450&r2=370451&view=diff
==============================================================================
--- cfe/trunk/lib/Tooling/Tooling.cpp (original)
+++ cfe/trunk/lib/Tooling/Tooling.cpp Fri Aug 30 02:29:34 2019
@@ -124,12 +124,12 @@ CompilerInvocation *newInvocation(
   return Invocation;
 }
 
-bool runToolOnCode(FrontendAction *ToolAction, const Twine &Code,
-                   const Twine &FileName,
+bool runToolOnCode(std::unique_ptr<FrontendAction> ToolAction,
+                   const Twine &Code, const Twine &FileName,
                    std::shared_ptr<PCHContainerOperations> PCHContainerOps) {
-  return runToolOnCodeWithArgs(ToolAction, Code, std::vector<std::string>(),
-                               FileName, "clang-tool",
-                               std::move(PCHContainerOps));
+  return runToolOnCodeWithArgs(std::move(ToolAction), Code,
+                               std::vector<std::string>(), FileName,
+                               "clang-tool", std::move(PCHContainerOps));
 }
 
 } // namespace tooling
@@ -151,7 +151,7 @@ namespace clang {
 namespace tooling {
 
 bool runToolOnCodeWithArgs(
-    FrontendAction *ToolAction, const Twine &Code,
+    std::unique_ptr<FrontendAction> ToolAction, const Twine &Code,
     llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
     const std::vector<std::string> &Args, const Twine &FileName,
     const Twine &ToolName,
@@ -164,13 +164,12 @@ bool runToolOnCodeWithArgs(
   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<FrontendAction> ToolAction, const Twine &Code,
     const std::vector<std::string> &Args, const Twine &FileName,
     const Twine &ToolName,
     std::shared_ptr<PCHContainerOperations> PCHContainerOps,
@@ -192,8 +191,8 @@ bool runToolOnCodeWithArgs(
         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<std::string> getAbsolutePath(llvm::vfs::FileSystem &FS,
@@ -267,11 +266,11 @@ ToolInvocation::ToolInvocation(
       Files(Files), PCHContainerOps(std::move(PCHContainerOps)) {}
 
 ToolInvocation::ToolInvocation(
-    std::vector<std::string> CommandLine, FrontendAction *FAction,
-    FileManager *Files, std::shared_ptr<PCHContainerOperations> PCHContainerOps)
+    std::vector<std::string> CommandLine,
+    std::unique_ptr<FrontendAction> FAction, FileManager *Files,
+    std::shared_ptr<PCHContainerOperations> PCHContainerOps)
     : CommandLine(std::move(CommandLine)),
-      Action(new SingleFrontendActionFactory(
-          std::unique_ptr<FrontendAction>(FAction))),
+      Action(new SingleFrontendActionFactory(std::move(FAction))),
       OwnsAction(true), Files(Files),
       PCHContainerOps(std::move(PCHContainerOps)) {}
 

Modified: cfe/trunk/unittests/AST/EvaluateAsRValueTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/EvaluateAsRValueTest.cpp?rev=370451&r1=370450&r2=370451&view=diff
==============================================================================
--- cfe/trunk/unittests/AST/EvaluateAsRValueTest.cpp (original)
+++ cfe/trunk/unittests/AST/EvaluateAsRValueTest.cpp Fri Aug 30 02:29:34 2019
@@ -89,22 +89,22 @@ TEST(EvaluateAsRValue, FailsGracefullyFo
     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));
   }
 }

Modified: cfe/trunk/unittests/AST/RecursiveASTVisitorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/RecursiveASTVisitorTest.cpp?rev=370451&r1=370450&r2=370451&view=diff
==============================================================================
--- cfe/trunk/unittests/AST/RecursiveASTVisitorTest.cpp (original)
+++ cfe/trunk/unittests/AST/RecursiveASTVisitorTest.cpp Fri Aug 30 02:29:34 2019
@@ -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();

Modified: cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp?rev=370451&r1=370450&r2=370451&view=diff
==============================================================================
--- cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp (original)
+++ cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp Fri Aug 30 02:29:34 2019
@@ -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);
 }
 

Modified: cfe/trunk/unittests/Index/IndexTests.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Index/IndexTests.cpp?rev=370451&r1=370450&r2=370451&view=diff
==============================================================================
--- cfe/trunk/unittests/Index/IndexTests.cpp (original)
+++ cfe/trunk/unittests/Index/IndexTests.cpp Fri Aug 30 02:29:34 2019
@@ -155,7 +155,8 @@ MATCHER_P(HasRole, Role, "") { return ar
 
 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, IndexExplicitTemplateIns
   )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, IndexTemplateInstantiati
   )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(

Modified: cfe/trunk/unittests/Sema/CodeCompleteTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Sema/CodeCompleteTest.cpp?rev=370451&r1=370450&r2=370451&view=diff
==============================================================================
--- cfe/trunk/unittests/Sema/CodeCompleteTest.cpp (original)
+++ cfe/trunk/unittests/Sema/CodeCompleteTest.cpp Fri Aug 30 02:29:34 2019
@@ -101,10 +101,10 @@ ParsedSourceLocation offsetToPosition(ll
 
 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;
 }
 

Modified: cfe/trunk/unittests/Sema/ExternalSemaSourceTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Sema/ExternalSemaSourceTest.cpp?rev=370451&r1=370450&r2=370451&view=diff
==============================================================================
--- cfe/trunk/unittests/Sema/ExternalSemaSourceTest.cpp (original)
+++ cfe/trunk/unittests/Sema/ExternalSemaSourceTest.cpp Fri Aug 30 02:29:34 2019
@@ -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, ExternalTypoCor
 // 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, ExternalTypoCor
   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, ExternalTypoCor
 }
 
 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, ExternalDelayed
 // 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, TryOtherTactics
 // 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, FirstDiagnoserT
   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);

Modified: cfe/trunk/unittests/StaticAnalyzer/CallDescriptionTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/StaticAnalyzer/CallDescriptionTest.cpp?rev=370451&r1=370450&r2=370451&view=diff
==============================================================================
--- cfe/trunk/unittests/StaticAnalyzer/CallDescriptionTest.cpp (original)
+++ cfe/trunk/unittests/StaticAnalyzer/CallDescriptionTest.cpp Fri Aug 30 02:29:34 2019
@@ -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),"

Modified: cfe/trunk/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp?rev=370451&r1=370450&r2=370451&view=diff
==============================================================================
--- cfe/trunk/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp (original)
+++ cfe/trunk/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp Fri Aug 30 02:29:34 2019
@@ -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) {

Modified: cfe/trunk/unittests/StaticAnalyzer/StoreTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/StaticAnalyzer/StoreTest.cpp?rev=370451&r1=370450&r2=370451&view=diff
==============================================================================
--- cfe/trunk/unittests/StaticAnalyzer/StoreTest.cpp (original)
+++ cfe/trunk/unittests/StaticAnalyzer/StoreTest.cpp Fri Aug 30 02:29:34 2019
@@ -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

Modified: cfe/trunk/unittests/StaticAnalyzer/SymbolReaperTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/StaticAnalyzer/SymbolReaperTest.cpp?rev=370451&r1=370450&r2=370451&view=diff
==============================================================================
--- cfe/trunk/unittests/StaticAnalyzer/SymbolReaperTest.cpp (original)
+++ cfe/trunk/unittests/StaticAnalyzer/SymbolReaperTest.cpp Fri Aug 30 02:29:34 2019
@@ -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

Modified: cfe/trunk/unittests/Tooling/CommentHandlerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/CommentHandlerTest.cpp?rev=370451&r1=370450&r2=370451&view=diff
==============================================================================
--- cfe/trunk/unittests/Tooling/CommentHandlerTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/CommentHandlerTest.cpp Fri Aug 30 02:29:34 2019
@@ -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:

Modified: cfe/trunk/unittests/Tooling/RefactoringTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/RefactoringTest.cpp?rev=370451&r1=370450&r2=370451&view=diff
==============================================================================
--- cfe/trunk/unittests/Tooling/RefactoringTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/RefactoringTest.cpp Fri Aug 30 02:29:34 2019
@@ -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:

Modified: cfe/trunk/unittests/Tooling/TestVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/TestVisitor.h?rev=370451&r1=370450&r2=370451&view=diff
==============================================================================
--- cfe/trunk/unittests/Tooling/TestVisitor.h (original)
+++ cfe/trunk/unittests/Tooling/TestVisitor.h Fri Aug 30 02:29:34 2019
@@ -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 {

Modified: cfe/trunk/unittests/Tooling/ToolingTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/ToolingTest.cpp?rev=370451&r1=370450&r2=370451&view=diff
==============================================================================
--- cfe/trunk/unittests/Tooling/ToolingTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/ToolingTest.cpp Fri Aug 30 02:29:34 2019
@@ -62,10 +62,10 @@ class FindTopLevelDeclConsumer : public
 
 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, TestVirtualModulesC
   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, TestNoDepFil
   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); }"));
 }




More information about the cfe-commits mailing list