Skip to content

Commit e7f311c

Browse files
[clang-tidy]misc-const-correctness fix fake positive of function pointer
1 parent e8489c1 commit e7f311c

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ void ConstCorrectnessCheck::check(const MatchFinder::MatchResult &Result) {
249249
CheckValue();
250250
if (WarnPointersAsPointers) {
251251
if (const auto *PT = dyn_cast<PointerType>(VT)) {
252-
if (!PT->getPointeeType().isConstQualified())
252+
if (!PT->getPointeeType().isConstQualified() &&
253+
!PT->getPointeeType()->isFunctionType())
253254
CheckPointee();
254255
}
255256
if (const auto *AT = dyn_cast<ArrayType>(VT)) {

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,10 @@ Changes in existing checks
321321
- Improved :doc:`misc-header-include-cycle
322322
<clang-tidy/checks/misc/header-include-cycle>` check performance.
323323

324+
- Improved :doc:`misc-const-correctness
325+
<clang-tidy/checks/misc/const-correctness>` check by fixing false positives
326+
of function pointer.
327+
324328
- Improved :doc:`modernize-avoid-c-arrays
325329
<clang-tidy/checks/modernize/avoid-c-arrays>` to not diagnose array types
326330
which are part of an implicit instantiation of a template.

clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,7 @@ void ignore_const_alias() {
4848
p_local0 = &a[1];
4949
}
5050

51+
void function_pointer_basic() {
52+
void (*const fp)() = nullptr;
53+
fp();
54+
}

0 commit comments

Comments
 (0)