|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2005-05-22 21:07:53
Rene Rivera <grafik.list_at_[hidden]> writes:
> Many of the problems that CodeWarrior, and True64, have with the
> serialization library stem from the behavior of CW to not call
> constructors for static data members in one particular class in the
> library. I've come to think that this is standard conforming behavior.
>
> The serialization library relies on a static member of a template class
> being constructed at global initialization time to figure out what all
> the serialized classes are. The problem is that the template class is
> being instantiated implicitly. Which for most compilers also
> instantiates any static members of that template class. It's my
> understanding that this violates 14.7.1.7:
>
> "The implicit instantiation of a class template does not cause any
> static data members of that class to be implicitly instantiated."
>
> Question I have.. Is my understanding correct? Or is this a bug in CW part?
Your understanding is certainly correct. It's standard practice in
traits templates, for example, to do something like:
template <class T>
struct is_whatever
{
static T& x;
template <class U>
char test(U&);
template <class U>
char (& test( whatever<U>& ) )[2];
enum { value = sizeof(test(x)) == 2 };
};
Nobody ever even writes an initializer for x.
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk