[libcxx-commits] [libcxx] [libc++] Move math special functions under __cmath (PR #213944)

via libcxx-commits libcxx-commits at lists.llvm.org
Tue Aug 4 07:26:56 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: Louis Dionne (ldionne)

<details>
<summary>Changes</summary>

It was always a bit weird that these were the only functions under __math/ which were not in the __math namespace and were not in the global namespace. This also led to a workaround in the C++20 modules testing.

Instead, move math special functions under __cmath/, which will contain APIs that are part of `<cmath>` but not `<math.h>`.

---
Full diff: https://github.com/llvm/llvm-project/pull/213944.diff


5 Files Affected:

- (modified) libcxx/include/CMakeLists.txt (+1-1) 
- (renamed) libcxx/include/__cmath/special_functions.h (+3-3) 
- (modified) libcxx/include/cmath (+1-1) 
- (modified) libcxx/include/module.modulemap.in (+4-1) 
- (modified) libcxx/utils/libcxx/test/modules.py (-7) 


``````````diff
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index dc1d8bb26bac4..9f880bb281663 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -294,6 +294,7 @@ set(files
   __chrono/year_month_day.h
   __chrono/year_month_weekday.h
   __chrono/zoned_time.h
+  __cmath/special_functions.h
   __compare/common_comparison_category.h
   __compare/compare_partial_order_fallback.h
   __compare/compare_strong_order_fallback.h
@@ -581,7 +582,6 @@ set(files
   __math/remainder.h
   __math/roots.h
   __math/rounding_functions.h
-  __math/special_functions.h
   __math/traits.h
   __math/trigonometric_functions.h
   __mbstate_t.h
diff --git a/libcxx/include/__math/special_functions.h b/libcxx/include/__cmath/special_functions.h
similarity index 95%
rename from libcxx/include/__math/special_functions.h
rename to libcxx/include/__cmath/special_functions.h
index 64d16aa88d2ee..070272a2886c9 100644
--- a/libcxx/include/__math/special_functions.h
+++ b/libcxx/include/__cmath/special_functions.h
@@ -7,8 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _LIBCPP___MATH_SPECIAL_FUNCTIONS_H
-#define _LIBCPP___MATH_SPECIAL_FUNCTIONS_H
+#ifndef _LIBCPP___CMATH_SPECIAL_FUNCTIONS_H
+#define _LIBCPP___CMATH_SPECIAL_FUNCTIONS_H
 
 #include <__config>
 #include <__math/copysign.h>
@@ -81,4 +81,4 @@ _LIBCPP_END_NAMESPACE_STD
 
 #endif // _LIBCPP_STD_VER >= 17
 
-#endif // _LIBCPP___MATH_SPECIAL_FUNCTIONS_H
+#endif // _LIBCPP___CMATH_SPECIAL_FUNCTIONS_H
diff --git a/libcxx/include/cmath b/libcxx/include/cmath
index bf87509b30fdc..a4139fb8181f8 100644
--- a/libcxx/include/cmath
+++ b/libcxx/include/cmath
@@ -323,7 +323,7 @@ constexpr long double lerp(long double a, long double b, long double t) noexcept
 #  include <__type_traits/promote.h>
 #  include <version>
 
-#  include <__math/special_functions.h>
+#  include <__cmath/special_functions.h>
 #  include <math.h>
 
 #  ifndef _LIBCPP_MATH_H
diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in
index f56d48784737b..6c0879297372e 100644
--- a/libcxx/include/module.modulemap.in
+++ b/libcxx/include/module.modulemap.in
@@ -19,6 +19,10 @@ module std_config {
 }
 
 module std_core {
+  module cmath {
+    module special_functions { header "__cmath/special_functions.h" }
+  }
+
   module cstddef {
     module byte         { header "__cstddef/byte.h" }
     module max_align_t  {
@@ -65,7 +69,6 @@ module std_core {
     module remainder                        { header "__math/remainder.h" }
     module roots                            { header "__math/roots.h" }
     module rounding_functions               { header "__math/rounding_functions.h" }
-    module special_functions                { header "__math/special_functions.h" }
     module traits                           { header "__math/traits.h" }
     module trigonometric_functions          { header "__math/trigonometric_functions.h" }
   }
diff --git a/libcxx/utils/libcxx/test/modules.py b/libcxx/utils/libcxx/test/modules.py
index 4aff04864e2d1..c6563de6b293d 100644
--- a/libcxx/utils/libcxx/test/modules.py
+++ b/libcxx/utils/libcxx/test/modules.py
@@ -68,13 +68,6 @@
 # This declaration is in the ostream header.
 ExtraDeclarations["system_error"] = ["std::operator<<"]
 
-# TODO MODULES avoid this work-around
-# This is a work-around for the special math functions. They are declared in
-# __math/special_functions.h. Adding this as an ExtraHeader works for the std
-# module. However these functions are special; they are not available in the
-# global namespace.
-ExtraDeclarations["cmath"] = ["std::hermite", "std::hermitef", "std::hermitel"]
-
 ### ExtraHeader
 
 # Adds extra headers file to scan

``````````

</details>


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


More information about the libcxx-commits mailing list