|
Boost : |
Subject: Re: [boost] [parameter] aux_/void.hpp: potential undefined behavior
From: Krzysztof Czainski (1czajnik_at_[hidden])
Date: 2011-11-03 19:52:49
2011/11/3 Stewart, Robert <Robert.Stewart_at_[hidden]>
> Krzysztof Czainski wrote:
> >
> > struct void_ {};
> >
> > namespace aux
> > {
> > inline void_& void_reference()
> > {
> > static void_ instance; // (1)
> > return instance;
> > }
> [snip]
> > My question is: is it allowed to use an instance of an
> > uninitialized empty struct?
>
> That uses the implicit default constructor provided by the compiler which,
> of course, does nothing. instance is not uninitialized.
>
Oh, makes sense, thanks.
So then, don't you think it's better to use static initialization? Or maybe
it doesn't matter?
I mean, if the (empty autogenerated) default constructor is called, then
the compiler needs to generate some flag and an if condition, so the
default constructor is only called during the first invocation of
void_reference(). Of course, that can be optimized away, but isn't it just
better to use static initialization here? (something like prefere
pass-by-const-ref to pass-by-value)
Regards,
Kris
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk