Author: Congcong Cai Date: 2025-03-28T06:21:15+08:00 New Revision: 01e505b9922485514d4e1f9a26c390d0e7a71bf4
URL: https://github.com/llvm/llvm-project/commit/01e505b9922485514d4e1f9a26c390d0e7a71bf4 DIFF: https://github.com/llvm/llvm-project/commit/01e505b9922485514d4e1f9a26c390d0e7a71bf4.diff LOG: [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. Added: Modified: clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp index 50e6722badf50..697398a54332d 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::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( diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index aa85105918ecf..7bbf2190ee262 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -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 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 4cf78aeef5bd4..a80e1e1af1870 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 @@ 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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits