| Issue |
176776
|
| Summary |
std::nextafter, etc should be constexpr in C++23 mode
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
amluto
|
cppreference.com informs me that `std::nextafter` and its relatives are specified to be `constexpr`, and N4950 [cmath.syn] agrees, but clang does not implement them as such:
#include <cmath>
```c++
#include <cmath>
int main()
{
constexpr double cppstyle = std::nextafter(73.0, 0.0);
constexpr double builtinstyle = __builtin_nextafterl(73.0, 0.0);
(void)cppstyle;
(void)builtinstyle;
return 0;
}
```
clang trunk says:
```
<source>:5:22: error: constexpr variable 'cppstyle' must be initialized by a constant _expression_
5 | constexpr double cppstyle = std::nextafter(73.0, 0.0);
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:5:33: note: non-constexpr function 'nextafter' cannot be used in a constant _expression_
5 | constexpr double cppstyle = std::nextafter(73.0, 0.0);
| ^
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:262:13: note: declared here
262 | __MATHCALL (nextafter,, (_Mdouble_ __x, _Mdouble_ __y));
| ^
<source>:6:37: error: constexpr variable 'builtinstyle' must be initialized by a constant _expression_
6 | constexpr double builtinstyle = __builtin_nextafterl(73.0, 0.0);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.
```
Any recent gcc version compiles this code successfully, even in modes earlier than C++23. Looking at the libstdc++ header, `nextafter` is implemented interms of `__builtin_nextafterl` etc, so the correct fix is presumably to improve `__builtin_nextafterl` etc.
Fixing this seems likely to fix #74368 as well.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs