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) + } +}
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) + } +}
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits