https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71962
--- Comment #22 from Nana Sakisaka <aroma.slope.seven at gmail dot com> ---
This may look a bit hacky, but here is a temporary workaround that can be
applied on the user side:
[[nodiscard]] constexpr bool is_same_address(void const* a, void const* b)
noexcept
{
#if defined(__GNUC__) && !defined(__clang__)
if consteval {
return __builtin_constant_p(a == b) ? a == b : false;
}
#endif
return a == b;
}
With -fno-delete-null-pointer-checks (implied by -fsanitize=undefined), GCC
refuses to fold a comparison between the addresses of two distinct variables in
a constant evaluation, but it still folds the comparison of an address with
itself.
A comparison that does not fold is therefore between two distinct objects, so
it can be treated as false.