On 19 March 2012 18:48, Jonathan Wakely wrote:
> On 19 March 2012 18:27, Hite, Christopher wrote:
>> Thanks for the quick response.
>>> The C++ standard says that for a POD type the initializer () will cause it to be zero-initialized.
>> No the standard says: If I don't init the POD with an initializer or otherwise, I have to expect dirty memory there.
>
> Where does it say that?
>
> [dcl.init] paragraph 10 says "An object whose initializer is an empty
> set of parentheses, i.e., (), shall be value-initialized."
When Ray2 is value-initialized the following text from paragraph 7 applies:
"if T is a (possibly cv-qualified) non-union class type without a
user-provided constructor, then the object is zero-initialized and, if
T’s implicitly-declared default constructor is non-trivial, that
constructor is called."
Note that the object is zero-initialized, then the implicitly-declared
constructor Ray2::Ray2() is called, which calls the Ray::Ray()
constructor.
> [dcl.init] paragraph 11 says "If no initializer is specified for an
> object, the object is default-initialized; if no initialization is
> performed, an object with automatic or dynamic storage duration has
> indeterminate value."
In the default-initialized case Ray2::Ray2() is called, with no
zero-initialization.
> Your example has an initializer which is an empty set of parentheses.
So as I said in my first mail, if you don't want the
zero-initialization, remove the initializer i.e. the empty
parentheses.
If you don't see behaviour matching the standard semantics described
above then I suggest you try a more recent version of GCC, and if you
still don't get that behaviour then you should report a bug.
[Linux C Programming]
[Linux Kernel]
[eCos]
[Fedora Development]
[Fedora Announce]
[Autoconf]
[The DWARVES Debugging Tools]
[Yosemite Campsites]
[Yosemite News]
[Linux GCC]