Title
Class for pointer-to-member formation
Status
open
Section
7.6.2.2 [expr.unary.op]
Submitter
Hubert Tong

Created on 2025-05-11.00:00:00 last changed 1 month ago

Messages

Date: 2025-05-12.20:40:45

Suggested resolution:

Change in 7.6.2.2 [expr.unary.op] bullet 3.1 as follows:

The operand of the unary & operator shall be an lvalue of some type T.
  • If the operand is a qualified-id naming a non-static or variant class member m of some class C, other than an explicit object member function, then let C be the class, that is not an anonymous union, of which m is a direct member. the The result has type “pointer to member of class C of type T” and designates C::m. [Note: A qualified-id that names a member of a namespace-scope anonymous union is considered to be a class member access expression (7.5.5.1 [expr.prim.id.general]) and thus cannot be used to form a pointer to member.-- end note]
  • ...
Date: 2025-05-11.00:00:00

(From submission #705.)

Consider:

  struct A {
   union { int x; };
   int y;
  };
  struct B : A {};

  template <typename> struct Q;
  template <> struct Q<A> {};
  template <typename T> Q<T> f(int T::*);

  Q<A> g() { return f(&B::x); }  // OK
  Q<A> h() { return f(&B::y); }  // OK

For both cases, the pointer to member is of type "pointer to member of class A", but the wording is not clear.

History
Date User Action Args
2025-05-11 06:06:18adminsetmessages: + msg8024
2025-05-11 00:00:00admincreate