https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106865
--- Comment #2 from cqwrteur <unlvsur at live dot com> --- template<typename T> inline constexpr T add_carry(T a,T b,T carryin,T& carryout) noexcept { a+=b; carryout=a<b; a+=carryin; carryout+=a<carryin; return a; } template<typename T> inline constexpr T sub_carry(T a,T b,T carryin,T& carryout) noexcept { a-=b; carryout=b<a; a-=carryin; carryout+=carryin<a; return a; } https://godbolt.org/z/ETnzKxGGd This pattern is even better. It generates identical code with clang's builtin. The only problem is that it does not work on archs that provide carry flags.