[clang-tools-extra] 6504546 - [clang-tidy][use-internal-linkage] fix false positive for consteval function (#122141)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 10 00:24:27 PST 2025
Author: maflcko
Date: 2025-01-10T09:24:24+01:00
New Revision: 6504546abcd38159256c3030286b1c02b401c4f8
URL: https://github.com/llvm/llvm-project/commit/6504546abcd38159256c3030286b1c02b401c4f8
DIFF: https://github.com/llvm/llvm-project/commit/6504546abcd38159256c3030286b1c02b401c4f8.diff
LOG: [clang-tidy][use-internal-linkage] fix false positive for consteval function (#122141)
Fixes https://github.com/llvm/llvm-project/issues/122096
---------
Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_ at 721217.xyz>
Added:
clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-consteval.cpp
Modified:
clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
index 1e0f398a4a560b..4778182944abda 100644
--- a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
@@ -125,7 +125,7 @@ void UseInternalLinkageCheck::registerMatchers(MatchFinder *Finder) {
exportDecl()))))));
Finder->addMatcher(
functionDecl(Common, hasBody(),
- unless(anyOf(cxxMethodDecl(),
+ unless(anyOf(cxxMethodDecl(), isConsteval(),
isAllocationOrDeallocationOverloadedFunction(),
isMain())))
.bind("fn"),
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 19c59f5b32eed1..1a7d48a0b4dc7e 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -286,9 +286,9 @@ Changes in existing checks
- Improved :doc:`misc-use-internal-linkage
<clang-tidy/checks/misc/use-internal-linkage>` check to insert ``static``
- keyword before type qualifiers such as ``const`` and ``volatile`` and fix
- false positives for function declaration without body and fix false positives
- for C++20 export declarations and fix false positives for global scoped
+ keyword before type qualifiers such as ``const`` and ``volatile``. Also, fix
+ false positives for function declaration without body, C++20 consteval
+ functions, C++20 export declarations, and global scoped
overloaded ``operator new`` and ``operator delete``.
- Improved :doc:`modernize-avoid-c-arrays
diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-consteval.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-consteval.cpp
new file mode 100644
index 00000000000000..62c9818e07c4f2
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-consteval.cpp
@@ -0,0 +1,7 @@
+// RUN: %check_clang_tidy -std=c++20 %s misc-use-internal-linkage %t -- -- -I%S/Inputs/use-internal-linkage
+
+consteval void gh122096() {}
+
+constexpr void cxf() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: function 'cxf'
+// CHECK-FIXES: static constexpr void cxf() {}
More information about the cfe-commits
mailing list