[PATCH] D22069: clang-tidy modernize-loop-convert: preserve type of alias declaration (bug 28341)
Matthias Gehre via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 20 05:39:36 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL276111: clang-tidy modernize-loop-convert: preserve type of alias declaration (bug… (authored by mgehre).
Changed prior to commit:
https://reviews.llvm.org/D22069?vs=63400&id=64672#toc
Repository:
rL LLVM
https://reviews.llvm.org/D22069
Files:
clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp
Index: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -517,7 +517,17 @@
if (VarNameFromAlias) {
const auto *AliasVar = cast<VarDecl>(AliasDecl->getSingleDecl());
VarName = AliasVar->getName().str();
- AliasVarIsRef = AliasVar->getType()->isReferenceType();
+
+ // Use the type of the alias if it's not the same
+ QualType AliasVarType = AliasVar->getType();
+ assert(!AliasVarType.isNull() && "Type in VarDecl is null");
+ if (AliasVarType->isReferenceType()) {
+ AliasVarType = AliasVarType.getNonReferenceType();
+ AliasVarIsRef = true;
+ }
+ if (Descriptor.ElemType.isNull() ||
+ !Context->hasSameUnqualifiedType(AliasVarType, Descriptor.ElemType))
+ Descriptor.ElemType = AliasVarType;
// We keep along the entire DeclStmt to keep the correct range here.
SourceRange ReplaceRange = AliasDecl->getSourceRange();
Index: clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp
@@ -1060,3 +1060,15 @@
}
} // namespace InitLists
+
+void bug28341() {
+ char v[5];
+ for(int i = 0; i < 5; ++i) {
+ unsigned char value = v[i];
+ if (value > 127)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
+ // CHECK-FIXES: for(unsigned char value : v)
+ // CHECK-FIXES-NEXT: if (value > 127)
+ }
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22069.64672.patch
Type: text/x-patch
Size: 1783 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160720/31269f9d/attachment.bin>
More information about the cfe-commits
mailing list