This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: Initialization of a static member of a template class fails
- From: "John (Eljay) Love-Jensen" <eljay at adobe dot com>
- To: "Valery Jean-Michel" <Jean-Michel dot Valery at fr dot thalesgroup dot com>, <gcc-help at gcc dot gnu dot org>
- Date: Thu, 26 Jul 2007 11:42:17 -0700
- Subject: RE: Initialization of a static member of a template class fails
- References: <F2E37429BA50E34EA0B7F97AFEB8CBD10B5FF4D7@mercure.tus.fr.thales>
Hi Valery,
I suspect your code is running into the dreaded Order Of Construction problem. Which is only turn-of-the-screw less painful than the even more dreaded Order Of Destruction problem.
I replaced this part of your code...
static instance_list s_instances;
...with a class function to access a function-wrapped static instance_list variable...
static instance_list& GetInstanceList()
{
static instance_list s_instances;
return s_instances;
}
...and the crasher (which I also saw) went away.
Of course, you won't want a class static accessor function wrapping an instance variable in a header file, since that may cause even harder to diagnose problems. Such as: every translation unit* getting one-or-more copies of an inlined GetInstanceList. Doh!
The solution to that latter problem is rather heinous (in my opinion), which involves explicit instantiation for all known instances of Enum<T> in a designated translation unit. Ugh. Maybe there is a more elegant solution.
HTH,
--Eljay
* Or compilation unit - whatever your terminological preference.