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/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index 9b8dc148..6a2f744 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -282,7 +282,7 @@
}
CSec->Valid = true;
- CSec->SectionName = SecName;
+ CSec->SectionName = std::string(SecName);
CSec->PragmaLocation = PragmaLoc;
}
diff --git a/clang/lib/Sema/SemaAvailability.cpp b/clang/lib/Sema/SemaAvailability.cpp
index 0c0275d..bb3334a 100644
--- a/clang/lib/Sema/SemaAvailability.cpp
+++ b/clang/lib/Sema/SemaAvailability.cpp
@@ -368,8 +368,8 @@
unsigned Warning = UseNewWarning ? diag::warn_unguarded_availability_new
: diag::warn_unguarded_availability;
- std::string PlatformName = AvailabilityAttr::getPrettyPlatformName(
- S.getASTContext().getTargetInfo().getPlatformName());
+ std::string PlatformName(AvailabilityAttr::getPrettyPlatformName(
+ S.getASTContext().getTargetInfo().getPlatformName()));
S.Diag(Loc, Warning) << OffendingDecl << PlatformName
<< Introduced.getAsString();
@@ -767,8 +767,8 @@
? diag::warn_unguarded_availability_new
: diag::warn_unguarded_availability;
- std::string PlatformName = AvailabilityAttr::getPrettyPlatformName(
- SemaRef.getASTContext().getTargetInfo().getPlatformName());
+ std::string PlatformName(AvailabilityAttr::getPrettyPlatformName(
+ SemaRef.getASTContext().getTargetInfo().getPlatformName()));
SemaRef.Diag(Range.getBegin(), DiagKind)
<< Range << D << PlatformName << Introduced.getAsString();
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index 18b1172..487ba46 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -2755,7 +2755,7 @@
std::string Result;
if (Param->getIdentifier() && !ObjCMethodParam && !SuppressName)
- Result = Param->getIdentifier()->getName();
+ Result = std::string(Param->getIdentifier()->getName());
QualType Type = Param->getType();
if (ObjCSubsts)
@@ -2794,7 +2794,7 @@
// for the block; just use the parameter type as a placeholder.
std::string Result;
if (!ObjCMethodParam && Param->getIdentifier())
- Result = Param->getIdentifier()->getName();
+ Result = std::string(Param->getIdentifier()->getName());
QualType Type = Param->getType().getUnqualifiedType();
@@ -3009,7 +3009,7 @@
} else if (NonTypeTemplateParmDecl *NTTP =
dyn_cast<NonTypeTemplateParmDecl>(*P)) {
if (NTTP->getIdentifier())
- PlaceholderStr = NTTP->getIdentifier()->getName();
+ PlaceholderStr = std::string(NTTP->getIdentifier()->getName());
NTTP->getType().getAsStringInternal(PlaceholderStr, Policy);
HasDefaultArg = NTTP->hasDefaultArgument();
} else {
@@ -4339,7 +4339,7 @@
First = false;
constexpr llvm::StringLiteral NamePlaceholder = "!#!NAME_GOES_HERE!#!";
- std::string Type = NamePlaceholder;
+ std::string Type = std::string(NamePlaceholder);
Parameter.getAsStringInternal(Type, PrintingPolicy(LangOpts));
llvm::StringRef Prefix, Suffix;
std::tie(Prefix, Suffix) = llvm::StringRef(Type).split(NamePlaceholder);
@@ -7655,7 +7655,7 @@
} Key(Allocator, PropName->getName());
// The uppercased name of the property name.
- std::string UpperKey = PropName->getName();
+ std::string UpperKey = std::string(PropName->getName());
if (!UpperKey.empty())
UpperKey[0] = toUppercase(UpperKey[0]);
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index d70e85a..e8589d3 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -2741,21 +2741,19 @@
// heroics.
std::string SuitableSpelling;
if (S.getLangOpts().CPlusPlus2a)
- SuitableSpelling =
- S.PP.getLastMacroWithSpelling(InsertLoc, {tok::kw_constinit});
+ SuitableSpelling = std::string(
+ S.PP.getLastMacroWithSpelling(InsertLoc, {tok::kw_constinit}));
if (SuitableSpelling.empty() && S.getLangOpts().CPlusPlus11)
- SuitableSpelling = S.PP.getLastMacroWithSpelling(
- InsertLoc,
- {tok::l_square, tok::l_square, S.PP.getIdentifierInfo("clang"),
- tok::coloncolon,
- S.PP.getIdentifierInfo("require_constant_initialization"),
- tok::r_square, tok::r_square});
+ SuitableSpelling = std::string(S.PP.getLastMacroWithSpelling(
+ InsertLoc, {tok::l_square, tok::l_square,
+ S.PP.getIdentifierInfo("clang"), tok::coloncolon,
+ S.PP.getIdentifierInfo("require_constant_initialization"),
+ tok::r_square, tok::r_square}));
if (SuitableSpelling.empty())
- SuitableSpelling = S.PP.getLastMacroWithSpelling(
- InsertLoc,
- {tok::kw___attribute, tok::l_paren, tok::r_paren,
- S.PP.getIdentifierInfo("require_constant_initialization"),
- tok::r_paren, tok::r_paren});
+ SuitableSpelling = std::string(S.PP.getLastMacroWithSpelling(
+ InsertLoc, {tok::kw___attribute, tok::l_paren, tok::r_paren,
+ S.PP.getIdentifierInfo("require_constant_initialization"),
+ tok::r_paren, tok::r_paren}));
if (SuitableSpelling.empty() && S.getLangOpts().CPlusPlus2a)
SuitableSpelling = "constinit";
if (SuitableSpelling.empty() && S.getLangOpts().CPlusPlus11)
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 523daf3..814a3c6 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -952,7 +952,7 @@
Arg.getArgument().print(PrintingPolicy, OS);
First = false;
}
- return OS.str();
+ return std::string(OS.str());
}
static bool lookupStdTypeTraitMember(Sema &S, LookupResult &TraitMemberLookup,
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 5b00e55..b063247 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -11328,12 +11328,12 @@
if (XorStr == "xor")
return;
- std::string LHSStr = Lexer::getSourceText(
+ std::string LHSStr = std::string(Lexer::getSourceText(
CharSourceRange::getTokenRange(LHSInt->getSourceRange()),
- S.getSourceManager(), S.getLangOpts());
- std::string RHSStr = Lexer::getSourceText(
+ S.getSourceManager(), S.getLangOpts()));
+ std::string RHSStr = std::string(Lexer::getSourceText(
CharSourceRange::getTokenRange(RHSInt->getSourceRange()),
- S.getSourceManager(), S.getLangOpts());
+ S.getSourceManager(), S.getLangOpts()));
if (Negative) {
RightSideValue = -RightSideValue;
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 64e7b9d..5d253cd 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -11979,7 +11979,7 @@
else if (I + Skipped + 1 != Last)
Out << ", ";
}
- return Out.str();
+ return std::string(Out.str());
}
OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind,
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 4d38d07..1188017 100755
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -10627,7 +10627,7 @@
}
Out << ']';
- return Out.str();
+ return std::string(Out.str());
}
void Sema::MarkAsLateParsedTemplate(FunctionDecl *FD, Decl *FnD,