I'm using __builtin_expect
to perform a null pointer check in a constexpr function like so:
constexpr int Add(const int * x, const int * y)
{
assert(__builtin_expect(!!(x && y), 1));
return *x + *y;
}
I also have a wrapper method for const refs to allow for passing temporaries:
constexpr int Add(const int & x, const int & y)
{
return Add(&x, &y);
}
I then create a global constant using temporaries:
static constexpr int result = Add(1, 2);
Printing this value results in 0
:
int main() {
std::cout << result; // 0
}
What exactly is going on here?
Removal of __builtin_expect
fails to compile with GCC complaining about pointer comparisons to temporaries inside constexpr context maybe related.