Skip to content

Commit 99334f7

Browse files
[ADT] Add static_assert to llvm::to_address for function types (#166505)
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.
1 parent 0b5a00a commit 99334f7

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

llvm/include/llvm/ADT/STLForwardCompat.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ struct identity // NOLINT(readability-identifier-naming)
142142
/// The std::pointer_traits<>::to_address(p) variations of these overloads has
143143
/// not been implemented.
144144
template <class Ptr> auto to_address(const Ptr &P) { return P.operator->(); }
145-
template <class T> constexpr T *to_address(T *P) { return P; }
145+
template <class T> constexpr T *to_address(T *P) {
146+
static_assert(!std::is_function_v<T>);
147+
return P;
148+
}
146149

147150
//===----------------------------------------------------------------------===//
148151
// Features from C++23

0 commit comments

Comments
 (0)