
2011/11/3 Stewart, Robert <Robert.Stewart@sig.com>
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