This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/67519] New: New warning: calls to member functions before all base classes constructed


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67519

            Bug ID: 67519
           Summary: New warning: calls to member functions before all base
                    classes constructed
           Product: gcc
           Version: 4.9.4
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: enhancement
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

It's undefined to (directly or indirectly) call a member function in a
ctor-initializer before all the mem-initializers for base classes have
completed ([class.base.init] p16).

It should be possible to warn about this, at least for simple cases.

The example in [class.base.init] p16 should give two warnings:

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

class B : public A {
  int j;
public:
  int f();
  B() : A(f()), // undefined: calls member function
                // but base A not yet initialized
  j(f()) { }    // well-defined: bases are all initialized
};

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

class D : public B, C {
  int i;
public:
  D() : C(f()), // undefined: calls member function
                // but base C not yet initialized
  i(f()) { }    // well-defined: bases are all initialized
};


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]