This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-11-11


2329. Virtual base classes and generated assignment operators

Section: 11.4.6  [class.copy.assign]     Status: drafting     Submitter: Daveed Vandevoorde     Date: 2016-10-31

An example like the following,

  class A {
  private:
    A& operator=(const A&);
  };

  class B : virtual public A {
  public:
    B& operator = (const B& src);
  };

  class C: public B {
  public:
    void f(const C* psrc) {
      *this = *psrc;
    }
  };

is presumably well-formed, even though the copy assignment operator of A is inaccessible in C, because 11.4.6 [class.copy.assign] paragraph 12 says that only direct, not virtual, base class object assignment operators are invoked by the generated assignment operator (although there is implementation divergence on this question).

Should the example also be well-formed if A were a direct virtual base of C? That is, if a direct virtual base also has an indirect derivation path, its direct derivation can be ignored for generated assignment operators.

Possibly relevant to this question is the permission for an implementation to assign virtual base class objects more than once:

It is unspecified whether subobjects representing virtual base classes are assigned more than once by the implicitly-defined copy/move assignment operator.