#include <iostream>
int main()
{
struct pod {
int i;
};
struct inherit : pod {
inherit() : pod() {}
};
struct compose {
compose() : p() {}
pod p;
};
inherit i;
compose c;
std::cout << i.i << std::endl;
std::cout << c.p.i << std::endl;
}
In both cases the pod object is explicitly value-initialized, which according
to 8.5para5 means that "every non-static data member ... is value-initialized"
compose::pod::i is value-initialised, inherit::i is not. This can be seen from
the values printed out for i.i and by using Purify.
Same result with GCC 4.1.1, 3.4.3, 3.3.4 on Solaris 9, GCC 3.4.3 on AIX 5/3
Valgrind is being weird so I can't test it on Linux, butI don't think it's
platform-dependent.
--
Summary: Value-initialization of POD base class doesn't
initialize members
Product: gcc
Version: 4.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: gcc-bugzilla at kayari dot org
GCC target triplet: sparc-sun-solaris2.9
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30111