summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitri Gribenko <gribozavr@gmail.com>2019-08-30 09:29:34 +0000
committerDmitri Gribenko <gribozavr@gmail.com>2019-08-30 09:29:34 +0000
commitb6cbdf1b70fcaf54b91086c1fb922a2f99282172 (patch)
tree13b037130c4490fefcc458ef93f5c92034487783
parent99b2bc4f952874990519d75bb61631959f8fd6c1 (diff)
downloadclang-b6cbdf1b70fcaf54b91086c1fb922a2f99282172.tar.gz
[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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@370451 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--docs/LibTooling.rst2
-rw-r--r--docs/RAVFrontendAction.rst2
-rw-r--r--docs/ReleaseNotes.rst6
-rw-r--r--include/clang/Tooling/Tooling.h47
-rw-r--r--lib/Tooling/Tooling.cpp29
-rw-r--r--unittests/AST/EvaluateAsRValueTest.cpp34
-rw-r--r--unittests/AST/RecursiveASTVisitorTest.cpp2
-rw-r--r--unittests/CrossTU/CrossTranslationUnitTest.cpp8
-rw-r--r--unittests/Index/IndexTests.cpp23
-rw-r--r--unittests/Sema/CodeCompleteTest.cpp8
-rw-r--r--unittests/Sema/ExternalSemaSourceTest.cpp30
-rw-r--r--unittests/StaticAnalyzer/CallDescriptionTest.cpp24
-rw-r--r--unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp3
-rw-r--r--unittests/StaticAnalyzer/StoreTest.cpp4
-rw-r--r--unittests/StaticAnalyzer/SymbolReaperTest.cpp5
-rw-r--r--unittests/Tooling/CommentHandlerTest.cpp4
-rw-r--r--unittests/Tooling/RefactoringTest.cpp2
-rw-r--r--unittests/Tooling/TestVisitor.h4
-rw-r--r--unittests/Tooling/ToolingTest.cpp96
19 files changed, 150 insertions, 183 deletions
diff --git a/docs/LibTooling.rst b/docs/LibTooling.rst
index 2aaa508a13..202afc0887 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(new clang::SyntaxOnlyAction, "class X {};"));
+ EXPECT_TRUE(runToolOnCode(std::make_unique<clang::SyntaxOnlyAction>(), "class X {};"));
}
Writing a standalone tool
diff --git a/docs/RAVFrontendAction.rst b/docs/RAVFrontendAction.rst
index dea23733bc..2c168a0577 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(new FindNamedClassAction, argv[1]);
+ clang::tooling::runToolOnCode(std::make_unique<FindNamedClassAction>(), argv[1]);
}
}
diff --git a/docs/ReleaseNotes.rst b/docs/ReleaseNotes.rst
index 403b3fbc8a..bf02a379fd 100644
--- a/docs/ReleaseNotes.rst
+++ b/docs/ReleaseNotes.rst
@@ -148,6 +148,12 @@ These are major API changes that have happened since the 9.0.0 release of
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
--------------------
diff --git a/include/clang/Tooling/Tooling.h b/include/clang/Tooling/Tooling.h
index b8c7435c5e..19421f0a39 100644
--- a/include/clang/Tooling/Tooling.h
+++ b/include/clang/Tooling/Tooling.h
@@ -154,19 +154,11 @@ inline std::unique_ptr<FrontendActionFactory> newFrontendActionFactory(
/// 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<std::pair<std::string, std::string>>;
///
/// \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.
///
diff --git a/lib/Tooling/Tooling.cpp b/lib/Tooling/Tooling.cpp
index 472a3ab57c..0b79e087b6 100644
--- a/lib/Tooling/Tooling.cpp
+++ b/lib/Tooling/Tooling.cpp
@@ -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)) {}
diff --git a/unittests/AST/EvaluateAsRValueTest.cpp b/unittests/AST/EvaluateAsRValueTest.cpp
index 4eabb2c3ec..0475330796 100644
--- a/unittests/AST/EvaluateAsRValueTest.cpp
+++ b/unittests/AST/EvaluateAsRValueTest.cpp
@@ -89,22 +89,22 @@ TEST(EvaluateAsRValue, FailsGracefullyForUnknownTypes) {
std::vector<std::string> Args(1, Mode);
Args.push_back("-fno-delayed-template-parsing");
ASSERT_TRUE(runToolOnCodeWithArgs(
- new EvaluateConstantInitializersAction(),
- "template <typename T>"
- "struct vector {"
- " explicit vector(int size);"
- "};"
- "template <typename R>"
- "struct S {"
- " vector<R> intervals() const {"
- " vector<R> Dependent(2);"
- " return Dependent;"
- " }"
- "};"
- "void doSomething() {"
- " int Constant = 2 + 2;"
- " (void) Constant;"
- "}",
- Args));
+ std::make_unique<EvaluateConstantInitializersAction>(),
+ "template <typename T>"
+ "struct vector {"
+ " explicit vector(int size);"
+ "};"
+ "template <typename R>"
+ "struct S {"
+ " vector<R> intervals() const {"
+ " vector<R> Dependent(2);"
+ " return Dependent;"
+ " }"
+ "};"
+ "void doSomething() {"
+ " int Constant = 2 + 2;"
+ " (void) Constant;"
+ "}",
+ Args));
}
}
diff --git a/unittests/AST/RecursiveASTVisitorTest.cpp b/unittests/AST/RecursiveASTVisitorTest.cpp
index 988a8ce4c2..aa8756527d 100644
--- a/unittests/AST/RecursiveASTVisitorTest.cpp
+++ b/unittests/AST/RecursiveASTVisitorTest.cpp
@@ -84,7 +84,7 @@ private:
std::vector<VisitEvent> collectEvents(llvm::StringRef Code) {
CollectInterestingEvents Visitor;
clang::tooling::runToolOnCode(
- new ProcessASTAction(
+ std::make_unique<ProcessASTAction>(
[&](clang::ASTContext &Ctx) { Visitor.TraverseAST(Ctx); }),
Code);
return std::move(Visitor).takeEvents();
diff --git a/unittests/CrossTU/CrossTranslationUnitTest.cpp b/unittests/CrossTU/CrossTranslationUnitTest.cpp
index 3cea3391a7..86ede5e319 100644
--- a/unittests/CrossTU/CrossTranslationUnitTest.cpp
+++ b/unittests/CrossTU/CrossTranslationUnitTest.cpp
@@ -134,15 +134,15 @@ private:
TEST(CrossTranslationUnit, CanLoadFunctionDefinition) {
bool Success = false;
- EXPECT_TRUE(
- tooling::runToolOnCode(new CTUAction(&Success, 1u), "int f(int);"));
+ EXPECT_TRUE(tooling::runToolOnCode(std::make_unique<CTUAction>(&Success, 1u),
+ "int f(int);"));
EXPECT_TRUE(Success);
}
TEST(CrossTranslationUnit, RespectsLoadThreshold) {
bool Success = false;
- EXPECT_TRUE(
- tooling::runToolOnCode(new CTUAction(&Success, 0u), "int f(int);"));
+ EXPECT_TRUE(tooling::runToolOnCode(std::make_unique<CTUAction>(&Success, 0u),
+ "int f(int);"));
EXPECT_FALSE(Success);
}
diff --git a/unittests/Index/IndexTests.cpp b/unittests/Index/IndexTests.cpp
index bf0418c5e2..752dab857e 100644
--- a/unittests/Index/IndexTests.cpp
+++ b/unittests/Index/IndexTests.cpp
@@ -155,7 +155,8 @@ MATCHER_P(HasRole, Role, "") { return arg.Roles & static_cast<unsigned>(Role); }
TEST(IndexTest, Simple) {
auto Index = std::make_shared<Indexer>();
- tooling::runToolOnCode(new IndexAction(Index), "class X {}; void f() {}");
+ tooling::runToolOnCode(std::make_unique<IndexAction>(Index),
+ "class X {}; void f() {}");
EXPECT_THAT(Index->Symbols, UnorderedElementsAre(QName("X"), QName("f")));
}
@@ -164,12 +165,12 @@ TEST(IndexTest, IndexPreprocessorMacros) {
auto Index = std::make_shared<Indexer>();
IndexingOptions Opts;
Opts.IndexMacrosInPreprocessor = true;
- tooling::runToolOnCode(new IndexAction(Index, Opts), Code);
+ tooling::runToolOnCode(std::make_unique<IndexAction>(Index, Opts), Code);
EXPECT_THAT(Index->Symbols, Contains(QName("INDEX_MAC")));
Opts.IndexMacrosInPreprocessor = false;
Index->Symbols.clear();
- tooling::runToolOnCode(new IndexAction(Index, Opts), Code);
+ tooling::runToolOnCode(std::make_unique<IndexAction>(Index, Opts), Code);
EXPECT_THAT(Index->Symbols, UnorderedElementsAre());
}
@@ -179,12 +180,12 @@ TEST(IndexTest, IndexParametersInDecls) {
IndexingOptions Opts;
Opts.IndexFunctionLocals = true;
Opts.IndexParametersInDeclarations = true;
- tooling::runToolOnCode(new IndexAction(Index, Opts), Code);
+ tooling::runToolOnCode(std::make_unique<IndexAction>(Index, Opts), Code);
EXPECT_THAT(Index->Symbols, Contains(QName("bar")));
Opts.IndexParametersInDeclarations = false;
Index->Symbols.clear();
- tooling::runToolOnCode(new IndexAction(Index, Opts), Code);
+ tooling::runToolOnCode(std::make_unique<IndexAction>(Index, Opts), Code);
EXPECT_THAT(Index->Symbols, Not(Contains(QName("bar"))));
}
@@ -201,7 +202,7 @@ TEST(IndexTest, IndexExplicitTemplateInstantiation) {
)cpp";
auto Index = std::make_shared<Indexer>();
IndexingOptions Opts;
- tooling::runToolOnCode(new IndexAction(Index, Opts), Code);
+ tooling::runToolOnCode(std::make_unique<IndexAction>(Index, Opts), Code);
EXPECT_THAT(Index->Symbols,
AllOf(Contains(AllOf(QName("Foo"), WrittenAt(Position(8, 7)),
DeclAt(Position(5, 12)))),
@@ -222,7 +223,7 @@ TEST(IndexTest, IndexTemplateInstantiationPartial) {
)cpp";
auto Index = std::make_shared<Indexer>();
IndexingOptions Opts;
- tooling::runToolOnCode(new IndexAction(Index, Opts), Code);
+ tooling::runToolOnCode(std::make_unique<IndexAction>(Index, Opts), Code);
EXPECT_THAT(Index->Symbols,
Contains(AllOf(QName("Foo"), WrittenAt(Position(8, 7)),
DeclAt(Position(5, 12)))));
@@ -238,7 +239,7 @@ TEST(IndexTest, IndexTypeParmDecls) {
)cpp";
auto Index = std::make_shared<Indexer>();
IndexingOptions Opts;
- tooling::runToolOnCode(new IndexAction(Index, Opts), Code);
+ tooling::runToolOnCode(std::make_unique<IndexAction>(Index, Opts), Code);
EXPECT_THAT(Index->Symbols, AllOf(Not(Contains(QName("Foo::T"))),
Not(Contains(QName("Foo::I"))),
Not(Contains(QName("Foo::C"))),
@@ -246,7 +247,7 @@ TEST(IndexTest, IndexTypeParmDecls) {
Opts.IndexTemplateParameters = true;
Index->Symbols.clear();
- tooling::runToolOnCode(new IndexAction(Index, Opts), Code);
+ tooling::runToolOnCode(std::make_unique<IndexAction>(Index, Opts), Code);
EXPECT_THAT(Index->Symbols,
AllOf(Contains(QName("Foo::T")), Contains(QName("Foo::I")),
Contains(QName("Foo::C")), Contains(QName("Foo::NoRef"))));
@@ -261,7 +262,7 @@ TEST(IndexTest, UsingDecls) {
)cpp";
auto Index = std::make_shared<Indexer>();
IndexingOptions Opts;
- tooling::runToolOnCode(new IndexAction(Index, Opts), Code);
+ tooling::runToolOnCode(std::make_unique<IndexAction>(Index, Opts), Code);
EXPECT_THAT(Index->Symbols,
Contains(AllOf(QName("std::foo"), Kind(SymbolKind::Using))));
}
@@ -275,7 +276,7 @@ TEST(IndexTest, Constructors) {
)cpp";
auto Index = std::make_shared<Indexer>();
IndexingOptions Opts;
- tooling::runToolOnCode(new IndexAction(Index, Opts), Code);
+ tooling::runToolOnCode(std::make_unique<IndexAction>(Index, Opts), Code);
EXPECT_THAT(
Index->Symbols,
UnorderedElementsAre(
diff --git a/unittests/Sema/CodeCompleteTest.cpp b/unittests/Sema/CodeCompleteTest.cpp
index dc0f7e07e0..ab1792ba63 100644
--- a/unittests/Sema/CodeCompleteTest.cpp
+++ b/unittests/Sema/CodeCompleteTest.cpp
@@ -101,10 +101,10 @@ ParsedSourceLocation offsetToPosition(llvm::StringRef Code, size_t Offset) {
CompletionContext runCompletion(StringRef Code, size_t Offset) {
CompletionContext ResultCtx;
- auto Action = std::make_unique<CodeCompleteAction>(
- offsetToPosition(Code, Offset), ResultCtx);
- clang::tooling::runToolOnCodeWithArgs(Action.release(), Code, {"-std=c++11"},
- TestCCName);
+ clang::tooling::runToolOnCodeWithArgs(
+ std::make_unique<CodeCompleteAction>(offsetToPosition(Code, Offset),
+ ResultCtx),
+ Code, {"-std=c++11"}, TestCCName);
return ResultCtx;
}
diff --git a/unittests/Sema/ExternalSemaSourceTest.cpp b/unittests/Sema/ExternalSemaSourceTest.cpp
index edf91c9a08..44006e349c 100644
--- a/unittests/Sema/ExternalSemaSourceTest.cpp
+++ b/unittests/Sema/ExternalSemaSourceTest.cpp
@@ -220,28 +220,26 @@ public:
// Make sure that the DiagnosticWatcher is not miscounting.
TEST(ExternalSemaSource, SanityCheck) {
- std::unique_ptr<ExternalSemaSourceInstaller> Installer(
- new ExternalSemaSourceInstaller);
+ auto Installer = std::make_unique<ExternalSemaSourceInstaller>();
DiagnosticWatcher Watcher("AAB", "BBB");
Installer->PushWatcher(&Watcher);
std::vector<std::string> Args(1, "-std=c++11");
ASSERT_TRUE(clang::tooling::runToolOnCodeWithArgs(
- Installer.release(), "namespace AAA { } using namespace AAB;", Args));
+ std::move(Installer), "namespace AAA { } using namespace AAB;", Args));
ASSERT_EQ(0, Watcher.SeenCount);
}
// Check that when we add a NamespaceTypeProvider, we use that suggestion
// instead of the usual suggestion we would use above.
TEST(ExternalSemaSource, ExternalTypoCorrectionPrioritized) {
- std::unique_ptr<ExternalSemaSourceInstaller> Installer(
- new ExternalSemaSourceInstaller);
+ auto Installer = std::make_unique<ExternalSemaSourceInstaller>();
NamespaceTypoProvider Provider("AAB", "BBB");
DiagnosticWatcher Watcher("AAB", "BBB");
Installer->PushSource(&Provider);
Installer->PushWatcher(&Watcher);
std::vector<std::string> Args(1, "-std=c++11");
ASSERT_TRUE(clang::tooling::runToolOnCodeWithArgs(
- Installer.release(), "namespace AAA { } using namespace AAB;", Args));
+ std::move(Installer), "namespace AAA { } using namespace AAB;", Args));
ASSERT_LE(0, Provider.CallCount);
ASSERT_EQ(1, Watcher.SeenCount);
}
@@ -249,8 +247,7 @@ TEST(ExternalSemaSource, ExternalTypoCorrectionPrioritized) {
// Check that we use the first successful TypoCorrection returned from an
// ExternalSemaSource.
TEST(ExternalSemaSource, ExternalTypoCorrectionOrdering) {
- std::unique_ptr<ExternalSemaSourceInstaller> Installer(
- new ExternalSemaSourceInstaller);
+ auto Installer = std::make_unique<ExternalSemaSourceInstaller>();
NamespaceTypoProvider First("XXX", "BBB");
NamespaceTypoProvider Second("AAB", "CCC");
NamespaceTypoProvider Third("AAB", "DDD");
@@ -261,7 +258,7 @@ TEST(ExternalSemaSource, ExternalTypoCorrectionOrdering) {
Installer->PushWatcher(&Watcher);
std::vector<std::string> Args(1, "-std=c++11");
ASSERT_TRUE(clang::tooling::runToolOnCodeWithArgs(
- Installer.release(), "namespace AAA { } using namespace AAB;", Args));
+ std::move(Installer), "namespace AAA { } using namespace AAB;", Args));
ASSERT_LE(1, First.CallCount);
ASSERT_LE(1, Second.CallCount);
ASSERT_EQ(0, Third.CallCount);
@@ -269,15 +266,14 @@ TEST(ExternalSemaSource, ExternalTypoCorrectionOrdering) {
}
TEST(ExternalSemaSource, ExternalDelayedTypoCorrection) {
- std::unique_ptr<ExternalSemaSourceInstaller> Installer(
- new ExternalSemaSourceInstaller);
+ auto Installer = std::make_unique<ExternalSemaSourceInstaller>();
FunctionTypoProvider Provider("aaa", "bbb");
DiagnosticWatcher Watcher("aaa", "bbb");
Installer->PushSource(&Provider);
Installer->PushWatcher(&Watcher);
std::vector<std::string> Args(1, "-std=c++11");
ASSERT_TRUE(clang::tooling::runToolOnCodeWithArgs(
- Installer.release(), "namespace AAA { } void foo() { AAA::aaa(); }",
+ std::move(Installer), "namespace AAA { } void foo() { AAA::aaa(); }",
Args));
ASSERT_LE(0, Provider.CallCount);
ASSERT_EQ(1, Watcher.SeenCount);
@@ -286,15 +282,14 @@ TEST(ExternalSemaSource, ExternalDelayedTypoCorrection) {
// We should only try MaybeDiagnoseMissingCompleteType if we can't otherwise
// solve the problem.
TEST(ExternalSemaSource, TryOtherTacticsBeforeDiagnosing) {
- std::unique_ptr<ExternalSemaSourceInstaller> Installer(
- new ExternalSemaSourceInstaller);
+ auto Installer = std::make_unique<ExternalSemaSourceInstaller>();
CompleteTypeDiagnoser Diagnoser(false);
Installer->PushSource(&Diagnoser);
std::vector<std::string> Args(1, "-std=c++11");
// This code hits the class template specialization/class member of a class
// template specialization checks in Sema::RequireCompleteTypeImpl.
ASSERT_TRUE(clang::tooling::runToolOnCodeWithArgs(
- Installer.release(),
+ std::move(Installer),
"template <typename T> struct S { class C { }; }; S<char>::C SCInst;",
Args));
ASSERT_EQ(0, Diagnoser.CallCount);
@@ -303,8 +298,7 @@ TEST(ExternalSemaSource, TryOtherTacticsBeforeDiagnosing) {
// The first ExternalSemaSource where MaybeDiagnoseMissingCompleteType returns
// true should be the last one called.
TEST(ExternalSemaSource, FirstDiagnoserTaken) {
- std::unique_ptr<ExternalSemaSourceInstaller> Installer(
- new ExternalSemaSourceInstaller);
+ auto Installer = std::make_unique<ExternalSemaSourceInstaller>();
CompleteTypeDiagnoser First(false);
CompleteTypeDiagnoser Second(true);
CompleteTypeDiagnoser Third(true);
@@ -313,7 +307,7 @@ TEST(ExternalSemaSource, FirstDiagnoserTaken) {
Installer->PushSource(&Third);
std::vector<std::string> Args(1, "-std=c++11");
ASSERT_FALSE(clang::tooling::runToolOnCodeWithArgs(
- Installer.release(), "class Incomplete; Incomplete IncompleteInstance;",
+ std::move(Installer), "class Incomplete; Incomplete IncompleteInstance;",
Args));
ASSERT_EQ(1, First.CallCount);
ASSERT_EQ(1, Second.CallCount);
diff --git a/unittests/StaticAnalyzer/CallDescriptionTest.cpp b/unittests/StaticAnalyzer/CallDescriptionTest.cpp
index 86cd6a40f0..2ebaa46b0f 100644
--- a/unittests/StaticAnalyzer/CallDescriptionTest.cpp
+++ b/unittests/StaticAnalyzer/CallDescriptionTest.cpp
@@ -100,30 +100,30 @@ public:
TEST(CallEvent, CallDescription) {
// Test simple name matching.
EXPECT_TRUE(tooling::runToolOnCode(
- new CallDescriptionAction({
+ std::unique_ptr<CallDescriptionAction>(new CallDescriptionAction({
{{"bar"}, false}, // false: there's no call to 'bar' in this code.
{{"foo"}, true}, // true: there's a call to 'foo' in this code.
- }), "void foo(); void bar() { foo(); }"));
+ })), "void foo(); void bar() { foo(); }"));
// Test arguments check.
EXPECT_TRUE(tooling::runToolOnCode(
- new CallDescriptionAction({
+ std::unique_ptr<CallDescriptionAction>(new CallDescriptionAction({
{{"foo", 1}, true},
{{"foo", 2}, false},
- }), "void foo(int); void foo(int, int); void bar() { foo(1); }"));
+ })), "void foo(int); void foo(int, int); void bar() { foo(1); }"));
// Test lack of arguments check.
EXPECT_TRUE(tooling::runToolOnCode(
- new CallDescriptionAction({
+ std::unique_ptr<CallDescriptionAction>(new CallDescriptionAction({
{{"foo", None}, true},
{{"foo", 2}, false},
- }), "void foo(int); void foo(int, int); void bar() { foo(1); }"));
+ })), "void foo(int); void foo(int, int); void bar() { foo(1); }"));
// Test qualified names.
EXPECT_TRUE(tooling::runToolOnCode(
- new CallDescriptionAction({
+ std::unique_ptr<CallDescriptionAction>(new CallDescriptionAction({
{{{"std", "basic_string", "c_str"}}, true},
- }),
+ })),
"namespace std { inline namespace __1 {"
" template<typename T> class basic_string {"
" public:"
@@ -138,18 +138,18 @@ TEST(CallEvent, CallDescription) {
// A negative test for qualified names.
EXPECT_TRUE(tooling::runToolOnCode(
- new CallDescriptionAction({
+ std::unique_ptr<CallDescriptionAction>(new CallDescriptionAction({
{{{"foo", "bar"}}, false},
{{{"bar", "foo"}}, false},
{{"foo"}, true},
- }), "void foo(); struct bar { void foo(); }; void test() { foo(); }"));
+ })), "void foo(); struct bar { void foo(); }; void test() { foo(); }"));
// Test CDF_MaybeBuiltin - a flag that allows matching weird builtins.
EXPECT_TRUE(tooling::runToolOnCode(
- new CallDescriptionAction({
+ std::unique_ptr<CallDescriptionAction>(new CallDescriptionAction({
{{"memset", 3}, false},
{{CDF_MaybeBuiltin, "memset", 3}, true}
- }),
+ })),
"void foo() {"
" int x;"
" __builtin___memset_chk(&x, 0, sizeof(x),"
diff --git a/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp b/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp
index 109e762892..4773852866 100644
--- a/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp
+++ b/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp
@@ -58,7 +58,8 @@ public:
template <typename CheckerT>
bool runCheckerOnCode(const std::string &Code, std::string &Diags) {
llvm::raw_string_ostream OS(Diags);
- return tooling::runToolOnCode(new TestAction<CheckerT>(OS), Code);
+ return tooling::runToolOnCode(std::make_unique<TestAction<CheckerT>>(OS),
+ Code);
}
template <typename CheckerT>
bool runCheckerOnCode(const std::string &Code) {
diff --git a/unittests/StaticAnalyzer/StoreTest.cpp b/unittests/StaticAnalyzer/StoreTest.cpp
index 0cbe7d4793..c8b930bf32 100644
--- a/unittests/StaticAnalyzer/StoreTest.cpp
+++ b/unittests/StaticAnalyzer/StoreTest.cpp
@@ -96,8 +96,8 @@ public:
};
TEST(Store, VariableBind) {
- EXPECT_TRUE(tooling::runToolOnCode(
- new VariableBindAction, "void foo() { int x0, y0, z0, x1, y1; }"));
+ EXPECT_TRUE(tooling::runToolOnCode(std::make_unique<VariableBindAction>(),
+ "void foo() { int x0, y0, z0, x1, y1; }"));
}
} // namespace
diff --git a/unittests/StaticAnalyzer/SymbolReaperTest.cpp b/unittests/StaticAnalyzer/SymbolReaperTest.cpp
index bd11303e94..bbbf68851a 100644
--- a/unittests/StaticAnalyzer/SymbolReaperTest.cpp
+++ b/unittests/StaticAnalyzer/SymbolReaperTest.cpp
@@ -61,8 +61,9 @@ public:
// Test that marking s.x as live would also make s live.
TEST(SymbolReaper, SuperRegionLiveness) {
- EXPECT_TRUE(tooling::runToolOnCode(new SuperRegionLivenessAction,
- "void foo() { struct S { int x; } s; }"));
+ EXPECT_TRUE(
+ tooling::runToolOnCode(std::make_unique<SuperRegionLivenessAction>(),
+ "void foo() { struct S { int x; } s; }"));
}
} // namespace
diff --git a/unittests/Tooling/CommentHandlerTest.cpp b/unittests/Tooling/CommentHandlerTest.cpp
index 5ceed95b98..7eb11ccd6e 100644
--- a/unittests/Tooling/CommentHandlerTest.cpp
+++ b/unittests/Tooling/CommentHandlerTest.cpp
@@ -55,8 +55,8 @@ public:
CommentVerifier GetVerifier();
protected:
- ASTFrontendAction *CreateTestAction() override {
- return new CommentHandlerAction(this);
+ std::unique_ptr<ASTFrontendAction> CreateTestAction() override {
+ return std::make_unique<CommentHandlerAction>(this);
}
private:
diff --git a/unittests/Tooling/RefactoringTest.cpp b/unittests/Tooling/RefactoringTest.cpp
index b5c56e907a..5949c53d8e 100644
--- a/unittests/Tooling/RefactoringTest.cpp
+++ b/unittests/Tooling/RefactoringTest.cpp
@@ -650,7 +650,7 @@ template <typename T>
class TestVisitor : public clang::RecursiveASTVisitor<T> {
public:
bool runOver(StringRef Code) {
- return runToolOnCode(new TestAction(this), Code);
+ return runToolOnCode(std::make_unique<TestAction>(this), Code);
}
protected:
diff --git a/unittests/Tooling/TestVisitor.h b/unittests/Tooling/TestVisitor.h
index 95252b82c6..751ca74d1a 100644
--- a/unittests/Tooling/TestVisitor.h
+++ b/unittests/Tooling/TestVisitor.h
@@ -85,8 +85,8 @@ public:
}
protected:
- virtual ASTFrontendAction* CreateTestAction() {
- return new TestAction(this);
+ virtual std::unique_ptr<ASTFrontendAction> CreateTestAction() {
+ return std::make_unique<TestAction>(this);
}
class FindConsumer : public ASTConsumer {
diff --git a/unittests/Tooling/ToolingTest.cpp b/unittests/Tooling/ToolingTest.cpp
index 447b9973e4..c22d0bdca4 100644
--- a/unittests/Tooling/ToolingTest.cpp
+++ b/unittests/Tooling/ToolingTest.cpp
@@ -62,10 +62,10 @@ class FindTopLevelDeclConsumer : public clang::ASTConsumer {
TEST(runToolOnCode, FindsNoTopLevelDeclOnEmptyCode) {
bool FoundTopLevelDecl = false;
- EXPECT_TRUE(
- runToolOnCode(new TestAction(std::make_unique<FindTopLevelDeclConsumer>(
- &FoundTopLevelDecl)),
- ""));
+ EXPECT_TRUE(runToolOnCode(
+ std::make_unique<TestAction>(
+ std::make_unique<FindTopLevelDeclConsumer>(&FoundTopLevelDecl)),
+ ""));
EXPECT_FALSE(FoundTopLevelDecl);
}
@@ -102,17 +102,17 @@ bool FindClassDeclX(ASTUnit *AST) {
TEST(runToolOnCode, FindsClassDecl) {
bool FoundClassDeclX = false;
- EXPECT_TRUE(
- runToolOnCode(new TestAction(std::make_unique<FindClassDeclXConsumer>(
- &FoundClassDeclX)),
- "class X;"));
+ EXPECT_TRUE(runToolOnCode(
+ std::make_unique<TestAction>(
+ std::make_unique<FindClassDeclXConsumer>(&FoundClassDeclX)),
+ "class X;"));
EXPECT_TRUE(FoundClassDeclX);
FoundClassDeclX = false;
- EXPECT_TRUE(
- runToolOnCode(new TestAction(std::make_unique<FindClassDeclXConsumer>(
- &FoundClassDeclX)),
- "class Y;"));
+ EXPECT_TRUE(runToolOnCode(
+ std::make_unique<TestAction>(
+ std::make_unique<FindClassDeclXConsumer>(&FoundClassDeclX)),
+ "class Y;"));
EXPECT_FALSE(FoundClassDeclX);
}
@@ -160,8 +160,8 @@ TEST(ToolInvocation, TestMapVirtualFile) {
Args.push_back("-Idef");
Args.push_back("-fsyntax-only");
Args.push_back("test.cpp");
- clang::tooling::ToolInvocation Invocation(Args, new SyntaxOnlyAction,
- Files.get());
+ clang::tooling::ToolInvocation Invocation(
+ Args, std::make_unique<SyntaxOnlyAction>(), Files.get());
InMemoryFileSystem->addFile(
"test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("#include <abc>\n"));
InMemoryFileSystem->addFile("def/abc", 0,
@@ -186,8 +186,8 @@ TEST(ToolInvocation, TestVirtualModulesCompilation) {
Args.push_back("-Idef");
Args.push_back("-fsyntax-only");
Args.push_back("test.cpp");
- clang::tooling::ToolInvocation Invocation(Args, new SyntaxOnlyAction,
- Files.get());
+ clang::tooling::ToolInvocation Invocation(
+ Args, std::make_unique<SyntaxOnlyAction>(), Files.get());
InMemoryFileSystem->addFile(
"test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("#include <abc>\n"));
InMemoryFileSystem->addFile("def/abc", 0,
@@ -257,61 +257,61 @@ TEST(runToolOnCode, TestSkipFunctionBody) {
std::vector<std::string> Args = {"-std=c++11"};
std::vector<std::string> Args2 = {"-fno-delayed-template-parsing"};
- EXPECT_TRUE(runToolOnCode(new SkipBodyAction,
+ EXPECT_TRUE(runToolOnCode(std::make_unique<SkipBodyAction>(),
"int skipMe() { an_error_here }"));
- EXPECT_FALSE(runToolOnCode(new SkipBodyAction,
+ EXPECT_FALSE(runToolOnCode(std::make_unique<SkipBodyAction>(),
"int skipMeNot() { an_error_here }"));
// Test constructors with initializers
EXPECT_TRUE(runToolOnCodeWithArgs(
- new SkipBodyAction,
+ std::make_unique<SkipBodyAction>(),
"struct skipMe { skipMe() : an_error() { more error } };", Args));
EXPECT_TRUE(runToolOnCodeWithArgs(
- new SkipBodyAction, "struct skipMe { skipMe(); };"
+ std::make_unique<SkipBodyAction>(), "struct skipMe { skipMe(); };"
"skipMe::skipMe() : an_error([](){;}) { more error }",
Args));
EXPECT_TRUE(runToolOnCodeWithArgs(
- new SkipBodyAction, "struct skipMe { skipMe(); };"
+ std::make_unique<SkipBodyAction>(), "struct skipMe { skipMe(); };"
"skipMe::skipMe() : an_error{[](){;}} { more error }",
Args));
EXPECT_TRUE(runToolOnCodeWithArgs(
- new SkipBodyAction,
+ std::make_unique<SkipBodyAction>(),
"struct skipMe { skipMe(); };"
"skipMe::skipMe() : a<b<c>(e)>>(), f{}, g() { error }",
Args));
EXPECT_TRUE(runToolOnCodeWithArgs(
- new SkipBodyAction, "struct skipMe { skipMe() : bases()... { error } };",
+ std::make_unique<SkipBodyAction>(), "struct skipMe { skipMe() : bases()... { error } };",
Args));
EXPECT_FALSE(runToolOnCodeWithArgs(
- new SkipBodyAction, "struct skipMeNot { skipMeNot() : an_error() { } };",
+ std::make_unique<SkipBodyAction>(), "struct skipMeNot { skipMeNot() : an_error() { } };",
Args));
- EXPECT_FALSE(runToolOnCodeWithArgs(new SkipBodyAction,
+ EXPECT_FALSE(runToolOnCodeWithArgs(std::make_unique<SkipBodyAction>(),
"struct skipMeNot { skipMeNot(); };"
"skipMeNot::skipMeNot() : an_error() { }",
Args));
// Try/catch
EXPECT_TRUE(runToolOnCode(
- new SkipBodyAction,
+ std::make_unique<SkipBodyAction>(),
"void skipMe() try { an_error() } catch(error) { error };"));
EXPECT_TRUE(runToolOnCode(
- new SkipBodyAction,
+ std::make_unique<SkipBodyAction>(),
"struct S { void skipMe() try { an_error() } catch(error) { error } };"));
EXPECT_TRUE(
- runToolOnCode(new SkipBodyAction,
+ runToolOnCode(std::make_unique<SkipBodyAction>(),
"void skipMe() try { an_error() } catch(error) { error; }"
"catch(error) { error } catch (error) { }"));
EXPECT_FALSE(runToolOnCode(
- new SkipBodyAction,
+ std::make_unique<SkipBodyAction>(),
"void skipMe() try something;")); // don't crash while parsing
// Template
EXPECT_TRUE(runToolOnCode(
- new SkipBodyAction, "template<typename T> int skipMe() { an_error_here }"
+ std::make_unique<SkipBodyAction>(), "template<typename T> int skipMe() { an_error_here }"
"int x = skipMe<int>();"));
EXPECT_FALSE(runToolOnCodeWithArgs(
- new SkipBodyAction,
+ std::make_unique<SkipBodyAction>(),
"template<typename T> int skipMeNot() { an_error_here }", Args2));
}
@@ -325,7 +325,7 @@ TEST(runToolOnCodeWithArgs, TestNoDepFile) {
Args.push_back(DepFilePath.str());
Args.push_back("-MF");
Args.push_back(DepFilePath.str());
- EXPECT_TRUE(runToolOnCodeWithArgs(new SkipBodyAction, "", Args));
+ EXPECT_TRUE(runToolOnCodeWithArgs(std::make_unique<SkipBodyAction>(), "", Args));
EXPECT_FALSE(llvm::sys::fs::exists(DepFilePath.str()));
EXPECT_FALSE(llvm::sys::fs::remove(DepFilePath.str()));
}
@@ -348,24 +348,26 @@ private:
};
TEST(runToolOnCodeWithArgs, DiagnosticsColor) {
-
- EXPECT_TRUE(runToolOnCodeWithArgs(new CheckColoredDiagnosticsAction(true), "",
- {"-fcolor-diagnostics"}));
- EXPECT_TRUE(runToolOnCodeWithArgs(new CheckColoredDiagnosticsAction(false),
- "", {"-fno-color-diagnostics"}));
- EXPECT_TRUE(
- runToolOnCodeWithArgs(new CheckColoredDiagnosticsAction(true), "",
- {"-fno-color-diagnostics", "-fcolor-diagnostics"}));
- EXPECT_TRUE(
- runToolOnCodeWithArgs(new CheckColoredDiagnosticsAction(false), "",
- {"-fcolor-diagnostics", "-fno-color-diagnostics"}));
EXPECT_TRUE(runToolOnCodeWithArgs(
- new CheckColoredDiagnosticsAction(true), "",
+ std::make_unique<CheckColoredDiagnosticsAction>(true), "",
+ {"-fcolor-diagnostics"}));
+ EXPECT_TRUE(runToolOnCodeWithArgs(
+ std::make_unique<CheckColoredDiagnosticsAction>(false), "",
+ {"-fno-color-diagnostics"}));
+ EXPECT_TRUE(runToolOnCodeWithArgs(
+ std::make_unique<CheckColoredDiagnosticsAction>(true), "",
+ {"-fno-color-diagnostics", "-fcolor-diagnostics"}));
+ EXPECT_TRUE(runToolOnCodeWithArgs(
+ std::make_unique<CheckColoredDiagnosticsAction>(false), "",
+ {"-fcolor-diagnostics", "-fno-color-diagnostics"}));
+ EXPECT_TRUE(runToolOnCodeWithArgs(
+ std::make_unique<CheckColoredDiagnosticsAction>(true), "",
{"-fno-color-diagnostics", "-fdiagnostics-color=always"}));
// Check that this test would fail if ShowColors is not what it should.
- EXPECT_FALSE(runToolOnCodeWithArgs(new CheckColoredDiagnosticsAction(false),
- "", {"-fcolor-diagnostics"}));
+ EXPECT_FALSE(runToolOnCodeWithArgs(
+ std::make_unique<CheckColoredDiagnosticsAction>(false), "",
+ {"-fcolor-diagnostics"}));
}
TEST(ClangToolTest, ArgumentAdjusters) {
@@ -657,7 +659,7 @@ TEST(runToolOnCode, TestResetDiagnostics) {
// Should not crash
EXPECT_FALSE(
- runToolOnCode(new ResetDiagnosticAction,
+ runToolOnCode(std::make_unique<ResetDiagnosticAction>(),
"struct Foo { Foo(int); ~Foo(); struct Fwd _fwd; };"
"void func() { long x; Foo f(x); }"));
}