[libcxx-commits] [libcxx] [libc++] Fix hypotf linker error with Clang modules on Windows UCRT (PR #209403)

Takuto Ikuta via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jul 14 01:49:57 PDT 2026


================
@@ -27,19 +27,35 @@
 _LIBCPP_PUSH_MACROS
 #include <__undef_macros>
 
+#if defined(_LIBCPP_MSVCRT)
+extern "C" {
+_LIBCPP_CRT_FUNC float __cdecl _hypotf(float, float);
+}
+#endif
+
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace __math {
 
-inline _LIBCPP_HIDE_FROM_ABI float hypot(float __x, float __y) _NOEXCEPT { return __builtin_hypotf(__x, __y); }
+inline _LIBCPP_HIDE_FROM_ABI float hypot(float __x, float __y) _NOEXCEPT {
+#if defined(_LIBCPP_MSVCRT)
+  return ::_hypotf(__x, __y);
+#else
+  return __builtin_hypotf(__x, __y);
+#endif
+}
 
 template <class = int>
 _LIBCPP_HIDE_FROM_ABI double hypot(double __x, double __y) _NOEXCEPT {
   return __builtin_hypot(__x, __y);
 }
 
 inline _LIBCPP_HIDE_FROM_ABI long double hypot(long double __x, long double __y) _NOEXCEPT {
+#if defined(_LIBCPP_MSVCRT)
+  return (long double)__math::hypot((double)__x, (double)__y);
----------------
atetubou wrote:

Can we use `static_cast` here?
https://llvm.org/docs/CodingStandards.html#prefer-c-style-casts

https://github.com/llvm/llvm-project/pull/209403


More information about the libcxx-commits mailing list