[libcxx-commits] [libcxx] WIP [libc++][math] Add `constexpr` to `copysign`, `copysignf`, `copysignl` (PR #216285)
Richard Smith via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Sep 28 11:53:33 PDT 2026
zygoloid wrote:
[Addressing only the C++ side here; I don't know enough about the new C constexpr rules to comment.]
> 3. Diagnose the `foo` form in a constant expression evaluation context in C and C++ before C++26 as being a Clang (or GNU?) extension
How would you diagnose this? In particular, what would you do in a "trial evaluation" context, such as:
```c++
void f() {
const int n = fabs(1.0);
// do something that depends on whether `n` is usable in constant expressions
}
```
I think your options for this are either that we allow the evaluation (which is *not* a conforming extension) and either produce a warning (which is a false positive if `n` happens to not be required to be usable in constant expressions) or produce no warning (which would be an extension with no diagnostic), or that we disallow this extension during trial evaluations (which probably means disallowing it everywhere so our evaluation is self-consistent). I'm not seeing a good path through that which allows this as an extension ever.
This really doesn't seem to be a situation where we can provide a compatible, conforming extension.
I think our viable options are to either say this is the standard library's problem (libc++ and libstdc++ would need to ensure the functions are declared `constexpr` in the right cases, which libc++ could do via its "preferred overload" mechanism, but libstdc++ maybe couldn't and maybe wouldn't), or to implement the language rule ourselves, properly, including only making the libc functions `constexpr` in the cases where the language rules say they are.
(We already allow use of these non-prefixed functions during constant folding and only disallow them in standards-rule-following evaluation mode. That seems right to me, in the older C++ language modes where they are not `constexpr`.)
https://github.com/llvm/llvm-project/pull/216285
More information about the libcxx-commits
mailing list