This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 108i. See for the official list.


1598. Criterion for equality of pointers to members

Section: 7.6.10  [expr.eq]     Status: C++14     Submitter: Richard Smith     Date: 2012-12-21

[Moved to DR at the February, 2014 meeting.]

According to 7.6.10 [expr.eq] paragraph 2, pointers to data members compare equal

if and only if they would refer to the same member of the same most derived object (6.7.2 [intro.object]) or the same subobject if indirection with a hypothetical object of the associated class type were performed.

This specification is overly constrained. For data members, most implementations simply compare the offsets of the members involved, violating the “only if” part of the specification. For example:

  struct A {};
  struct B : A { int x; };
  struct C : A { int x; };

  int A::*bx = (int(A::*))&B::x;
  int A::*cx = (int(A::*))&C::x;

  bool b1 = bx == cx;

The existing wording requires b1 to have the value false, even though the offsets of the members are the same. It would be better if the result of the comparison were unspecified unless the class containing the original member for the LHS is a base or derived class of the class containing the original member for the RHS.

Proposed resolution (January, 2014):

Change 7.6.10 [expr.eq] paragraph 3 as follows:

...Comparing pointers to members is defined as follows: