[libcxx-commits] [libcxx] [libc++] Make all `__random/HEADER.h` depend on `<__math/FOO.h>` instead of `<cmath>` and use `__math::` namespace instead `std::` (PR #213084)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Jul 31 02:02:55 PDT 2026
Hana =?utf-8?q?Dusíková?= <hanicka at hanicka.net>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/213084 at github.com>
philnik777 wrote:
> IIRC the current flow is:
>
> 1. `<__math/foo.h>` implements `std::__math::foo`
>
> 2. `<math.h>` includes `<__math/foo.h>` and does `using std::__math::foo`
>
> 3. `<cmath>` includes `<math.h>` and does `namespace std { using ::foo; }`
>
>
> In other words, we _should_ already be bypassing the underlying system's C library `<math.h>`, unless I missed something.
We use the system's overloads for the `double` cases if they are provided, since we can't override them on GCC.
> Therefore, I don't fully understand this part of the PR description:
>
> > I have found some of `<random>` functionality depends on system's `math.h`
>
> My understanding is that this shouldn't be the case, but perhaps we're doing something wrong?
>
> Either way, I think it would make some sense to start using `__math::foo` from our internal code instead of `std::foo` since it allows using the granularized headers and removes any possibility of confusion about what's being used (via the complex include chain involving `<math.h>`). So overall, I like this, but if we do this then I'd like us to also be on the same page that we'd want to do the same transformation throughout the whole code base. I'm not asking that we actually make that change, just that we agree that would be the desired end state. CC @philnik777
Yes, we should use `__math` where applicable. IIRC the last time I tried this for `<random>` the issue was `lgamma_r`, but we've resolved that particular issue by now, so this should be fine.
https://github.com/llvm/llvm-project/pull/213084
More information about the libcxx-commits
mailing list