diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp index f90d99a8d6606..8beaa62c78ba0 100644 --- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp @@ -753,6 +753,7 @@ void LoopConvertCheck::doConversion( bool IsCheapToCopy = !Descriptor.ElemType.isNull() && Descriptor.ElemType.isTriviallyCopyableType(*Context) && + !Descriptor.ElemType->isDependentSizedArrayType() && // TypeInfo::Width is in bits. Context->getTypeInfo(Descriptor.ElemType).Width <= 8 * MaxCopySize; bool UseCopy = CanCopy && ((VarNameFromAlias && !AliasVarIsRef) || diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index c732d4904df13..af164d0462d52 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -271,7 +271,8 @@ Changes in existing checks - Improved :doc:`modernize-loop-convert ` to support for-loops with - iterators initialized by free functions like ``begin``, ``end``, or ``size``. + iterators initialized by free functions like ``begin``, ``end``, or ``size`` + and avoid crash for array of dependent array. - Improved :doc:`modernize-return-braced-init-list ` check to ignore diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp index 71ae4c46e6a5e..e2b9336d620f5 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp @@ -939,4 +939,18 @@ void fundamentalTypesTest() { // CHECK-FIXES: for (double Double : Doubles) } +template void _dependenceArrayTest() { + unsigned test[3][p]; + for (unsigned i = 0; i < p; ++i) + for (unsigned j = 0; j < 3; ++j) + printf("%d", test[j][i]); + // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use range-based for loop instead + // CHECK-FIXES: (auto & j : test) + // CHECK-FIXES: printf("%d", j[i]); +} +void dependenceArrayTest() { + _dependenceArrayTest<1>(); + _dependenceArrayTest<2>(); +} + } // namespace PseudoArray