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(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) + } +}