Skip to content

Commit f71fb2d

Browse files
[clang] Use StringRef in range-based for loops (NFC) (#144242)
When we iterate over std::vector<std::string>, we can directly assign each element to StringRef. We do not need to go through separate statements.
1 parent 9adde28 commit f71fb2d

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

clang/lib/Basic/TargetInfo.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,7 @@ void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
555555
bool TargetInfo::initFeatureMap(
556556
llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
557557
const std::vector<std::string> &FeatureVec) const {
558-
for (const auto &F : FeatureVec) {
559-
StringRef Name = F;
558+
for (StringRef Name : FeatureVec) {
560559
if (Name.empty())
561560
continue;
562561
// Apply the feature via the target.

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3232,17 +3232,15 @@ bool Sema::checkTargetAttr(SourceLocation LiteralLoc, StringRef AttrStr) {
32323232
if (ParsedAttrs.Duplicate != "")
32333233
return Diag(LiteralLoc, diag::err_duplicate_target_attribute)
32343234
<< Duplicate << None << ParsedAttrs.Duplicate << Target;
3235-
for (const auto &Feature : ParsedAttrs.Features) {
3236-
StringRef CurFeature = Feature;
3235+
for (StringRef CurFeature : ParsedAttrs.Features) {
32373236
if (!CurFeature.starts_with('+') && !CurFeature.starts_with('-'))
32383237
return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
32393238
<< Unsupported << None << AttrStr << Target;
32403239
}
32413240
}
32423241

32433242
if (Context.getTargetInfo().getTriple().isLoongArch()) {
3244-
for (const auto &Feature : ParsedAttrs.Features) {
3245-
StringRef CurFeature = Feature;
3243+
for (StringRef CurFeature : ParsedAttrs.Features) {
32463244
if (CurFeature.starts_with("!arch=")) {
32473245
StringRef ArchValue = CurFeature.split("=").second.trim();
32483246
return Diag(LiteralLoc, diag::err_attribute_unsupported)

clang/lib/Tooling/ArgumentsAdjusters.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ namespace clang {
2222
namespace tooling {
2323

2424
static StringRef getDriverMode(const CommandLineArguments &Args) {
25-
for (const auto &Arg : Args) {
26-
StringRef ArgRef = Arg;
25+
for (StringRef ArgRef : Args) {
2726
if (ArgRef.consume_front("--driver-mode=")) {
2827
return ArgRef;
2928
}

0 commit comments

Comments
 (0)