This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/67519] New: New warning: calls to member functions before all base classes constructed
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 09 Sep 2015 13:04:09 +0000
- Subject: [Bug c++/67519] New: New warning: calls to member functions before all base classes constructed
- Auto-submitted: auto-generated
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
};