Accessing ambiguous subobjects
Section [expr.ref]
Davis Herring

Created on 2023-02-11.00:00:00 last changed 2 weeks ago


Date: 2023-03-11.18:07:02

Suggested resolution:

Change 11.8.3 [class.access.base] paragraph 6 to actually perform the conversion it requires, possibly moving it to [expr.ref] since it is not about access control; the definition of "naming class" in 11.8.3 [class.access.base] paragraph 5 would then need to be italicized.

Date: 2023-02-11.00:00:00


  struct A {int i;};
  struct X : A {};
  struct Y : A {};
  struct S : X,Y {};

  void f(S &s) {++s.X::i;}

There is a rule that &s be able to "be implicitly converted to a pointer to the naming class of the right operand" (11.8.3 [class.access.base] paragraph 6), which correctly selects X here, but [expr.ref] bullet 6.2 merely says that

If E2 is a non-static data member [...], the expression designates the corresponding member subobject of the object designated by the first expression.

E2 (i.e. X::i) and Y::i equally denote A::i (since name lookup produces declarations), but there is no rule that indicates which A::i is selected as the "corresponding member subobject". (Note that s.X::A::i means the same as s.A::i and is ambiguous.)

Date User Action Args
2023-03-11 18:07:02adminsetmessages: + msg7224
2023-02-11 00:00:00admincreate