[PATCH] D12186: Fix bug in modernize-loop-convert check.
Angel Garcia via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 20 05:53:55 PDT 2015
angelgarcia updated this revision to Diff 32688.
angelgarcia added a comment.
Add a test.
http://reviews.llvm.org/D12186
Files:
clang-tidy/modernize/LoopConvertCheck.cpp
test/clang-tidy/Inputs/modernize-loop-convert/structures.h
test/clang-tidy/modernize-loop-convert-extra.cpp
Index: test/clang-tidy/modernize-loop-convert-extra.cpp
===================================================================
--- test/clang-tidy/modernize-loop-convert-extra.cpp
+++ test/clang-tidy/modernize-loop-convert-extra.cpp
@@ -605,4 +605,25 @@
}
}
+} // 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
Index: test/clang-tidy/Inputs/modernize-loop-convert/structures.h
===================================================================
--- test/clang-tidy/Inputs/modernize-loop-convert/structures.h
+++ test/clang-tidy/Inputs/modernize-loop-convert/structures.h
@@ -176,4 +176,15 @@
iterator begin() const;
iterator end() const;
};
+
+namespace Macros {
+
+struct MacroStruct {
+ int arr[10];
+};
+static MacroStruct *MacroSt;
+#define CONT MacroSt->
+
+} // namespace Macros
+
#endif // STRUCTURES_H
Index: clang-tidy/modernize/LoopConvertCheck.cpp
===================================================================
--- clang-tidy/modernize/LoopConvertCheck.cpp
+++ clang-tidy/modernize/LoopConvertCheck.cpp
@@ -337,8 +337,9 @@
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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12186.32688.patch
Type: text/x-patch
Size: 1928 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150820/748893b4/attachment.bin>
More information about the cfe-commits
mailing list