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.
diff --git a/clang/lib/Tooling/ASTDiff/ASTDiff.cpp b/clang/lib/Tooling/ASTDiff/ASTDiff.cpp
index 34e56f6..df00183 100644
--- a/clang/lib/Tooling/ASTDiff/ASTDiff.cpp
+++ b/clang/lib/Tooling/ASTDiff/ASTDiff.cpp
@@ -398,7 +398,7 @@
static std::string getInitializerValue(const CXXCtorInitializer *Init,
const PrintingPolicy &TypePP) {
if (Init->isAnyMemberInitializer())
- return Init->getAnyMember()->getName();
+ return std::string(Init->getAnyMember()->getName());
if (Init->isBaseInitializer())
return QualType(Init->getBaseClass(), 0).getAsString(TypePP);
if (Init->isDelegatingInitializer())
@@ -435,36 +435,36 @@
T->getTypeForDecl()->getCanonicalTypeInternal().getAsString(TypePP) +
";";
if (auto *U = dyn_cast<UsingDirectiveDecl>(D))
- return U->getNominatedNamespace()->getName();
+ return std::string(U->getNominatedNamespace()->getName());
if (auto *A = dyn_cast<AccessSpecDecl>(D)) {
CharSourceRange Range(A->getSourceRange(), false);
- return Lexer::getSourceText(Range, AST.getSourceManager(),
- AST.getLangOpts());
+ return std::string(
+ Lexer::getSourceText(Range, AST.getSourceManager(), AST.getLangOpts()));
}
return Value;
}
std::string SyntaxTree::Impl::getStmtValue(const Stmt *S) const {
if (auto *U = dyn_cast<UnaryOperator>(S))
- return UnaryOperator::getOpcodeStr(U->getOpcode());
+ return std::string(UnaryOperator::getOpcodeStr(U->getOpcode()));
if (auto *B = dyn_cast<BinaryOperator>(S))
- return B->getOpcodeStr();
+ return std::string(B->getOpcodeStr());
if (auto *M = dyn_cast<MemberExpr>(S))
return getRelativeName(M->getMemberDecl());
if (auto *I = dyn_cast<IntegerLiteral>(S)) {
SmallString<256> Str;
I->getValue().toString(Str, /*Radix=*/10, /*Signed=*/false);
- return Str.str();
+ return std::string(Str.str());
}
if (auto *F = dyn_cast<FloatingLiteral>(S)) {
SmallString<256> Str;
F->getValue().toString(Str);
- return Str.str();
+ return std::string(Str.str());
}
if (auto *D = dyn_cast<DeclRefExpr>(S))
return getRelativeName(D->getDecl(), getEnclosingDeclContext(AST, S));
if (auto *String = dyn_cast<StringLiteral>(S))
- return String->getString();
+ return std::string(String->getString());
if (auto *B = dyn_cast<CXXBoolLiteralExpr>(S))
return B->getValue() ? "true" : "false";
return "";