From 5f2389d49fef36ed2e97dcc6b54036542c160a36 Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Tue, 27 Aug 2024 16:46:03 -0500 Subject: [PATCH] [libc++] Do not redeclare lgamma_r when targeting the LLVM C library (#102036) We use lgamma_r for the random normal distribution support. In this code we redeclare it, which causes issues with the LLVM C library as this function is marked noexcept in LLVM libc. This patch ensures that we don't redeclare that function when targeting LLVM libc. --- libcxx/include/__configuration/platform.h | 9 ++++++--- libcxx/include/__random/binomial_distribution.h | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/libcxx/include/__configuration/platform.h b/libcxx/include/__configuration/platform.h index 27f68d04e8a8..2a92ce209b91 100644 --- a/libcxx/include/__configuration/platform.h +++ b/libcxx/include/__configuration/platform.h @@ -30,15 +30,18 @@ // ... add new file formats here ... #endif -// Need to detect which libc we're using if we're on Linux. -#if defined(__linux__) +// To detect which libc we're using +#if __has_include() # include +#endif + +#if defined(__linux__) # if defined(__GLIBC_PREREQ) # define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b) # else # define _LIBCPP_GLIBC_PREREQ(a, b) 0 # endif // defined(__GLIBC_PREREQ) -#endif // defined(__linux__) +#endif #ifndef __BYTE_ORDER__ # error \ diff --git a/libcxx/include/__random/binomial_distribution.h b/libcxx/include/__random/binomial_distribution.h index e8774bb8d67e..3f19746bae23 100644 --- a/libcxx/include/__random/binomial_distribution.h +++ b/libcxx/include/__random/binomial_distribution.h @@ -97,7 +97,8 @@ public: } }; -#ifndef _LIBCPP_MSVCRT_LIKE +// The LLVM C library provides this with conflicting `noexcept` attributes. +#if !defined(_LIBCPP_MSVCRT_LIKE) && !defined(__LLVM_LIBC__) extern "C" double lgamma_r(double, int*); #endif