Skip to content

Commit 5ae5af1

Browse files
authored
[clang-tidy][modernize-loop-convert]check isDependentSizedArrayType (#69062)
1 parent ab737a8 commit 5ae5af1

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ void LoopConvertCheck::doConversion(
753753
bool IsCheapToCopy =
754754
!Descriptor.ElemType.isNull() &&
755755
Descriptor.ElemType.isTriviallyCopyableType(*Context) &&
756+
!Descriptor.ElemType->isDependentSizedArrayType() &&
756757
// TypeInfo::Width is in bits.
757758
Context->getTypeInfo(Descriptor.ElemType).Width <= 8 * MaxCopySize;
758759
bool UseCopy = CanCopy && ((VarNameFromAlias && !AliasVarIsRef) ||

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ Changes in existing checks
271271

272272
- Improved :doc:`modernize-loop-convert
273273
<clang-tidy/checks/modernize/loop-convert>` to support for-loops with
274-
iterators initialized by free functions like ``begin``, ``end``, or ``size``.
274+
iterators initialized by free functions like ``begin``, ``end``, or ``size``
275+
and avoid crash for array of dependent array.
275276

276277
- Improved :doc:`modernize-return-braced-init-list
277278
<clang-tidy/checks/modernize/return-braced-init-list>` check to ignore

clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,4 +939,18 @@ void fundamentalTypesTest() {
939939
// CHECK-FIXES: for (double Double : Doubles)
940940
}
941941

942+
template <unsigned p> void _dependenceArrayTest() {
943+
unsigned test[3][p];
944+
for (unsigned i = 0; i < p; ++i)
945+
for (unsigned j = 0; j < 3; ++j)
946+
printf("%d", test[j][i]);
947+
// CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use range-based for loop instead
948+
// CHECK-FIXES: (auto & j : test)
949+
// CHECK-FIXES: printf("%d", j[i]);
950+
}
951+
void dependenceArrayTest() {
952+
_dependenceArrayTest<1>();
953+
_dependenceArrayTest<2>();
954+
}
955+
942956
} // namespace PseudoArray

0 commit comments

Comments
 (0)