[clang-tidy] Fix LoopConvertCheck bug.

Fix LoopConvertCheck bug: StringRef to temporaries.

Also add LLVM_ATTRIBUTE_UNUSED to ModernizeModuleAnchorDestination.

http://reviews.llvm.org/D12157

Patch by Angel Garcia!

llvm-svn: 245458
This commit is contained in:
Alexander Kornienko 2015-08-19 16:54:51 +00:00
parent eb552e83e0
commit e1292f8e4e
2 changed files with 14 additions and 11 deletions

View File

@ -417,7 +417,7 @@ void LoopConvertCheck::doConversion(
// First, replace all usages of the array subscript expression with our new
// variable.
for (const auto &I : Usages) {
StringRef ReplaceText = I.IsArrow ? VarName + "." : VarName;
std::string ReplaceText = I.IsArrow ? VarName + "." : VarName;
TUInfo->getReplacedVars().insert(std::make_pair(TheLoop, IndexVar));
Diag << FixItHint::CreateReplacement(
CharSourceRange::getTokenRange(I.Range), ReplaceText);
@ -446,11 +446,9 @@ void LoopConvertCheck::doConversion(
}
StringRef MaybeDereference = ContainerNeedsDereference ? "*" : "";
StringRef TypeString = AutoRefType.getAsString();
StringRef Range = ("(" + TypeString + " " + VarName + " : " +
MaybeDereference + ContainerString + ")")
.str();
std::string TypeString = AutoRefType.getAsString();
std::string Range = ("(" + TypeString + " " + VarName + " : " +
MaybeDereference + ContainerString + ")").str();
Diag << FixItHint::CreateReplacement(
CharSourceRange::getTokenRange(ParenRange), Range);
TUInfo->getGeneratedDecls().insert(make_pair(TheLoop, VarName));

View File

@ -347,23 +347,28 @@ static int clangTidyMain(int argc, const char **argv) {
// This anchor is used to force the linker to link the LLVMModule.
extern volatile int LLVMModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED LLVMModuleAnchorDestination = LLVMModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED LLVMModuleAnchorDestination =
LLVMModuleAnchorSource;
// This anchor is used to force the linker to link the GoogleModule.
extern volatile int GoogleModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED GoogleModuleAnchorDestination = GoogleModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED GoogleModuleAnchorDestination =
GoogleModuleAnchorSource;
// This anchor is used to force the linker to link the MiscModule.
extern volatile int MiscModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination = MiscModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =
MiscModuleAnchorSource;
// This anchor is used to force the linker to link the ModernizeModule.
extern volatile int ModernizeModuleAnchorSource;
static int ModernizeModuleAnchorDestination = ModernizeModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
ModernizeModuleAnchorSource;
// This anchor is used to force the linker to link the ReadabilityModule.
extern volatile int ReadabilityModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED ReadabilityModuleAnchorDestination = ReadabilityModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED ReadabilityModuleAnchorDestination =
ReadabilityModuleAnchorSource;
} // namespace tidy
} // namespace clang