[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.
This commit is contained in:
Congcong Cai 2025-03-28 06:21:15 +08:00 committed by GitHub
parent 52975d5c9f
commit 01e505b992
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 5 deletions

View File

@ -81,10 +81,10 @@ void ConstCorrectnessCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
}
void ConstCorrectnessCheck::registerMatchers(MatchFinder *Finder) {
const auto ConstType = hasType(
qualType(isConstQualified(),
// pointee check will check the const pointer and const array
unless(pointerType()), unless(arrayType())));
const auto ConstType =
hasType(qualType(isConstQualified(),
// pointee check will check the constness of pointer
unless(pointerType())));
const auto ConstReference = hasType(references(isConstQualified()));
const auto RValueReference = hasType(

View File

@ -146,7 +146,8 @@ Changes in existing checks
`AllowedTypes`, that excludes specified types from const-correctness
checking and fixing false positives when modifying variant by ``operator[]``
with template in parameters and supporting to check pointee mutation by
`AnalyzePointers` option.
`AnalyzePointers` option and fixing false positives when using const array
type.
- Improved :doc:`misc-redundant-expression
<clang-tidy/checks/misc/redundant-expression>` check by providing additional

View File

@ -1007,3 +1007,11 @@ template <typename T> void f() {
x[T{}] = 3;
}
} // namespace gh127776_false_positive
namespace gh132931_false_positive {
using T = const int;
void valid(int i) {
const int arr0[] = {1, 2, 3};
T arr1[] = {1, 2, 3};
}
} // namespace gh132931_false_positive