Boost logo

Boost :

Subject: Re: [boost] Is there any interest in a base class which prevents construction during the static initialization phase?
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2011-06-12 22:39:32


On Sun, Jun 12, 2011 at 4:51 PM, Ben Robinson <icaretaker_at_[hidden]> wrote:
> Hello,
>
> Because the order of static initialization is undefined, numerous difficult
> to detect problems can arise when multiple objects are initialized during
> the static initialization phase.  This base class would guarantee that a
> class will never be unintentionally constructed during static
> initialization.  This is the same philosophy behind how boost::noncopyable
> guarantees that a class will never be unintentionally copied.

What you probably mean is "initialization of objects with static
storage duration", which can be static and dynamic. All such objects
are first zero initialized. Then the ones that are initialized with a
constant expression are initialized, and this concludes the static
initialization phase. Then the dynamic initialization phase follows.

Only the dynamic initialization phase can cause problems.

However, the dynamic initialization phase can cause problems with any
object that uses it. That is, whether or not a compile error is
induced should only depend on whether or not a given object with
static storage duration is initialized during the dynamic
initialization phase. Deriving or not deriving from
nonstaticinitializable doesn't seem to have anything to do with this.

Don't get me wrong, I agree that using objects with static storage
duration that are initialized dynamically is the source of many
problems, but it seems like it makes more sense to detect and report
such initialization with a lint-type utility rather than relying on a
programmer to derive from a type.

Emil Dotchevski
Reverge Studios, Inc.
http://www.revergestudios.com/reblog/index.php?n=ReCode


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk