core.builtins: Fix return value of likely/unlikely

For both GCC and LLVM, `__builtin_expect` and `llvm_expect` respectively
return an integer, not a boolean. This triggers a compiler error as
implicit narrow conversions are not allowed.
This commit is contained in:
Iain Buclaw 2025-01-10 23:17:04 +01:00 committed by Nicholas Wilson
parent 12d4f3e4d6
commit 126064282f

View file

@ -94,9 +94,9 @@ else version (DigitalMars)
/// Provide static branch and value hints for the LDC/GDC compilers. /// Provide static branch and value hints for the LDC/GDC compilers.
/// DMD ignores these hints. /// DMD ignores these hints.
pragma(inline, true) bool likely()(bool b) { return expect(b, true); } pragma(inline, true) bool likely()(bool b) { return !!expect(b, true); }
/// ditto /// ditto
pragma(inline, true) bool unlikely()(bool b) { return expect(b, false); } pragma(inline, true) bool unlikely()(bool b) { return !!expect(b, false); }
/// ///
@nogc nothrow pure @safe unittest @nogc nothrow pure @safe unittest