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

2024-04-18


2056. Member function calls in partially-initialized class objects

Section: 11.9.3  [class.base.init]     Status: drafting     Submitter: Richard Smith     Date: 2014-12-11

According to 11.9.3 [class.base.init] paragraph 16,

Member functions (including virtual member functions, 11.7.3 [class.virtual]) can be called for an object under construction. Similarly, an object under construction can be the operand of the typeid operator (7.6.1.8 [expr.typeid]) or of a dynamic_cast (7.6.1.7 [expr.dynamic.cast]). However, if these operations are performed in a ctor-initializer (or in a function called directly or indirectly from a ctor-initializer) before all the mem-initializers for base classes have completed, the result of the operation is undefined.

The example in that paragraph reads, in significant part,

  class B {
  public:
    int f();
  };

  class C {
  public:
    C(int);
  };

  class D : public B, C {
  public:
    D() : C(f())  // undefined: calls member function
                  // but base \tcode{C} not yet initialized
    {}
  };

However, the construction of B, the object for which the member function is being called) has completed its construction, so it is not clear why this should be undefined behavior.

(See also issue 1517.)