Index: clang-tidy/modernize/LoopConvertCheck.cpp =================================================================== --- clang-tidy/modernize/LoopConvertCheck.cpp +++ clang-tidy/modernize/LoopConvertCheck.cpp @@ -517,6 +517,15 @@ if (VarNameFromAlias) { const auto *AliasVar = cast(AliasDecl->getSingleDecl()); VarName = AliasVar->getName().str(); + + // Use the type of the alias if it's not the same + QualType DeclarationType = AliasVar->getType(); + if (!DeclarationType.isNull() && DeclarationType->isReferenceType()) + DeclarationType = DeclarationType.getNonReferenceType(); + if (Descriptor.ElemType.isNull() || DeclarationType.isNull() || + !Context->hasSameUnqualifiedType(DeclarationType, Descriptor.ElemType)) + Descriptor.ElemType = AliasVar->getType(); + AliasVarIsRef = AliasVar->getType()->isReferenceType(); // We keep along the entire DeclStmt to keep the correct range here. 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 @@ -1060,3 +1060,15 @@ } } // namespace InitLists + +void bug28341() { + char v[5]; + for(int i = 0; i < 5; ++i) { + unsigned char value = v[i]; + // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead + // CHECK-FIXES: for(unsigned char value : v) + // CHECK-FIXES-NOT: unsigned char value = v[i]; + if (value > 127) + ; + } +}