[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.
diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index 50e6722..697398a 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -81,10 +81,10 @@
}
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(
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index aa85105..7bbf219 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -146,7 +146,8 @@
`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
diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
index 4cf78ae..a80e1e1 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
@@ -1007,3 +1007,11 @@
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