__attribute__((noreturn)) extern void bar();
int test_no_warn(int x) {
if (x) {
if (__builtin_expect_with_probability(1, 1, 1))
bar();
} else {
return 0;
}
}
template <int b> void tempf() {
static_assert(b == 1, "should be evaluated as 1"); }
constexpr int constf() {
return __builtin_expect_with_probability(1, 1, 1);
}
void foo() {
tempf<__builtin_expect_with_probability(1, 1, 1)>();
constexpr int f = constf();
static_assert(f == 1, "should be evaluated as 1"); }
extern int global;
struct S {
static constexpr float prob = 0.7;
};
template<typename T>
void expect_taken(int x) {
if (__builtin_expect_with_probability(x > 0, 1, T::prob)) {
global++;
}
}
void test(int x, double p) { bool dummy;
dummy = __builtin_expect_with_probability(x > 0, 1, 0.9);
dummy = __builtin_expect_with_probability(x > 0, 1, 1.1); dummy = __builtin_expect_with_probability(x > 0, 1, -1); dummy = __builtin_expect_with_probability(x > 0, 1, p); dummy = __builtin_expect_with_probability(x > 0, 1, "aa"); dummy = __builtin_expect_with_probability(x > 0, 1, __builtin_nan("")); dummy = __builtin_expect_with_probability(x > 0, 1, __builtin_inf()); dummy = __builtin_expect_with_probability(x > 0, 1, -0.0);
dummy = __builtin_expect_with_probability(x > 0, 1, 1.0 + __DBL_EPSILON__); dummy = __builtin_expect_with_probability(x > 0, 1, -__DBL_DENORM_MIN__); constexpr double pd = 0.7;
dummy = __builtin_expect_with_probability(x > 0, 1, pd);
constexpr int pi = 1;
dummy = __builtin_expect_with_probability(x > 0, 1, pi);
expect_taken<S>(x);
}