[clang-tools-extra] r245561 - [clang-tidy] Fix bug in modernize-loop-convert check.
Alexander Kornienko via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 20 06:18:23 PDT 2015
Author: alexfh
Date: Thu Aug 20 08:18:23 2015
New Revision: 245561
URL: http://llvm.org/viewvc/llvm-project?rev=245561&view=rev
Log:
[clang-tidy] Fix bug in modernize-loop-convert check.
http://reviews.llvm.org/D12186
Patch by Angel Garcia!
Modified:
clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-loop-convert/structures.h
clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp
Modified: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp?rev=245561&r1=245560&r2=245561&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp Thu Aug 20 08:18:23 2015
@@ -337,8 +337,9 @@ static StringRef getStringFromRange(Sour
const LangOptions &LangOpts,
SourceRange Range) {
if (SourceMgr.getFileID(Range.getBegin()) !=
- SourceMgr.getFileID(Range.getEnd()))
- return nullptr;
+ SourceMgr.getFileID(Range.getEnd())) {
+ return StringRef(); // Empty string.
+ }
return Lexer::getSourceText(CharSourceRange(Range, true), SourceMgr,
LangOpts);
Modified: clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-loop-convert/structures.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-loop-convert/structures.h?rev=245561&r1=245560&r2=245561&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-loop-convert/structures.h (original)
+++ clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-loop-convert/structures.h Thu Aug 20 08:18:23 2015
@@ -176,4 +176,15 @@ struct RValueDerefContainer {
iterator begin() const;
iterator end() const;
};
+
+namespace Macros {
+
+struct MacroStruct {
+ int arr[10];
+};
+static MacroStruct *MacroSt;
+#define CONT MacroSt->
+
+} // namespace Macros
+
#endif // STRUCTURES_H
Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp?rev=245561&r1=245560&r2=245561&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp Thu Aug 20 08:18:23 2015
@@ -605,4 +605,25 @@ void different_type() {
}
}
+} // namespace SingleIterator
+
+
+namespace Macros {
+
+const int N = 10;
+int arr[N];
+
+void messing_with_macros() {
+ for (int i = 0; i < N; ++i) {
+ printf("Value: %d\n", arr[i]);
+ }
+ // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+ // CHECK-FIXES: for (auto & elem : arr) {
+ // CHECK-FIXES-NEXT: printf("Value: %d\n", elem);
+
+ for (int i = 0; i < N; ++i) {
+ printf("Value: %d\n", CONT arr[i]);
+ }
}
+
+} // namespace Macros
More information about the cfe-commits
mailing list