From e7f311cb790ae0adbe4999ae0211ba89fd24057d Mon Sep 17 00:00:00 2001 From: Changqing Jing Date: Mon, 6 Oct 2025 20:47:28 +0800 Subject: [PATCH 1/5] [clang-tidy]misc-const-correctness fix fake positive of function pointer --- clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp | 3 ++- clang-tools-extra/docs/ReleaseNotes.rst | 4 ++++ .../checkers/misc/const-correctness-pointer-as-pointers.cpp | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp index b93f3d6a5a13b..8c25e928667df 100644 --- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp @@ -249,7 +249,8 @@ void ConstCorrectnessCheck::check(const MatchFinder::MatchResult &Result) { CheckValue(); if (WarnPointersAsPointers) { if (const auto *PT = dyn_cast(VT)) { - if (!PT->getPointeeType().isConstQualified()) + if (!PT->getPointeeType().isConstQualified() && + !PT->getPointeeType()->isFunctionType()) CheckPointee(); } if (const auto *AT = dyn_cast(VT)) { diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 7e836a7114d50..512527abf608a 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -321,6 +321,10 @@ Changes in existing checks - Improved :doc:`misc-header-include-cycle ` check performance. +- Improved :doc:`misc-const-correctness + ` check by fixing false positives + of function pointer. + - Improved :doc:`modernize-avoid-c-arrays ` to not diagnose array types which are part of an implicit instantiation of a template. diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp index 2ef47266b02b0..c2c939b9ba32e 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp @@ -48,3 +48,7 @@ void ignore_const_alias() { p_local0 = &a[1]; } +void function_pointer_basic() { + void (*const fp)() = nullptr; + fp(); +} From 7f0b88494e2bc8b3c1a659c6941bde69b729067e Mon Sep 17 00:00:00 2001 From: Changqing Jing Date: Wed, 8 Oct 2025 09:33:28 +0800 Subject: [PATCH 2/5] Fix review --- clang-tools-extra/docs/ReleaseNotes.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 512527abf608a..a4a023021e2ce 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -318,13 +318,13 @@ Changes in existing checks - ``for`` loops are supported. -- Improved :doc:`misc-header-include-cycle - ` check performance. - - Improved :doc:`misc-const-correctness ` check by fixing false positives of function pointer. +- Improved :doc:`misc-header-include-cycle + ` check performance. + - Improved :doc:`modernize-avoid-c-arrays ` to not diagnose array types which are part of an implicit instantiation of a template. From 631496b57a18c321f8dd89b0bf009c051c9532cd Mon Sep 17 00:00:00 2001 From: Changqing Jing Date: Thu, 9 Oct 2025 10:03:07 +0800 Subject: [PATCH 3/5] Fix release note --- clang-tools-extra/docs/ReleaseNotes.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 6ba0cd746b035..f30728ac114d4 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -319,10 +319,9 @@ Changes in existing checks - ``for`` loops are supported. - Improved :doc:`misc-const-correctness - ` check by fixing false positives - of function pointer. ` check to avoid false - positives when pointers is tranferred to non-const references. + positives when pointers is tranferred to non-const references and check by fixing false positives + of function pointer. - Improved :doc:`misc-header-include-cycle ` check performance. From fa660307614a51de7409caac876196251d442002 Mon Sep 17 00:00:00 2001 From: Changqing Jing Date: Thu, 9 Oct 2025 10:21:16 +0800 Subject: [PATCH 4/5] Fix release note --- clang-tools-extra/docs/ReleaseNotes.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index f30728ac114d4..1781c5f6f13be 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -320,8 +320,8 @@ Changes in existing checks - Improved :doc:`misc-const-correctness ` check to avoid false - positives when pointers is tranferred to non-const references and check by fixing false positives - of function pointer. + positives when pointers is tranferred to non-const references + and check by fixing false positives of function pointer. - Improved :doc:`misc-header-include-cycle ` check performance. From 417daa2d4c41c88c5bb1f15d3f74a262d1d0540e Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Thu, 9 Oct 2025 10:36:52 +0800 Subject: [PATCH 5/5] Update clang-tools-extra/docs/ReleaseNotes.rst --- clang-tools-extra/docs/ReleaseNotes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 1781c5f6f13be..4aa127a0ea583 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -321,7 +321,7 @@ Changes in existing checks - Improved :doc:`misc-const-correctness ` check to avoid false positives when pointers is tranferred to non-const references - and check by fixing false positives of function pointer. + and avoid false positives of function pointer. - Improved :doc:`misc-header-include-cycle ` check performance.