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

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Aug 4 06:37:20 PDT 2026


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

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>.

>From 49b5ad4610bc21de1c4659990eae4235466cd138 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Tue, 4 Aug 2026 09:35:27 -0400
Subject: [PATCH] [libc++] Move math special functions under __cmath

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>.
---
 libcxx/include/CMakeLists.txt                          | 2 +-
 libcxx/include/{__math => __cmath}/special_functions.h | 0
 libcxx/include/cmath                                   | 2 +-
 libcxx/include/module.modulemap.in                     | 5 ++++-
 libcxx/utils/libcxx/test/modules.py                    | 7 -------
 5 files changed, 6 insertions(+), 10 deletions(-)
 rename libcxx/include/{__math => __cmath}/special_functions.h (100%)

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 100%
rename from libcxx/include/__math/special_functions.h
rename to libcxx/include/__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



More information about the libcxx-commits mailing list