[Bug c++/19123] Static member object gets constructed after containing objects constructor returns

pinskia at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Wed Dec 22 00:31:00 GMT 2004


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-12-22 00:31 -------
One more thing, try linking in a different order and see that you get different order of constructing of 
the objects.

There is nothing we can do.

More more thing the testcase is equivent to:
#include <iostream>
class	C_CHILD{
public:
	C_CHILD();
	C_CHILD( const char* name);
	const char*				m_name;

};
class C_ROOT{
public:
	C_ROOT();
	static C_CHILD		m_variable_root;
};
C_ROOT::C_ROOT(){
	std::cout<<"We needed you CTOR!"<<std::endl;
}
C_CHILD::C_CHILD(){
	m_name				= NULL;
}
C_CHILD::C_CHILD(const char* name){
	std::cout<<"Constructor: "<<name<<std::endl;
}
class cCore {
public:
	cCore();
	~cCore();
	static C_ROOT	m_database;
};
cCore::cCore() {	}
cCore::~cCore() {	}
#if 1
C_CHILD		C_ROOT::m_variable_root( "/" );
C_ROOT		cCore::m_database;
#else
C_ROOT		cCore::m_database;
C_CHILD		C_ROOT::m_variable_root( "/" );
#endif
int main(){
	return 0;
}



And switch the order of the two objects in the file, you will get a different behavior, though the 
requirement of that is defined IIRC but between different TU is undefined.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19123



More information about the Gcc-bugs mailing list