angelgarcia created this revision.
angelgarcia added a reviewer: alexfh.
angelgarcia added subscribers: klimek, cfe-commits.
angelgarcia changed the visibility of this Differential Revision from "Public 
(No Login Required)" to "All Users".

Fix LoopConvertCheck bug: StringRef to temporaries.

http://reviews.llvm.org/D12157

Files:
  clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tidy/tool/ClangTidyMain.cpp

Index: clang-tidy/tool/ClangTidyMain.cpp
===================================================================
--- clang-tidy/tool/ClangTidyMain.cpp
+++ clang-tidy/tool/ClangTidyMain.cpp
@@ -359,7 +359,7 @@
 
 // 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;
Index: clang-tidy/modernize/LoopConvertCheck.cpp
===================================================================
--- clang-tidy/modernize/LoopConvertCheck.cpp
+++ clang-tidy/modernize/LoopConvertCheck.cpp
@@ -417,7 +417,7 @@
     // 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 @@
   }
 
   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));


Index: clang-tidy/tool/ClangTidyMain.cpp
===================================================================
--- clang-tidy/tool/ClangTidyMain.cpp
+++ clang-tidy/tool/ClangTidyMain.cpp
@@ -359,7 +359,7 @@
 
 // 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;
Index: clang-tidy/modernize/LoopConvertCheck.cpp
===================================================================
--- clang-tidy/modernize/LoopConvertCheck.cpp
+++ clang-tidy/modernize/LoopConvertCheck.cpp
@@ -417,7 +417,7 @@
     // 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 @@
   }
 
   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));
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to