https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101539

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
As for __builtin_is_corresponding_member, could be perhaps implemented as
varargs FE builtin and only check during folding it has exactly two arguments
that are pointer to data members with layout-compatible types and standard
layout structs.
For constexpr, especially if we can see unfolded PMR address which says which
FIELD_DECL it is implementing it shouldn't be hard, but it seems that it can't
be always folded at compile time, we can have cases where we need to decide at
runtime.
#include <type_traits>
struct A { int a; long long b; int c; int e; int d; };
struct B { int a; long long b; long long c; int d; };
bool
foo (int A::*x, int B::*y)
{
  return std::is_corresponding_member (x, y);
}
This should return true if called e.g. with &A::a, &B::a, but not with &A::d,
&B::d.  So I guess at compile time we need to check if the types (int in this
case twice) is layout-compatible and whether A and B are standard-layout
structure types, but then actually at compile time need to compare the
OFFSET_TYPEs for equality and compare it against pre-computed value of an upper
bound for the initial common sequence of the two types.
The U and V structs show that it is harder though, at least the offset would be
dependent on the type of the field.

No plans on my side to work on the pointer interconvertibility on my side.

Reply via email to