[clang-tools-extra] [clang-tidy]misc-const-correctness fix fake positive of function pointer (PR #162079)
Changqing Jing via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 6 05:47:50 PDT 2025
https://github.com/Changqing-JING updated https://github.com/llvm/llvm-project/pull/162079
>From e7f311cb790ae0adbe4999ae0211ba89fd24057d Mon Sep 17 00:00:00 2001
From: Changqing Jing <changqing.jing at bmw.com>
Date: Mon, 6 Oct 2025 20:47:28 +0800
Subject: [PATCH] [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<PointerType>(VT)) {
- if (!PT->getPointeeType().isConstQualified())
+ if (!PT->getPointeeType().isConstQualified() &&
+ !PT->getPointeeType()->isFunctionType())
CheckPointee();
}
if (const auto *AT = dyn_cast<ArrayType>(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
<clang-tidy/checks/misc/header-include-cycle>` check performance.
+- Improved :doc:`misc-const-correctness
+ <clang-tidy/checks/misc/const-correctness>` check by fixing false positives
+ of function pointer.
+
- Improved :doc:`modernize-avoid-c-arrays
<clang-tidy/checks/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();
+}
More information about the cfe-commits
mailing list