From ff692f12b3ae6d98d010662554c04a1832c60dc1 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Tue, 4 Nov 2025 12:39:21 -0800 Subject: [PATCH] [ADT] Add static_assert to llvm::to_address for function types This patch aligns llvm::to_address with C++20 std::to_address by adding a static_assert to prevent instantiation with function types. The C++20 standard says that std::to_address is ill-formed on a function type. --- llvm/include/llvm/ADT/STLForwardCompat.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/ADT/STLForwardCompat.h b/llvm/include/llvm/ADT/STLForwardCompat.h index ad94cdede9288..b975a403cd042 100644 --- a/llvm/include/llvm/ADT/STLForwardCompat.h +++ b/llvm/include/llvm/ADT/STLForwardCompat.h @@ -142,7 +142,10 @@ struct identity // NOLINT(readability-identifier-naming) /// The std::pointer_traits<>::to_address(p) variations of these overloads has /// not been implemented. template auto to_address(const Ptr &P) { return P.operator->(); } -template constexpr T *to_address(T *P) { return P; } +template constexpr T *to_address(T *P) { + static_assert(!std::is_function_v); + return P; +} //===----------------------------------------------------------------------===// // Features from C++23