Skip to content

Commit 01e505b

Browse files
authored
[clang-tidy][misc-const-correctness] fix fp when using const array type. (#133018)
Fixed: #132931 const array is immutable in C/C++ language design, we don't need to check constness for it.
1 parent 52975d5 commit 01e505b

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ void ConstCorrectnessCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
8181
}
8282

8383
void ConstCorrectnessCheck::registerMatchers(MatchFinder *Finder) {
84-
const auto ConstType = hasType(
85-
qualType(isConstQualified(),
86-
// pointee check will check the const pointer and const array
87-
unless(pointerType()), unless(arrayType())));
84+
const auto ConstType =
85+
hasType(qualType(isConstQualified(),
86+
// pointee check will check the constness of pointer
87+
unless(pointerType())));
8888

8989
const auto ConstReference = hasType(references(isConstQualified()));
9090
const auto RValueReference = hasType(

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ Changes in existing checks
146146
`AllowedTypes`, that excludes specified types from const-correctness
147147
checking and fixing false positives when modifying variant by ``operator[]``
148148
with template in parameters and supporting to check pointee mutation by
149-
`AnalyzePointers` option.
149+
`AnalyzePointers` option and fixing false positives when using const array
150+
type.
150151

151152
- Improved :doc:`misc-redundant-expression
152153
<clang-tidy/checks/misc/redundant-expression>` check by providing additional

clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,3 +1007,11 @@ template <typename T> void f() {
10071007
x[T{}] = 3;
10081008
}
10091009
} // namespace gh127776_false_positive
1010+
1011+
namespace gh132931_false_positive {
1012+
using T = const int;
1013+
void valid(int i) {
1014+
const int arr0[] = {1, 2, 3};
1015+
T arr1[] = {1, 2, 3};
1016+
}
1017+
} // namespace gh132931_false_positive

0 commit comments

Comments
 (0)