diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2020-01-28 20:23:46 +0100 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2020-01-28 23:25:25 +0100 |
commit | adcd02683856c30ba6f349279509acecd90063df (patch) | |
tree | 7b5927ef2ecab1618842183fac5ebe848f5832dd /clang/unittests | |
parent | 5eaf44f99f0a0a3bdfa892892b8aaca841c8dbe0 (diff) | |
download | llvm-adcd02683856c30ba6f349279509acecd90063df.zip llvm-adcd02683856c30ba6f349279509acecd90063df.tar.gz llvm-adcd02683856c30ba6f349279509acecd90063df.tar.bz2 |
Make llvm::StringRef to std::string conversions explicit.
This is how it should've been and brings it more in line with
std::string_view. There should be no functional change here.
This is mostly mechanical from a custom clang-tidy check, with a lot of
manual fixups. It uncovers a lot of minor inefficiencies.
This doesn't actually modify StringRef yet, I'll do that in a follow-up.
Diffstat (limited to 'clang/unittests')
33 files changed, 197 insertions, 181 deletions
diff --git a/clang/unittests/AST/ASTImporterFixtures.cpp b/clang/unittests/AST/ASTImporterFixtures.cpp index 80fcd1f..36732ee 100644 --- a/clang/unittests/AST/ASTImporterFixtures.cpp +++ b/clang/unittests/AST/ASTImporterFixtures.cpp @@ -41,7 +41,7 @@ void createVirtualFileIfNeeded(ASTUnit *ToAST, StringRef FileName, ASTImporterTestBase::TU::TU(StringRef Code, StringRef FileName, ArgVector Args, ImporterConstructor C, ASTImporter::ODRHandlingType ODRHandling) - : Code(Code), FileName(FileName), + : Code(std::string(Code)), FileName(std::string(FileName)), Unit(tooling::buildASTFromCodeWithArgs(this->Code, Args, this->FileName)), TUDecl(Unit->getASTContext().getTranslationUnitDecl()), Creator(C), ODRHandling(ODRHandling) { @@ -118,7 +118,7 @@ void ASTImporterTestBase::lazyInitToAST(Language ToLang, StringRef ToSrcCode, return; ArgVector ToArgs = getArgVectorForLanguage(ToLang); // Source code must be a valid live buffer through the tests lifetime. - ToCode = ToSrcCode; + ToCode = std::string(ToSrcCode); // Build the AST from an empty file. ToAST = tooling::buildASTFromCodeWithArgs(ToCode, ToArgs, FileName); ToAST->enableSourceFileDiagnostics(); diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 3e8f804..8c3dc6c 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -115,8 +115,8 @@ class TestImportBase : public CompilerOptionSpecificTest, const BindableMatcher<NodeType> &VerificationMatcher) { return testImport( FromCode, FromArgs, ToCode, ToArgs, Verifier, - translationUnitDecl( - has(namedDecl(hasName(DeclToImportID)).bind(DeclToImportID))), + translationUnitDecl(has(namedDecl(hasName(std::string(DeclToImportID))) + .bind(DeclToImportID))), VerificationMatcher); } diff --git a/clang/unittests/AST/DeclPrinterTest.cpp b/clang/unittests/AST/DeclPrinterTest.cpp index 5a0a804..3bb17ab 100644 --- a/clang/unittests/AST/DeclPrinterTest.cpp +++ b/clang/unittests/AST/DeclPrinterTest.cpp @@ -108,12 +108,9 @@ PrintedDeclCXX98Matches(StringRef Code, StringRef DeclName, StringRef ExpectedPrinted, PrintingPolicyModifier PolicyModifier = nullptr) { std::vector<std::string> Args(1, "-std=c++98"); - return PrintedDeclMatches(Code, - Args, - namedDecl(hasName(DeclName)).bind("id"), - ExpectedPrinted, - "input.cc", - PolicyModifier); + return PrintedDeclMatches( + Code, Args, namedDecl(hasName(std::string(DeclName))).bind("id"), + ExpectedPrinted, "input.cc", PolicyModifier); } ::testing::AssertionResult @@ -133,11 +130,9 @@ PrintedDeclCXX98Matches(StringRef Code, const DeclarationMatcher &NodeMatch, StringRef DeclName, StringRef ExpectedPrinted) { std::vector<std::string> Args(1, "-std=c++11"); - return PrintedDeclMatches(Code, - Args, - namedDecl(hasName(DeclName)).bind("id"), - ExpectedPrinted, - "input.cc"); + return PrintedDeclMatches( + Code, Args, namedDecl(hasName(std::string(DeclName))).bind("id"), + ExpectedPrinted, "input.cc"); } ::testing::AssertionResult PrintedDeclCXX11Matches( diff --git a/clang/unittests/AST/NamedDeclPrinterTest.cpp b/clang/unittests/AST/NamedDeclPrinterTest.cpp index a5c3e19..d5077b8 100644 --- a/clang/unittests/AST/NamedDeclPrinterTest.cpp +++ b/clang/unittests/AST/NamedDeclPrinterTest.cpp @@ -112,47 +112,45 @@ PrintedNamedDeclMatches(StringRef Code, const std::vector<std::string> &Args, PrintedNamedDeclCXX98Matches(StringRef Code, StringRef DeclName, StringRef ExpectedPrinted) { std::vector<std::string> Args(1, "-std=c++98"); - return PrintedNamedDeclMatches(Code, - Args, - /*SuppressUnwrittenScope*/ false, - namedDecl(hasName(DeclName)).bind("id"), - ExpectedPrinted, - "input.cc"); + return PrintedNamedDeclMatches( + Code, Args, + /*SuppressUnwrittenScope*/ false, + namedDecl(hasName(std::string(DeclName))).bind("id"), ExpectedPrinted, + "input.cc"); } ::testing::AssertionResult PrintedWrittenNamedDeclCXX11Matches(StringRef Code, StringRef DeclName, StringRef ExpectedPrinted) { std::vector<std::string> Args(1, "-std=c++11"); - return PrintedNamedDeclMatches(Code, - Args, - /*SuppressUnwrittenScope*/ true, - namedDecl(hasName(DeclName)).bind("id"), - ExpectedPrinted, - "input.cc"); + return PrintedNamedDeclMatches( + Code, Args, + /*SuppressUnwrittenScope*/ true, + namedDecl(hasName(std::string(DeclName))).bind("id"), ExpectedPrinted, + "input.cc"); } ::testing::AssertionResult PrintedWrittenPropertyDeclObjCMatches(StringRef Code, StringRef DeclName, StringRef ExpectedPrinted) { std::vector<std::string> Args{"-std=c++11", "-xobjective-c++"}; - return PrintedNamedDeclMatches(Code, - Args, - /*SuppressUnwrittenScope*/ true, - objcPropertyDecl(hasName(DeclName)).bind("id"), - ExpectedPrinted, - "input.m"); + return PrintedNamedDeclMatches( + Code, Args, + /*SuppressUnwrittenScope*/ true, + objcPropertyDecl(hasName(std::string(DeclName))).bind("id"), + ExpectedPrinted, "input.m"); } ::testing::AssertionResult PrintedNestedNameSpecifierMatches(StringRef Code, StringRef DeclName, StringRef ExpectedPrinted) { std::vector<std::string> Args{"-std=c++11"}; - return PrintedDeclMatches(Code, Args, namedDecl(hasName(DeclName)).bind("id"), - ExpectedPrinted, "input.cc", - [](llvm::raw_ostream &Out, const NamedDecl *D) { - D->printNestedNameSpecifier(Out); - }); + return PrintedDeclMatches( + Code, Args, namedDecl(hasName(std::string(DeclName))).bind("id"), + ExpectedPrinted, "input.cc", + [](llvm::raw_ostream &Out, const NamedDecl *D) { + D->printNestedNameSpecifier(Out); + }); } } // unnamed namespace diff --git a/clang/unittests/AST/StmtPrinterTest.cpp b/clang/unittests/AST/StmtPrinterTest.cpp index 080c18b..76195af 100644 --- a/clang/unittests/AST/StmtPrinterTest.cpp +++ b/clang/unittests/AST/StmtPrinterTest.cpp @@ -34,7 +34,7 @@ namespace { enum class StdVer { CXX98, CXX11, CXX14, CXX17, CXX2a }; DeclarationMatcher FunctionBodyMatcher(StringRef ContainingFunction) { - return functionDecl(hasName(ContainingFunction), + return functionDecl(hasName(std::string(ContainingFunction)), has(compoundStmt(has(stmt().bind("id"))))); } diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.h b/clang/unittests/ASTMatchers/ASTMatchersTest.h index 745122a..6af039e 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.h +++ b/clang/unittests/ASTMatchers/ASTMatchersTest.h @@ -268,8 +268,8 @@ testing::AssertionResult matchesConditionallyWithCuda( // unknown-unknown triple is good for a large speedup, because it lets us // avoid constructing a full system triple. std::vector<std::string> Args = { - "-xcuda", "-fno-ms-extensions", "--cuda-host-only", "-nocudainc", - "-target", "x86_64-unknown-unknown", CompileArg}; + "-xcuda", "-fno-ms-extensions", "--cuda-host-only", "-nocudainc", + "-target", "x86_64-unknown-unknown", std::string(CompileArg)}; if (!runToolOnCodeWithArgs(Factory->create(), CudaHeader + Code, Args)) { return testing::AssertionFailure() << "Parsing error in \"" << Code << "\""; @@ -385,20 +385,20 @@ public: // Create an object that checks that a node of type \c T was bound to \c Id. // Does not check for a certain number of matches. explicit VerifyIdIsBoundTo(llvm::StringRef Id) - : Id(Id), ExpectedCount(-1), Count(0) {} + : Id(std::string(Id)), ExpectedCount(-1), Count(0) {} // Create an object that checks that a node of type \c T was bound to \c Id. // Checks that there were exactly \c ExpectedCount matches. VerifyIdIsBoundTo(llvm::StringRef Id, int ExpectedCount) - : Id(Id), ExpectedCount(ExpectedCount), Count(0) {} + : Id(std::string(Id)), ExpectedCount(ExpectedCount), Count(0) {} // Create an object that checks that a node of type \c T was bound to \c Id. // Checks that there was exactly one match with the name \c ExpectedName. // Note that \c T must be a NamedDecl for this to work. VerifyIdIsBoundTo(llvm::StringRef Id, llvm::StringRef ExpectedName, int ExpectedCount = 1) - : Id(Id), ExpectedCount(ExpectedCount), Count(0), - ExpectedName(ExpectedName) {} + : Id(std::string(Id)), ExpectedCount(ExpectedCount), Count(0), + ExpectedName(std::string(ExpectedName)) {} void onEndOfTranslationUnit() override { if (ExpectedCount != -1) { diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp index b1f070bd..29f30cb 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp @@ -1572,7 +1572,7 @@ TEST(IgnoringImplicit, MatchesImplicit) { } TEST(IgnoringImplicit, MatchesNestedImplicit) { - StringRef Code = R"( + const char *Code = R"( struct OtherType; @@ -1617,7 +1617,7 @@ TEST(IgnoringImplicit, DoesNotMatchIncorrectly) { TEST(Traversal, traverseMatcher) { - StringRef VarDeclCode = R"cpp( + const char *VarDeclCode = R"cpp( void foo() { int i = 3.0; @@ -1692,7 +1692,7 @@ void foo() functionDecl(traverse(ast_type_traits::TK_IgnoreUnlessSpelledInSource, hasAnyName("foo", "bar"))))); - llvm::StringRef Code = R"cpp( + const char *Code = R"cpp( void foo(int a) { int i = 3.0 + a; @@ -1759,7 +1759,7 @@ const char *SomeString{"str"}; template <typename MatcherT> bool matcherTemplateWithBinding(StringRef Code, const MatcherT &M) { return matchAndVerifyResultTrue( - Code, M.bind("matchedStmt"), + std::string(Code), M.bind("matchedStmt"), std::make_unique<VerifyIdIsBoundTo<ReturnStmt>>("matchedStmt", 1)); } @@ -1781,7 +1781,7 @@ int foo() TEST(Traversal, traverseMatcherNesting) { - StringRef Code = R"cpp( + const char *Code = R"cpp( float bar(int i) { return i; @@ -1802,7 +1802,7 @@ void foo() } TEST(Traversal, traverseMatcherThroughImplicit) { - StringRef Code = R"cpp( + const char *Code = R"cpp( struct S { S(int x); }; @@ -1822,7 +1822,7 @@ void constructImplicit() { TEST(Traversal, traverseMatcherThroughMemoization) { - StringRef Code = R"cpp( + const char *Code = R"cpp( void foo() { int i = 3.0; @@ -1847,7 +1847,7 @@ void foo() TEST(Traversal, traverseUnlessSpelledInSource) { - StringRef Code = R"cpp( + const char *Code = R"cpp( struct A { diff --git a/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp b/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp index 6c07c83..d98e319 100644 --- a/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp +++ b/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp @@ -43,7 +43,7 @@ public: llvm::Optional<MatcherCtor> lookupMatcherCtor(StringRef MatcherName) override { const ExpectedMatchersTy::value_type *Matcher = - &*ExpectedMatchers.find(MatcherName); + &*ExpectedMatchers.find(std::string(MatcherName)); return reinterpret_cast<MatcherCtor>(Matcher); } @@ -54,7 +54,8 @@ public: Diagnostics *Error) override { const ExpectedMatchersTy::value_type *Matcher = reinterpret_cast<const ExpectedMatchersTy::value_type *>(Ctor); - MatcherInfo ToStore = { Matcher->first, NameRange, Args, BindID }; + MatcherInfo ToStore = {Matcher->first, NameRange, Args, + std::string(BindID)}; Matchers.push_back(ToStore); return VariantMatcher::SingleMatcher(Matcher->second); } diff --git a/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp b/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp index 1c3e00c..b24ec07f3 100644 --- a/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp +++ b/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp @@ -44,7 +44,7 @@ std::unique_ptr<ASTUnit> buildASTFromCode(const Twine &Code) { } ExprMatcher declRefTo(StringRef Name) { - return declRefExpr(to(namedDecl(hasName(Name)))); + return declRefExpr(to(namedDecl(hasName(std::string(Name))))); } StmtMatcher withEnclosingCompound(ExprMatcher Matcher) { diff --git a/clang/unittests/Basic/SourceManagerTest.cpp b/clang/unittests/Basic/SourceManagerTest.cpp index 07c72e2..f4bdd9c 100644 --- a/clang/unittests/Basic/SourceManagerTest.cpp +++ b/clang/unittests/Basic/SourceManagerTest.cpp @@ -347,7 +347,7 @@ struct MacroAction { unsigned MAKind : 3; MacroAction(SourceLocation Loc, StringRef Name, unsigned K) - : Loc(Loc), Name(Name), MAKind(K) { } + : Loc(Loc), Name(std::string(Name)), MAKind(K) {} bool isExpansion() const { return MAKind == kExpansion; } bool isDefinition() const { return MAKind & kDefinition; } diff --git a/clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp b/clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp index 7a898cd..510ade4 100644 --- a/clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp +++ b/clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp @@ -45,9 +45,9 @@ struct DirectoryWatcherTestFixture { #endif createUniqueDirectory("dirwatcher", pathBuf); assert(!UniqDirRes); - TestRootDir = pathBuf.str(); + TestRootDir = std::string(pathBuf.str()); path::append(pathBuf, "watch"); - TestWatchedDir = pathBuf.str(); + TestWatchedDir = std::string(pathBuf.str()); #ifndef NDEBUG std::error_code CreateDirRes = #endif diff --git a/clang/unittests/Frontend/ASTUnitTest.cpp b/clang/unittests/Frontend/ASTUnitTest.cpp index 5cb2087..fbc641e 100644 --- a/clang/unittests/Frontend/ASTUnitTest.cpp +++ b/clang/unittests/Frontend/ASTUnitTest.cpp @@ -87,7 +87,7 @@ TEST_F(ASTUnitTest, SaveLoadPreservesLangOptionsInPrintingPolicy) { EXPECT_TRUE(llvm::sys::fs::exists(ASTFileName)); std::unique_ptr<ASTUnit> AU = ASTUnit::LoadFromASTFile( - ASTFileName.str(), PCHContainerOps->getRawReader(), + std::string(ASTFileName.str()), PCHContainerOps->getRawReader(), ASTUnit::LoadEverything, Diags, FileSystemOptions(), /*UseDebugInfo=*/false); diff --git a/clang/unittests/Frontend/CompilerInstanceTest.cpp b/clang/unittests/Frontend/CompilerInstanceTest.cpp index d2377d0..eeae2e9 100644 --- a/clang/unittests/Frontend/CompilerInstanceTest.cpp +++ b/clang/unittests/Frontend/CompilerInstanceTest.cpp @@ -32,8 +32,8 @@ TEST(CompilerInstance, DefaultVFSOverlayFromInvocation) { // Mount the VFS file itself on the path 'virtual.file'. Makes this test // a bit shorter than creating a new dummy file just for this purpose. - const std::string CurrentPathStr = CurrentPath.str(); - const std::string FileNameStr = FileName.str(); + const std::string CurrentPathStr = std::string(CurrentPath.str()); + const std::string FileNameStr = std::string(FileName.str()); const char *VFSYaml = "{ 'version': 0, 'roots': [\n" " { 'name': '%s',\n" " 'type': 'directory',\n" diff --git a/clang/unittests/Frontend/FrontendActionTest.cpp b/clang/unittests/Frontend/FrontendActionTest.cpp index d0a3020..9f8a746 100644 --- a/clang/unittests/Frontend/FrontendActionTest.cpp +++ b/clang/unittests/Frontend/FrontendActionTest.cpp @@ -272,7 +272,8 @@ TEST(GeneratePCHFrontendAction, CacheGeneratedPCH) { MemoryBuffer::getMemBuffer("int foo(void) { return 1; }\n").release()); Invocation->getFrontendOpts().Inputs.push_back( FrontendInputFile("test.h", Language::C)); - Invocation->getFrontendOpts().OutputFile = StringRef(PCHFilename); + Invocation->getFrontendOpts().OutputFile = + std::string(StringRef(PCHFilename)); Invocation->getFrontendOpts().ProgramAction = frontend::GeneratePCH; Invocation->getTargetOpts().Triple = "x86_64-apple-darwin19.0.0"; CompilerInstance Compiler; diff --git a/clang/unittests/Index/IndexTests.cpp b/clang/unittests/Index/IndexTests.cpp index 3ccec683..a279f48 100644 --- a/clang/unittests/Index/IndexTests.cpp +++ b/clang/unittests/Index/IndexTests.cpp @@ -95,7 +95,7 @@ public: SymbolRoleSet Roles, SourceLocation Loc) override { TestSymbol S; S.SymInfo = getSymbolInfoForMacro(*MI); - S.QName = Name->getName(); + S.QName = std::string(Name->getName()); S.WrittenPos = Position::fromSourceLocation(Loc, AST->getSourceManager()); S.DeclPos = Position::fromSourceLocation(MI->getDefinitionLoc(), AST->getSourceManager()); diff --git a/clang/unittests/Lex/LexerTest.cpp b/clang/unittests/Lex/LexerTest.cpp index ad9010e..c68eed9 100644 --- a/clang/unittests/Lex/LexerTest.cpp +++ b/clang/unittests/Lex/LexerTest.cpp @@ -98,7 +98,7 @@ protected: SourceMgr, LangOpts, &Invalid); if (Invalid) return "<INVALID>"; - return Str; + return std::string(Str); } FileSystemOptions FileMgrOpts; diff --git a/clang/unittests/Rename/ClangRenameTest.h b/clang/unittests/Rename/ClangRenameTest.h index 9dfa6d9..6403365 100644 --- a/clang/unittests/Rename/ClangRenameTest.h +++ b/clang/unittests/Rename/ClangRenameTest.h @@ -58,7 +58,7 @@ protected: Context.createInMemoryFile(HeaderName, HeaderContent); clang::FileID InputFileID = Context.createInMemoryFile(CCName, NewCode); - tooling::USRFindingAction FindingAction({}, {OldName}, false); + tooling::USRFindingAction FindingAction({}, {std::string(OldName)}, false); std::unique_ptr<tooling::FrontendActionFactory> USRFindingActionFactory = tooling::newFrontendActionFactory(&FindingAction); @@ -70,7 +70,7 @@ protected: const std::vector<std::vector<std::string>> &USRList = FindingAction.getUSRList(); - std::vector<std::string> NewNames = {NewName}; + std::vector<std::string> NewNames = {std::string(NewName)}; std::map<std::string, tooling::Replacements> FileToReplacements; tooling::QualifiedRenamingAction RenameAction(NewNames, USRList, FileToReplacements); diff --git a/clang/unittests/Sema/ExternalSemaSourceTest.cpp b/clang/unittests/Sema/ExternalSemaSourceTest.cpp index 44006e3..842eb83 100644 --- a/clang/unittests/Sema/ExternalSemaSourceTest.cpp +++ b/clang/unittests/Sema/ExternalSemaSourceTest.cpp @@ -48,7 +48,7 @@ class DiagnosticWatcher : public clang::DiagnosticConsumer { public: DiagnosticWatcher(StringRef From, StringRef To) : Chained(nullptr), FromName(From), ToName("'"), SeenCount(0) { - ToName.append(To); + ToName.append(std::string(To)); ToName.append("'"); } diff --git a/clang/unittests/StaticAnalyzer/Reusables.h b/clang/unittests/StaticAnalyzer/Reusables.h index bac2808..db9c085 100644 --- a/clang/unittests/StaticAnalyzer/Reusables.h +++ b/clang/unittests/StaticAnalyzer/Reusables.h @@ -34,7 +34,7 @@ const T *findNode(const Decl *Where, MatcherT What) { template <typename T> const T *findDeclByName(const Decl *Where, StringRef Name) { using namespace ast_matchers; - return findNode<T>(Where, namedDecl(hasName(Name))); + return findNode<T>(Where, namedDecl(hasName(std::string(Name)))); } // A re-usable consumer that constructs ExprEngine out of CompilerInvocation. diff --git a/clang/unittests/Tooling/CompilationDatabaseTest.cpp b/clang/unittests/Tooling/CompilationDatabaseTest.cpp index 56ebadc..cc948b8 100644 --- a/clang/unittests/Tooling/CompilationDatabaseTest.cpp +++ b/clang/unittests/Tooling/CompilationDatabaseTest.cpp @@ -87,11 +87,11 @@ TEST(JSONCompilationDatabase, GetAllFiles) { std::vector<std::string> expected_files; SmallString<16> PathStorage; llvm::sys::path::native("//net/dir/file1", PathStorage); - expected_files.push_back(PathStorage.str()); + expected_files.push_back(std::string(PathStorage.str())); llvm::sys::path::native("//net/dir/file2", PathStorage); - expected_files.push_back(PathStorage.str()); + expected_files.push_back(std::string(PathStorage.str())); llvm::sys::path::native("//net/file1", PathStorage); - expected_files.push_back(PathStorage.str()); + expected_files.push_back(std::string(PathStorage.str())); EXPECT_EQ(expected_files, getAllFiles("[{\"directory\":\"//net/dir\"," "\"command\":\"command\"," @@ -654,7 +654,7 @@ struct MemCDB : public CompilationDatabase { std::vector<std::string> getAllFiles() const override { std::vector<std::string> Result; for (const auto &Entry : Entries) - Result.push_back(Entry.first()); + Result.push_back(std::string(Entry.first())); return Result; } }; @@ -682,7 +682,7 @@ protected: llvm::sys::path::native(File); llvm::SmallString<64> Result; llvm::sys::path::append(Result, Dir, File); - return Result.str(); + return std::string(Result.str()); } MemCDB::EntryMap Entries; @@ -723,7 +723,7 @@ protected: Proxy.consume_front(llvm::sys::path::get_separator()); llvm::SmallString<32> Result = Proxy; llvm::sys::path::native(Result, llvm::sys::path::Style::posix); - return Result.str(); + return std::string(Result.str()); } }; diff --git a/clang/unittests/Tooling/DependencyScannerTest.cpp b/clang/unittests/Tooling/DependencyScannerTest.cpp index 60f6566..5a9c514 100644 --- a/clang/unittests/Tooling/DependencyScannerTest.cpp +++ b/clang/unittests/Tooling/DependencyScannerTest.cpp @@ -83,9 +83,11 @@ TEST(DependencyScanner, ScanDepsReuseFilemanager) { auto VFS = new llvm::vfs::InMemoryFileSystem(); VFS->setCurrentWorkingDirectory(CWD); auto Sept = llvm::sys::path::get_separator(); - std::string HeaderPath = llvm::formatv("{0}root{0}header.h", Sept); - std::string SymlinkPath = llvm::formatv("{0}root{0}symlink.h", Sept); - std::string TestPath = llvm::formatv("{0}root{0}test.cpp", Sept); + std::string HeaderPath = + std::string(llvm::formatv("{0}root{0}header.h", Sept)); + std::string SymlinkPath = + std::string(llvm::formatv("{0}root{0}symlink.h", Sept)); + std::string TestPath = std::string(llvm::formatv("{0}root{0}test.cpp", Sept)); VFS->addFile(HeaderPath, 0, llvm::MemoryBuffer::getMemBuffer("\n")); VFS->addHardLink(SymlinkPath, HeaderPath); @@ -130,10 +132,13 @@ TEST(DependencyScanner, ScanDepsReuseFilemanagerSkippedFile) { auto VFS = new llvm::vfs::InMemoryFileSystem(); VFS->setCurrentWorkingDirectory(CWD); auto Sept = llvm::sys::path::get_separator(); - std::string HeaderPath = llvm::formatv("{0}root{0}header.h", Sept); - std::string SymlinkPath = llvm::formatv("{0}root{0}symlink.h", Sept); - std::string TestPath = llvm::formatv("{0}root{0}test.cpp", Sept); - std::string Test2Path = llvm::formatv("{0}root{0}test2.cpp", Sept); + std::string HeaderPath = + std::string(llvm::formatv("{0}root{0}header.h", Sept)); + std::string SymlinkPath = + std::string(llvm::formatv("{0}root{0}symlink.h", Sept)); + std::string TestPath = std::string(llvm::formatv("{0}root{0}test.cpp", Sept)); + std::string Test2Path = + std::string(llvm::formatv("{0}root{0}test2.cpp", Sept)); VFS->addFile(HeaderPath, 0, llvm::MemoryBuffer::getMemBuffer("#pragma once\n")); @@ -169,9 +174,11 @@ TEST(DependencyScanner, ScanDepsReuseFilemanagerHasInclude) { auto VFS = new llvm::vfs::InMemoryFileSystem(); VFS->setCurrentWorkingDirectory(CWD); auto Sept = llvm::sys::path::get_separator(); - std::string HeaderPath = llvm::formatv("{0}root{0}header.h", Sept); - std::string SymlinkPath = llvm::formatv("{0}root{0}symlink.h", Sept); - std::string TestPath = llvm::formatv("{0}root{0}test.cpp", Sept); + std::string HeaderPath = + std::string(llvm::formatv("{0}root{0}header.h", Sept)); + std::string SymlinkPath = + std::string(llvm::formatv("{0}root{0}symlink.h", Sept)); + std::string TestPath = std::string(llvm::formatv("{0}root{0}test.cpp", Sept)); VFS->addFile(HeaderPath, 0, llvm::MemoryBuffer::getMemBuffer("\n")); VFS->addHardLink(SymlinkPath, HeaderPath); diff --git a/clang/unittests/Tooling/ExecutionTest.cpp b/clang/unittests/Tooling/ExecutionTest.cpp index 16455fb..91ab859 100644 --- a/clang/unittests/Tooling/ExecutionTest.cpp +++ b/clang/unittests/Tooling/ExecutionTest.cpp @@ -112,7 +112,7 @@ public: } void mapVirtualFile(StringRef FilePath, StringRef Content) override { - VFS[FilePath] = Content; + VFS[std::string(FilePath)] = std::string(Content); } private: @@ -289,7 +289,7 @@ TEST(AllTUsToolTest, ManyFiles) { ASSERT_TRUE(!Err); std::vector<std::string> Results; Executor.getToolResults()->forEachResult( - [&](StringRef Name, StringRef) { Results.push_back(Name); }); + [&](StringRef Name, StringRef) { Results.push_back(std::string(Name)); }); EXPECT_THAT(ExpectedSymbols, ::testing::UnorderedElementsAreArray(Results)); } diff --git a/clang/unittests/Tooling/HeaderIncludesTest.cpp b/clang/unittests/Tooling/HeaderIncludesTest.cpp index 635d7eb..9f86d2e 100644 --- a/clang/unittests/Tooling/HeaderIncludesTest.cpp +++ b/clang/unittests/Tooling/HeaderIncludesTest.cpp @@ -25,7 +25,7 @@ protected: assert(Header.startswith("\"") || Header.startswith("<")); auto R = Includes.insert(Header.trim("\"<>"), Header.startswith("<")); if (!R) - return Code; + return std::string(Code); auto Result = applyAllReplacements(Code, Replacements(*R)); EXPECT_TRUE(static_cast<bool>(Result)); return *Result; diff --git a/clang/unittests/Tooling/RangeSelectorTest.cpp b/clang/unittests/Tooling/RangeSelectorTest.cpp index 8a7d555..a84b0b9 100644 --- a/clang/unittests/Tooling/RangeSelectorTest.cpp +++ b/clang/unittests/Tooling/RangeSelectorTest.cpp @@ -108,7 +108,7 @@ Expected<CharSourceRange> selectFromAssorted(RangeSelector Selector) { } // Matches the message expected for type-error failures. -testing::Matcher<StringError> withTypeErrorMessage(StringRef NodeID) { +testing::Matcher<StringError> withTypeErrorMessage(const std::string &NodeID) { return testing::Property( &StringError::getMessage, AllOf(HasSubstr(NodeID), HasSubstr("mismatched type"))); @@ -131,7 +131,7 @@ TEST(RangeSelectorTest, BeforeOp) { int f(int x, int y, int z) { return 3; } int g() { return f(/* comment */ 3, 7 /* comment */, 9); } )cc"; - StringRef Call = "call"; + const char *Call = "call"; TestMatch Match = matchCode(Code, callExpr().bind(Call)); const auto* E = Match.Result.Nodes.getNodeAs<Expr>(Call); assert(E != nullptr); @@ -173,8 +173,8 @@ TEST(RangeSelectorTest, RangeOp) { int f(int x, int y, int z) { return 3; } int g() { return f(/* comment */ 3, 7 /* comment */, 9); } )cc"; - StringRef Arg0 = "a0"; - StringRef Arg1 = "a1"; + const char *Arg0 = "a0"; + const char *Arg1 = "a1"; StringRef Call = "call"; auto Matcher = callExpr(hasArgument(0, expr().bind(Arg0)), hasArgument(1, expr().bind(Arg1))) @@ -190,21 +190,21 @@ TEST(RangeSelectorTest, RangeOp) { TEST(RangeSelectorTest, NodeOpStatement) { StringRef Code = "int f() { return 3; }"; - StringRef ID = "id"; + const char *ID = "id"; TestMatch Match = matchCode(Code, returnStmt().bind(ID)); EXPECT_THAT_EXPECTED(select(node(ID), Match), HasValue("return 3;")); } TEST(RangeSelectorTest, NodeOpExpression) { StringRef Code = "int f() { return 3; }"; - StringRef ID = "id"; + const char *ID = "id"; TestMatch Match = matchCode(Code, expr().bind(ID)); EXPECT_THAT_EXPECTED(select(node(ID), Match), HasValue("3")); } TEST(RangeSelectorTest, StatementOp) { StringRef Code = "int f() { return 3; }"; - StringRef ID = "id"; + const char *ID = "id"; TestMatch Match = matchCode(Code, expr().bind(ID)); EXPECT_THAT_EXPECTED(select(statement(ID), Match), HasValue("3;")); } @@ -219,7 +219,7 @@ TEST(RangeSelectorTest, MemberOp) { return s.member; } )cc"; - StringRef ID = "id"; + const char *ID = "id"; TestMatch Match = matchCode(Code, memberExpr().bind(ID)); EXPECT_THAT_EXPECTED(select(member(ID), Match), HasValue("member")); } @@ -238,7 +238,7 @@ TEST(RangeSelectorTest, MemberOpQualified) { return t.S::member; } )cc"; - StringRef ID = "id"; + const char *ID = "id"; TestMatch Match = matchCode(Code, memberExpr().bind(ID)); EXPECT_THAT_EXPECTED(select(member(ID), Match), HasValue("member")); } @@ -254,7 +254,7 @@ TEST(RangeSelectorTest, MemberOpTemplate) { } )cc"; - StringRef ID = "id"; + const char *ID = "id"; TestMatch Match = matchCode(Code, memberExpr().bind(ID)); EXPECT_THAT_EXPECTED(select(member(ID), Match), HasValue("foo")); } @@ -270,7 +270,7 @@ TEST(RangeSelectorTest, MemberOpOperator) { } )cc"; - StringRef ID = "id"; + const char *ID = "id"; TestMatch Match = matchCode(Code, memberExpr().bind(ID)); EXPECT_THAT_EXPECTED(select(member(ID), Match), HasValue("operator *")); } @@ -281,7 +281,7 @@ TEST(RangeSelectorTest, NameOpNamedDecl) { return 3; } )cc"; - StringRef ID = "id"; + const char *ID = "id"; TestMatch Match = matchCode(Code, functionDecl().bind(ID)); EXPECT_THAT_EXPECTED(select(name(ID), Match), HasValue("myfun")); } @@ -293,7 +293,7 @@ TEST(RangeSelectorTest, NameOpDeclRef) { } int g(int x) { return foo(x) * x; } )cc"; - StringRef Ref = "ref"; + const char *Ref = "ref"; TestMatch Match = matchCode(Code, declRefExpr(to(functionDecl())).bind(Ref)); EXPECT_THAT_EXPECTED(select(name(Ref), Match), HasValue("foo")); } @@ -306,7 +306,7 @@ TEST(RangeSelectorTest, NameOpCtorInitializer) { int field; }; )cc"; - StringRef Init = "init"; + const char *Init = "init"; TestMatch Match = matchCode(Code, cxxCtorInitializer().bind(Init)); EXPECT_THAT_EXPECTED(select(name(Init), Match), HasValue("field")); } @@ -328,7 +328,7 @@ TEST(RangeSelectorTest, NameOpDeclRefError) { return *s + x; } )cc"; - StringRef Ref = "ref"; + const char *Ref = "ref"; TestMatch Match = matchCode(Code, declRefExpr(to(functionDecl())).bind(Ref)); EXPECT_THAT_EXPECTED( name(Ref)(Match.Result), @@ -347,7 +347,7 @@ TEST(RangeSelectorTest, CallArgsOp) { return x.bar(3, 4); } )cc"; - StringRef ID = "id"; + const char *ID = "id"; TestMatch Match = matchCode(Code, callExpr().bind(ID)); EXPECT_THAT_EXPECTED(select(callArgs(ID), Match), HasValue("3, 4")); } @@ -362,7 +362,7 @@ TEST(RangeSelectorTest, CallArgsOpNoArgs) { return x.bar(); } )cc"; - StringRef ID = "id"; + const char *ID = "id"; TestMatch Match = matchCode(Code, callExpr().bind(ID)); EXPECT_THAT_EXPECTED(select(callArgs(ID), Match), HasValue("")); } @@ -377,7 +377,7 @@ TEST(RangeSelectorTest, CallArgsOpNoArgsWithComments) { return x.bar(/*empty*/); } )cc"; - StringRef ID = "id"; + const char *ID = "id"; TestMatch Match = matchCode(Code, callExpr().bind(ID)); EXPECT_THAT_EXPECTED(select(callArgs(ID), Match), HasValue("/*empty*/")); } @@ -394,7 +394,7 @@ TEST(RangeSelectorTest, CallArgsOpWithParens) { return C().bar(3, 4); } )cc"; - StringRef ID = "id"; + const char *ID = "id"; TestMatch Match = matchCode(Code, callExpr(callee(functionDecl(hasName("bar")))).bind(ID)); EXPECT_THAT_EXPECTED(select(callArgs(ID), Match), HasValue("3, 4")); @@ -410,7 +410,7 @@ TEST(RangeSelectorTest, CallArgsOpLeadingComments) { return x.bar(/*leading*/ 3, 4); } )cc"; - StringRef ID = "id"; + const char *ID = "id"; TestMatch Match = matchCode(Code, callExpr().bind(ID)); EXPECT_THAT_EXPECTED(select(callArgs(ID), Match), HasValue("/*leading*/ 3, 4")); @@ -426,7 +426,7 @@ TEST(RangeSelectorTest, CallArgsOpTrailingComments) { return x.bar(3 /*trailing*/, 4); } )cc"; - StringRef ID = "id"; + const char *ID = "id"; TestMatch Match = matchCode(Code, callExpr().bind(ID)); EXPECT_THAT_EXPECTED(select(callArgs(ID), Match), HasValue("3 /*trailing*/, 4")); @@ -445,7 +445,7 @@ TEST(RangeSelectorTest, CallArgsOpEolComments) { ); } )cc"; - StringRef ID = "id"; + const char *ID = "id"; TestMatch Match = matchCode(Code, callExpr().bind(ID)); std::string ExpectedString = R"( // Header 1, // foo @@ -466,7 +466,7 @@ TEST(RangeSelectorTest, StatementsOp) { void g(); void f() { /* comment */ g(); /* comment */ g(); /* comment */ } )cc"; - StringRef ID = "id"; + const char *ID = "id"; TestMatch Match = matchCode(Code, compoundStmt().bind(ID)); EXPECT_THAT_EXPECTED( select(statements(ID), Match), @@ -475,7 +475,7 @@ TEST(RangeSelectorTest, StatementsOp) { TEST(RangeSelectorTest, StatementsOpEmptyList) { StringRef Code = "void f() {}"; - StringRef ID = "id"; + const char *ID = "id"; TestMatch Match = matchCode(Code, compoundStmt().bind(ID)); EXPECT_THAT_EXPECTED(select(statements(ID), Match), HasValue("")); } @@ -494,7 +494,7 @@ TEST(RangeSelectorTest, ElementsOp) { (void)v; } )cc"; - StringRef ID = "id"; + const char *ID = "id"; TestMatch Match = matchCode(Code, initListExpr().bind(ID)); EXPECT_THAT_EXPECTED( select(initListElements(ID), Match), @@ -508,7 +508,7 @@ TEST(RangeSelectorTest, ElementsOpEmptyList) { (void)v; } )cc"; - StringRef ID = "id"; + const char *ID = "id"; TestMatch Match = matchCode(Code, initListExpr().bind(ID)); EXPECT_THAT_EXPECTED(select(initListElements(ID), Match), HasValue("")); } @@ -529,7 +529,7 @@ TEST(RangeSelectorTest, ElseBranchOpSingleStatement) { return x + 5; } )cc"; - StringRef ID = "id"; + const char *ID = "id"; TestMatch Match = matchCode(Code, ifStmt().bind(ID)); EXPECT_THAT_EXPECTED(select(elseBranch(ID), Match), HasValue("else x = 4;")); } @@ -543,7 +543,7 @@ TEST(RangeSelectorTest, ElseBranchOpCompoundStatement) { return x + 5; } )cc"; - StringRef ID = "id"; + const char *ID = "id"; TestMatch Match = matchCode(Code, ifStmt().bind(ID)); EXPECT_THAT_EXPECTED(select(elseBranch(ID), Match), HasValue("else { x = 4; }")); @@ -556,7 +556,7 @@ TEST(RangeSelectorTest, ExpansionOp) { BADDECL(x * x) )cc"; - StringRef Fun = "Fun"; + const char *Fun = "Fun"; TestMatch Match = matchCode(Code, functionDecl(hasName("bad")).bind(Fun)); EXPECT_THAT_EXPECTED(select(expansion(node(Fun)), Match), HasValue("BADDECL(x * x)")); @@ -569,7 +569,7 @@ TEST(RangeSelectorTest, ExpansionOpPartial) { BADDECL(x * x) )cc"; - StringRef Ret = "Ret"; + const char *Ret = "Ret"; TestMatch Match = matchCode(Code, returnStmt().bind(Ret)); EXPECT_THAT_EXPECTED(select(expansion(node(Ret)), Match), HasValue("BADDECL(x * x)")); @@ -581,7 +581,7 @@ TEST(RangeSelectorTest, IfBoundOpBound) { return 3 + 5; } )cc"; - StringRef ID = "id", Op = "op"; + const char *ID = "id", *Op = "op"; TestMatch Match = matchCode(Code, binaryOperator(hasLHS(expr().bind(ID))).bind(Op)); EXPECT_THAT_EXPECTED(select(ifBound(ID, node(ID), node(Op)), Match), @@ -594,7 +594,7 @@ TEST(RangeSelectorTest, IfBoundOpUnbound) { return 3 + 5; } )cc"; - StringRef ID = "id", Op = "op"; + const char *ID = "id", *Op = "op"; TestMatch Match = matchCode(Code, binaryOperator().bind(Op)); EXPECT_THAT_EXPECTED(select(ifBound(ID, node(ID), node(Op)), Match), HasValue("3 + 5")); diff --git a/clang/unittests/Tooling/RecursiveASTVisitorTestPostOrderVisitor.cpp b/clang/unittests/Tooling/RecursiveASTVisitorTestPostOrderVisitor.cpp index 965bb3d..9fd075e 100644 --- a/clang/unittests/Tooling/RecursiveASTVisitorTestPostOrderVisitor.cpp +++ b/clang/unittests/Tooling/RecursiveASTVisitorTestPostOrderVisitor.cpp @@ -31,12 +31,12 @@ public: bool shouldTraversePostOrder() const { return VisitPostOrder; } bool VisitUnaryOperator(UnaryOperator *Op) { - VisitedNodes.push_back(Op->getOpcodeStr(Op->getOpcode())); + VisitedNodes.push_back(std::string(Op->getOpcodeStr(Op->getOpcode()))); return true; } bool VisitBinaryOperator(BinaryOperator *Op) { - VisitedNodes.push_back(Op->getOpcodeStr()); + VisitedNodes.push_back(std::string(Op->getOpcodeStr())); return true; } diff --git a/clang/unittests/Tooling/RefactoringTest.cpp b/clang/unittests/Tooling/RefactoringTest.cpp index 5949c53..d65c6db 100644 --- a/clang/unittests/Tooling/RefactoringTest.cpp +++ b/clang/unittests/Tooling/RefactoringTest.cpp @@ -528,12 +528,12 @@ TEST_F(ReplacementTest, MultipleFilesReplaceAndFormat) { // Scrambled the order of replacements. std::map<std::string, Replacements> FileToReplaces; - FileToReplaces[File1] = toReplacements( + FileToReplaces[std::string(File1)] = toReplacements( {tooling::Replacement(Context.Sources, Context.getLocation(ID1, 1, 1), 6, "auto "), tooling::Replacement(Context.Sources, Context.getLocation(ID1, 3, 10), 1, "12345678901")}); - FileToReplaces[File2] = toReplacements( + FileToReplaces[std::string(File2)] = toReplacements( {tooling::Replacement(Context.Sources, Context.getLocation(ID2, 1, 12), 0, "4567890123"), tooling::Replacement(Context.Sources, Context.getLocation(ID2, 2, 9), 1, @@ -612,7 +612,8 @@ public: assert(File); StringRef Found = - TemporaryFiles.insert(std::make_pair(Name, Path.str())).first->second; + TemporaryFiles.insert(std::make_pair(Name, std::string(Path.str()))) + .first->second; assert(Found == Path); (void)Found; return Context.Sources.createFileID(*File, SourceLocation(), @@ -628,7 +629,7 @@ public: // FIXME: Figure out whether there is a way to get the SourceManger to // reopen the file. auto FileBuffer = Context.Files.getBufferForFile(Path); - return (*FileBuffer)->getBuffer(); + return std::string((*FileBuffer)->getBuffer()); } llvm::StringMap<std::string> TemporaryFiles; @@ -1044,8 +1045,8 @@ TEST(DeduplicateByFileTest, PathsWithDots) { #endif EXPECT_TRUE(VFS->addFile(Path1, 0, llvm::MemoryBuffer::getMemBuffer(""))); EXPECT_TRUE(VFS->addFile(Path2, 0, llvm::MemoryBuffer::getMemBuffer(""))); - FileToReplaces[Path1] = Replacements(); - FileToReplaces[Path2] = Replacements(); + FileToReplaces[std::string(Path1)] = Replacements(); + FileToReplaces[std::string(Path2)] = Replacements(); FileToReplaces = groupReplacementsByFile(FileMgr, FileToReplaces); EXPECT_EQ(1u, FileToReplaces.size()); EXPECT_EQ(Path1, FileToReplaces.begin()->first); @@ -1065,8 +1066,8 @@ TEST(DeduplicateByFileTest, PathWithDotSlash) { #endif EXPECT_TRUE(VFS->addFile(Path1, 0, llvm::MemoryBuffer::getMemBuffer(""))); EXPECT_TRUE(VFS->addFile(Path2, 0, llvm::MemoryBuffer::getMemBuffer(""))); - FileToReplaces[Path1] = Replacements(); - FileToReplaces[Path2] = Replacements(); + FileToReplaces[std::string(Path1)] = Replacements(); + FileToReplaces[std::string(Path2)] = Replacements(); FileToReplaces = groupReplacementsByFile(FileMgr, FileToReplaces); EXPECT_EQ(1u, FileToReplaces.size()); EXPECT_EQ(Path1, FileToReplaces.begin()->first); @@ -1084,8 +1085,8 @@ TEST(DeduplicateByFileTest, NonExistingFilePath) { StringRef Path1 = ".\\a\\b\\c.h"; StringRef Path2 = "a\\b\\c.h"; #endif - FileToReplaces[Path1] = Replacements(); - FileToReplaces[Path2] = Replacements(); + FileToReplaces[std::string(Path1)] = Replacements(); + FileToReplaces[std::string(Path2)] = Replacements(); FileToReplaces = groupReplacementsByFile(FileMgr, FileToReplaces); EXPECT_TRUE(FileToReplaces.empty()); } @@ -1306,7 +1307,7 @@ protected: ~ApplyAtomicChangesTest() override {} void setInput(llvm::StringRef Input) { - Code = Input; + Code = std::string(Input); FID = Context.createInMemoryFile(FilePath, Code); } diff --git a/clang/unittests/Tooling/RewriterTestContext.h b/clang/unittests/Tooling/RewriterTestContext.h index cfe5577a..99f7a11 100644 --- a/clang/unittests/Tooling/RewriterTestContext.h +++ b/clang/unittests/Tooling/RewriterTestContext.h @@ -77,7 +77,8 @@ class RewriterTestContext { assert(File); StringRef Found = - TemporaryFiles.insert(std::make_pair(Name, Path.str())).first->second; + TemporaryFiles.insert(std::make_pair(Name, std::string(Path.str()))) + .first->second; assert(Found == Path); (void)Found; return Sources.createFileID(*File, SourceLocation(), SrcMgr::C_User); @@ -107,7 +108,7 @@ class RewriterTestContext { // FIXME: Figure out whether there is a way to get the SourceManger to // reopen the file. auto FileBuffer = Files.getBufferForFile(Path); - return (*FileBuffer)->getBuffer(); + return std::string((*FileBuffer)->getBuffer()); } IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts; diff --git a/clang/unittests/Tooling/SourceCodeBuildersTest.cpp b/clang/unittests/Tooling/SourceCodeBuildersTest.cpp index 9b5e7bf..b6f6aba 100644 --- a/clang/unittests/Tooling/SourceCodeBuildersTest.cpp +++ b/clang/unittests/Tooling/SourceCodeBuildersTest.cpp @@ -133,7 +133,7 @@ static void testBuilder( ASSERT_TRUE(StmtMatch); EXPECT_THAT(Builder(*StmtMatch->Result.Nodes.getNodeAs<Expr>("expr"), *StmtMatch->Result.Context), - ValueIs(Expected)); + ValueIs(std::string(Expected))); } TEST(SourceCodeBuildersTest, BuildParensUnaryOp) { diff --git a/clang/unittests/Tooling/StencilTest.cpp b/clang/unittests/Tooling/StencilTest.cpp index b248a5a..bd35f0d 100644 --- a/clang/unittests/Tooling/StencilTest.cpp +++ b/clang/unittests/Tooling/StencilTest.cpp @@ -111,7 +111,8 @@ protected: // Tests failures caused by references to unbound nodes. `unbound_id` is the // id that will cause the failure. void testUnboundNodeError(const Stencil &Stencil, StringRef UnboundId) { - testError(Stencil, AllOf(HasSubstr(UnboundId), HasSubstr("not bound"))); + testError(Stencil, + AllOf(HasSubstr(std::string(UnboundId)), HasSubstr("not bound"))); } }; @@ -128,8 +129,9 @@ TEST_F(StencilTest, SingleStatement) { hasThen(stmt().bind(Then)), hasElse(stmt().bind(Else)))); ASSERT_TRUE(StmtMatch); // Invert the if-then-else. - auto Stencil = cat("if (!", node(Condition), ") ", statement(Else), " else ", - statement(Then)); + auto Stencil = + cat("if (!", node(std::string(Condition)), ") ", + statement(std::string(Else)), " else ", statement(std::string(Then))); EXPECT_THAT_EXPECTED(Stencil->eval(StmtMatch->Result), HasValue("if (!true) return 0; else return 1;")); } @@ -156,7 +158,8 @@ void testExpr(StringRef Id, StringRef Snippet, const Stencil &Stencil, StringRef Expected) { auto StmtMatch = matchStmt(Snippet, expr().bind(Id)); ASSERT_TRUE(StmtMatch); - EXPECT_THAT_EXPECTED(Stencil->eval(StmtMatch->Result), HasValue(Expected)); + EXPECT_THAT_EXPECTED(Stencil->eval(StmtMatch->Result), + HasValue(std::string(Expected))); } void testFailure(StringRef Id, StringRef Snippet, const Stencil &Stencil, @@ -170,7 +173,7 @@ void testFailure(StringRef Id, StringRef Snippet, const Stencil &Stencil, TEST_F(StencilTest, SelectionOp) { StringRef Id = "id"; - testExpr(Id, "3;", cat(node(Id)), "3"); + testExpr(Id, "3;", cat(node(std::string(Id))), "3"); } TEST_F(StencilTest, IfBoundOpBound) { diff --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp b/clang/unittests/Tooling/Syntax/TreeTest.cpp index 42d77d8..1749e66 100644 --- a/clang/unittests/Tooling/Syntax/TreeTest.cpp +++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp @@ -862,7 +862,8 @@ void test() { auto *Root = buildTree(T.first); std::string Expected = llvm::StringRef(T.second).trim().str(); - std::string Actual = llvm::StringRef(Root->dump(*Arena)).trim(); + std::string Actual = + std::string(llvm::StringRef(Root->dump(*Arena)).trim()); EXPECT_EQ(Expected, Actual) << "the resulting dump is:\n" << Actual; } } diff --git a/clang/unittests/Tooling/ToolingTest.cpp b/clang/unittests/Tooling/ToolingTest.cpp index 1358134..59c9b4f 100644 --- a/clang/unittests/Tooling/ToolingTest.cpp +++ b/clang/unittests/Tooling/ToolingTest.cpp @@ -325,9 +325,9 @@ TEST(runToolOnCodeWithArgs, TestNoDepFile) { std::vector<std::string> Args; Args.push_back("-MMD"); Args.push_back("-MT"); - Args.push_back(DepFilePath.str()); + Args.push_back(std::string(DepFilePath.str())); Args.push_back("-MF"); - Args.push_back(DepFilePath.str()); + Args.push_back(std::string(DepFilePath.str())); EXPECT_TRUE(runToolOnCodeWithArgs(std::make_unique<SkipBodyAction>(), "", Args)); EXPECT_FALSE(llvm::sys::fs::exists(DepFilePath.str())); EXPECT_FALSE(llvm::sys::fs::remove(DepFilePath.str())); @@ -552,8 +552,9 @@ std::string getAnyTarget() { StringRef TargetName(Target.getName()); if (TargetName == "x86-64") TargetName = "x86_64"; - if (llvm::TargetRegistry::lookupTarget(TargetName, Error) == &Target) { - return TargetName; + if (llvm::TargetRegistry::lookupTarget(std::string(TargetName), Error) == + &Target) { + return std::string(TargetName); } } return ""; diff --git a/clang/unittests/Tooling/TransformerTest.cpp b/clang/unittests/Tooling/TransformerTest.cpp index c382783..454615c 100644 --- a/clang/unittests/Tooling/TransformerTest.cpp +++ b/clang/unittests/Tooling/TransformerTest.cpp @@ -174,7 +174,7 @@ TEST_F(TransformerTest, Flag) { hasName("proto::ProtoCommandLineFlag")))) .bind(Flag)), unless(callee(cxxMethodDecl(hasName("GetProto"))))), - changeTo(node(Flag), cat("EXPR"))); + changeTo(node(std::string(Flag)), cat("EXPR"))); std::string Input = R"cc( proto::ProtoCommandLineFlag flag; @@ -229,7 +229,7 @@ TEST_F(TransformerTest, AddIncludeAngled) { TEST_F(TransformerTest, NodePartNameNamedDecl) { StringRef Fun = "fun"; RewriteRule Rule = makeRule(functionDecl(hasName("bad")).bind(Fun), - changeTo(name(Fun), cat("good"))); + changeTo(name(std::string(Fun)), cat("good"))); std::string Input = R"cc( int bad(int x); @@ -261,7 +261,7 @@ TEST_F(TransformerTest, NodePartNameDeclRef) { StringRef Ref = "ref"; testRule(makeRule(declRefExpr(to(functionDecl(hasName("bad")))).bind(Ref), - changeTo(name(Ref), cat("good"))), + changeTo(name(std::string(Ref)), cat("good"))), Input, Expected); } @@ -279,7 +279,7 @@ TEST_F(TransformerTest, NodePartNameDeclRefFailure) { StringRef Ref = "ref"; Transformer T(makeRule(declRefExpr(to(functionDecl())).bind(Ref), - changeTo(name(Ref), cat("good"))), + changeTo(name(std::string(Ref)), cat("good"))), consumer()); T.registerMatchers(&MatchFinder); EXPECT_FALSE(rewrite(Input)); @@ -288,7 +288,7 @@ TEST_F(TransformerTest, NodePartNameDeclRefFailure) { TEST_F(TransformerTest, NodePartMember) { StringRef E = "expr"; RewriteRule Rule = makeRule(memberExpr(member(hasName("bad"))).bind(E), - changeTo(member(E), cat("good"))); + changeTo(member(std::string(E)), cat("good"))); std::string Input = R"cc( struct S { @@ -341,7 +341,8 @@ TEST_F(TransformerTest, NodePartMemberQualified) { )cc"; StringRef E = "expr"; - testRule(makeRule(memberExpr().bind(E), changeTo(member(E), cat("good"))), + testRule(makeRule(memberExpr().bind(E), + changeTo(member(std::string(E)), cat("good"))), Input, Expected); } @@ -373,7 +374,7 @@ TEST_F(TransformerTest, NodePartMemberMultiToken) { StringRef MemExpr = "member"; testRule(makeRule(memberExpr().bind(MemExpr), - changeTo(member(MemExpr), cat("good"))), + changeTo(member(std::string(MemExpr)), cat("good"))), Input, Expected); } @@ -391,9 +392,10 @@ TEST_F(TransformerTest, InsertBeforeEdit) { )cc"; StringRef Ret = "return"; - testRule(makeRule(returnStmt().bind(Ret), - insertBefore(statement(Ret), cat("int y = 3;"))), - Input, Expected); + testRule( + makeRule(returnStmt().bind(Ret), + insertBefore(statement(std::string(Ret)), cat("int y = 3;"))), + Input, Expected); } TEST_F(TransformerTest, InsertAfterEdit) { @@ -412,9 +414,10 @@ TEST_F(TransformerTest, InsertAfterEdit) { )cc"; StringRef Decl = "decl"; - testRule(makeRule(declStmt().bind(Decl), - insertAfter(statement(Decl), cat("int y = 3;"))), - Input, Expected); + testRule( + makeRule(declStmt().bind(Decl), + insertAfter(statement(std::string(Decl)), cat("int y = 3;"))), + Input, Expected); } TEST_F(TransformerTest, RemoveEdit) { @@ -431,8 +434,9 @@ TEST_F(TransformerTest, RemoveEdit) { )cc"; StringRef Decl = "decl"; - testRule(makeRule(declStmt().bind(Decl), remove(statement(Decl))), Input, - Expected); + testRule( + makeRule(declStmt().bind(Decl), remove(statement(std::string(Decl)))), + Input, Expected); } TEST_F(TransformerTest, MultiChange) { @@ -452,12 +456,13 @@ TEST_F(TransformerTest, MultiChange) { )"; StringRef C = "C", T = "T", E = "E"; - testRule(makeRule(ifStmt(hasCondition(expr().bind(C)), - hasThen(stmt().bind(T)), hasElse(stmt().bind(E))), - {changeTo(node(C), cat("true")), - changeTo(statement(T), cat("{ /* then */ }")), - changeTo(statement(E), cat("{ /* else */ }"))}), - Input, Expected); + testRule( + makeRule(ifStmt(hasCondition(expr().bind(C)), hasThen(stmt().bind(T)), + hasElse(stmt().bind(E))), + {changeTo(node(std::string(C)), cat("true")), + changeTo(statement(std::string(T)), cat("{ /* then */ }")), + changeTo(statement(std::string(E)), cat("{ /* else */ }"))}), + Input, Expected); } TEST_F(TransformerTest, OrderedRuleUnrelated) { @@ -467,7 +472,7 @@ TEST_F(TransformerTest, OrderedRuleUnrelated) { hasName("proto::ProtoCommandLineFlag")))) .bind(Flag)), unless(callee(cxxMethodDecl(hasName("GetProto"))))), - changeTo(node(Flag), cat("PROTO"))); + changeTo(node(std::string(Flag)), cat("PROTO"))); std::string Input = R"cc( proto::ProtoCommandLineFlag flag; @@ -582,9 +587,10 @@ TEST_F(TransformerTest, TextGeneratorFailure) { } std::string toString() const override { return "AlwaysFail"; } }; - Transformer T(makeRule(binaryOperator().bind(O), - changeTo(node(O), std::make_shared<AlwaysFail>())), - consumer()); + Transformer T( + makeRule(binaryOperator().bind(O), + changeTo(node(std::string(O)), std::make_shared<AlwaysFail>())), + consumer()); T.registerMatchers(&MatchFinder); EXPECT_FALSE(rewrite(Input)); EXPECT_THAT(Changes, IsEmpty()); @@ -597,8 +603,8 @@ TEST_F(TransformerTest, OverlappingEditsInRule) { // Try to change the whole binary-operator expression AND one its operands: StringRef O = "O", L = "L"; Transformer T(makeRule(binaryOperator(hasLHS(expr().bind(L))).bind(O), - {changeTo(node(O), cat("DELETE_OP")), - changeTo(node(L), cat("DELETE_LHS"))}), + {changeTo(node(std::string(O)), cat("DELETE_OP")), + changeTo(node(std::string(L)), cat("DELETE_LHS"))}), consumer()); T.registerMatchers(&MatchFinder); EXPECT_FALSE(rewrite(Input)); @@ -611,7 +617,8 @@ TEST_F(TransformerTest, OverlappingEditsMultipleMatches) { std::string Input = "int conflictOneRule() { return -7; }"; // Try to change the whole binary-operator expression AND one its operands: StringRef E = "E"; - Transformer T(makeRule(expr().bind(E), changeTo(node(E), cat("DELETE_EXPR"))), + Transformer T(makeRule(expr().bind(E), + changeTo(node(std::string(E)), cat("DELETE_EXPR"))), consumer()); T.registerMatchers(&MatchFinder); // The rewrite process fails because the changes conflict with each other... @@ -649,7 +656,7 @@ TEST_F(TransformerTest, SimpleMacro) { StringRef zero = "zero"; RewriteRule R = makeRule(integerLiteral(equals(0)).bind(zero), - changeTo(node(zero), cat("999"))); + changeTo(node(std::string(zero)), cat("999"))); testRule(R, Input, Expected); } @@ -746,7 +753,7 @@ TEST_F(TransformerTest, MatchSpansMacroTextButChangeDoesNot) { StringRef E = "expr"; testRule(makeRule(binaryOperator(hasLHS(expr().bind(E))), - changeTo(node(E), cat("LIT"))), + changeTo(node(std::string(E)), cat("LIT"))), Input, Expected); } @@ -764,7 +771,7 @@ TEST_F(TransformerTest, MatchSpansMacroTextButChangeDoesNotAnchoredInMacro) { StringRef E = "expr"; testRule(makeRule(binaryOperator(hasRHS(expr().bind(E))), - changeTo(node(E), cat("LIT"))), + changeTo(node(std::string(E)), cat("LIT"))), Input, Expected); } @@ -779,7 +786,7 @@ TEST_F(TransformerTest, NoPartialRewriteOMacroExpansion) { StringRef zero = "zero"; RewriteRule R = makeRule(integerLiteral(equals(0)).bind(zero), - changeTo(node(zero), cat("0"))); + changeTo(node(std::string(zero)), cat("0"))); testRule(R, Input, Input); } diff --git a/clang/unittests/libclang/TestUtils.h b/clang/unittests/libclang/TestUtils.h index 883155e..347fa46 100644 --- a/clang/unittests/libclang/TestUtils.h +++ b/clang/unittests/libclang/TestUtils.h @@ -34,7 +34,7 @@ public: void SetUp() override { llvm::SmallString<256> Dir; ASSERT_FALSE(llvm::sys::fs::createUniqueDirectory("libclang-test", Dir)); - TestDir = Dir.str(); + TestDir = std::string(Dir.str()); TUFlags = CXTranslationUnit_DetailedPreprocessingRecord | clang_defaultEditingTranslationUnitOptions(); Index = clang_createIndex(0, 0); @@ -51,7 +51,7 @@ public: if (!llvm::sys::path::is_absolute(Filename)) { llvm::SmallString<256> Path(TestDir); llvm::sys::path::append(Path, Filename); - Filename = Path.str(); + Filename = std::string(Path.str()); Files.insert(Filename); } llvm::sys::fs::create_directories(llvm::sys::path::parent_path(Filename)); @@ -63,7 +63,7 @@ public: if (!llvm::sys::path::is_absolute(Filename)) { llvm::SmallString<256> Path(TestDir); llvm::sys::path::append(Path, Filename); - Filename = Path.str(); + Filename = std::string(Path.str()); } auto it = UnsavedFileContents.insert(std::make_pair( fixed_addr_string(new std::string(Filename)), |