The following short program
#include <cstdint>
#include <utility>
#include <iostream>
int main() {
__int128 a = -1;
__int128 b = 1;
if (std::cmp_less(a, b)) {
std::cout << "less" << std::endl;
}
}
compiles if I use -std=gnu++2b
(or even -std=gnu++20
) but fails with -std=c++20
or -std=c++23
:
In file included from <source>:2:
/opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/utility: In instantiation of 'constexpr bool std::cmp_less(_Tp, _Up) [with _Tp = __int128; _Up = __int128]':
<source>:11:18: required from here
/opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/utility:141:49: error: static assertion failed
141 | static_assert(__is_standard_integer<_Tp>::value);
| ^~~~~
/opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/utility:141:49: note: 'std::integral_constant<bool, false>::value' evaluates to false
/opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/utility:142:49: error: static assertion failed
142 | static_assert(__is_standard_integer<_Up>::value);
| ^~~~~
/opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/utility:142:49: note: 'std::integral_constant<bool, false>::value' evaluates to false
Compiler returned: 1
Can someone shed some light why this happens?
__int128
is not a standard type, so when you're in strict standard mode (-std=c++20
) it won't work. The only suprise is that it doesn't give an error on the declarations ofa
andb
.You need to enable GNU extensions (with
-std=gnu++20
or similar) to make it work, as you have already discovered.