[clang-tools-extra] [clang-tidy] Add misc-function-pointer-equality lint (PR #239430)
Jordan R AW via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 3 10:52:15 PST 2026
================
@@ -0,0 +1,24 @@
+// RUN: %check_clang_tidy -std=c++11-or-later %s misc-function-pointer-equality %t -- \
+// RUN: -config='{CheckOptions: { misc-function-pointer-equality.KeyedContainerTypes: "::std::MyCustomContainer" }}'
+
+#include <set>
+
+void f();
+
+namespace std
+{
+template<typename T>
+class MyCustomContainer {
+public:
+ MyCustomContainer(T myVal): val(myVal) {};
+ T val;
+};
+}
+
+void test_custom_container() {
+ std::MyCustomContainer<void (*)()> a(&f);
+ // CHECK-MESSAGES: :[[@LINE-1]]:38: warning: associative or unordered container 'a' with a function pointer key type is unsound with '--icf=all' enabled [misc-function-pointer-equality]
----------------
ajordanr-google wrote:
Would "introducing miscompiles" be sufficient? It's not UB (it's well defined to be against the spec), and it won't (always) lead to crashes. It will instead miscompile. In general, it may be that simply the code no longer does what it says it does. Inlining optimisations and Indirect Function Call Promotion can lead to issues such as dropping nullptr checks leading to segfaults, which is what we saw in Android.
https://github.com/llvm/llvm-project/pull/239430
More information about the cfe-commits
mailing list