Within the same compilation unit, the C ++ standard says that the static order of initialization is well defined - this is the order of declarations of static objects. But using the Sun Studio 12 compiler, I come across unintuitive behavior. I defined a templated template helper<T>that contains a static _datatype member Tand a static member function that uses what is _datacalled foo. In my .cpp file, I have this above main ():
struct A { };
typedef helper<int> s0;
typedef helper<A> s1;
Note that typedef for helper<int>matches up to typedef for helper<A>. So, according to the standard, I would expect it to helper<int>::_databe built before helper<A>::_data(remember, that _datais a static member). On the GCC, this is so; on the Sun, it is not.
This is problematic because the constructor uses helper<int>::_data. I have only one compilation unit that does not have an earlier potential instance helper<A>, so I thought the order should be clearly defined. Is this a Sun compiler bug, or is typedef not technically a definition / specification? I mean, is Sun compiler behavior a valid standard?
I have the following main ():
int main()
{
s0::foo();
s1::foo();
}
There are no other uses for s0 or s1.