https://github.com/bassiounix created 
https://github.com/llvm/llvm-project/pull/224690

Now that __builtin_exp and __builtin_expf are constant-evaluable in
clang (#199808), mark libc++'s float, double, and integral-promoting
overloads of __math::exp as _LIBCPP_CONSTEXPR_SINCE_CXX23. The long
double overload stays non-constexpr because __builtin_expl is not
constant-evaluable yet.

Add constexpr coverage for std::exp and std::expf to the clang-specific
constexpr <cmath> test.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

---

<sub>Stack created with <a href="https://github.com/github/gh-stack";>GitHub 
Stacks CLI</a> • <a href="https://gh.io/stacks-feedback";>Give Feedback 
💬</a></sub>

>From 34a4380f2a3984642032c4de9e51d605dbc38654 Mon Sep 17 00:00:00 2001
From: bassiounix <[email protected]>
Date: Fri, 18 Sep 2026 20:18:25 +0300
Subject: [PATCH] [libc++] Make std::exp constexpr for float and double since
 C++23

Now that __builtin_exp and __builtin_expf are constant-evaluable in
clang (#199808), mark libc++'s float, double, and integral-promoting
overloads of __math::exp as _LIBCPP_CONSTEXPR_SINCE_CXX23. The long
double overload stays non-constexpr because __builtin_expl is not
constant-evaluable yet.

Add constexpr coverage for std::exp and std::expf to the clang-specific
constexpr <cmath> test.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
---
 libcxx/include/__math/exponential_functions.h             | 8 +++++---
 .../libcxx/numerics/c.math/constexpr-cxx23-clang.pass.cpp | 4 ++++
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/libcxx/include/__math/exponential_functions.h 
b/libcxx/include/__math/exponential_functions.h
index 09930b7819e23..1da3cfa2ea38d 100644
--- a/libcxx/include/__math/exponential_functions.h
+++ b/libcxx/include/__math/exponential_functions.h
@@ -26,17 +26,19 @@ namespace __math {
 
 // exp
 
-inline _LIBCPP_HIDE_FROM_ABI float exp(float __x) _NOEXCEPT { return 
__builtin_expf(__x); }
+inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI float exp(float 
__x) _NOEXCEPT {
+  return __builtin_expf(__x);
+}
 
 template <class = int>
-_LIBCPP_HIDE_FROM_ABI double exp(double __x) _NOEXCEPT {
+_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI double exp(double __x) 
_NOEXCEPT {
   return __builtin_exp(__x);
 }
 
 inline _LIBCPP_HIDE_FROM_ABI long double exp(long double __x) _NOEXCEPT { 
return __builtin_expl(__x); }
 
 template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
-inline _LIBCPP_HIDE_FROM_ABI double exp(_A1 __x) _NOEXCEPT {
+inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI double exp(_A1 __x) 
_NOEXCEPT {
   return __builtin_exp((double)__x);
 }
 
diff --git a/libcxx/test/libcxx/numerics/c.math/constexpr-cxx23-clang.pass.cpp 
b/libcxx/test/libcxx/numerics/c.math/constexpr-cxx23-clang.pass.cpp
index beca4907284ad..b9e0afab6349e 100644
--- a/libcxx/test/libcxx/numerics/c.math/constexpr-cxx23-clang.pass.cpp
+++ b/libcxx/test/libcxx/numerics/c.math/constexpr-cxx23-clang.pass.cpp
@@ -207,6 +207,10 @@ int main(int, char**) {
   ASSERT_CONSTEXPR_CXX23(std::fpclassify(-1.0) == FP_NORMAL);
   ASSERT_CONSTEXPR_CXX23(std::fpclassify(-1.0L) == FP_NORMAL);
 
+  ASSERT_CONSTEXPR_CXX23(std::exp(0.0f) == 1.0f);
+  ASSERT_CONSTEXPR_CXX23(std::exp(0.0) == 1.0);
+  ASSERT_CONSTEXPR_CXX23(std::expf(0.0f) == 1.0f);
+
   ASSERT_CONSTEXPR_CXX23(std::isfinite(-1.0f) == 1);
   ASSERT_CONSTEXPR_CXX23(std::isfinite(-1.0) == 1);
   ASSERT_CONSTEXPR_CXX23(std::isfinite(-1.0L) == 1);

_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
  • [llvm-branch-commits] [libcxx] ... Muhammad Bassiouni via llvm-branch-commits

Reply via email to