[libcxx-commits] [libcxx] [libc++][math] Add `constexpr` to `copysign`, `copysignf`, `copysignl` (PR #216285)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Sep 8 08:49:50 PDT 2026
philnik777 wrote:
> > I feel like this ignores the fact that the functions here are `constexpr` according to the standard now? We don't need to make them constexpr in all language modes, but we should in the language modes where it's required by the standard.
>
> Yes, because these are C interfaces. Our library builtins are tied to a particular header, so would the constexpr interfaces in C++ be the ones coming from the `<cfoo>` headers and not the `<foo.h>` headers? And would we treat `copysign` differently than `std::copysign`? Or would we not care about which header or spelling was used and make any of them constexpr in all language modes?
AFAIK they're all required to be `constexpr` since C++ 20(?). The `std::` versions are just aliases to `::`, so they're already recognized as the same builtin function.
> (I should be clear: I'm not say we should not go down this route, I'm saying it needs an RFC because there's a fair number of moving parts and we need a description of the design if we're talking about the builtin machinery.)
Sure. FWIW I'm pretty sure the only thing we need is for Clang to accept the current math builtins during constant evaluation in C++20 and from there we can implement the papers.
> > > it can break conforming code given that C++ makes it possible to observe whether something is or is not a constant expression
> >
> >
> > How, actually?
>
> Cribbed from code written by @zygoloid: https://godbolt.org/z/r3n5Ya1ds This was discussed in relation to making `strlen` be constexpr as part of r148374 in 2012.
This is indeed some black magic. Though it's UB since C++20 if applied to a `std::` function, since it takes the address of a function. No idea whether that's fundamentally required, but it probably makes it harder.
https://github.com/llvm/llvm-project/pull/216285
More information about the libcxx-commits
mailing list