This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/63526] O1 O2 O3 optimization and inline template constructor - uninitialized member
- From: "eles.david.88 at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 14 Oct 2014 05:23:28 +0000
- Subject: [Bug c++/63526] O1 O2 O3 optimization and inline template constructor - uninitialized member
- Auto-submitted: auto-generated
- References: <bug-63526-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63526
--- Comment #5 from DÃvid Ãles <eles.david.88 at gmail dot com> ---
(In reply to Daniel KrÃgler from comment #3)
> (In reply to DÃvid Ãles from comment #2)
> > I uses the default mechanism to initialization of members.
> > As far as I know the C++ standard says (8.5/5):
> > To default-initialize an object of type T means:
> > * If T is a non-POD class type (clause 9), the default constructor for T is
> > called (and the initialization is ill-formed if T has no accessible default
> > constructor).
>
> [Based on your quotes and your compiler settings you seem to quote the
> C++98/03 standard. This is where my response is referred to as well]
>
> In your example an object of type Foo<double> is default-initialized. Class
> Foo<double> is a non-POD class type, and therefore exactly this bullet is
> entered. The result is what the wording says: the default constructor for T
> (that is Foo<double> in this example is called. The semantics of calling the
> default-constructor of a class that has no member-initializer provided (such
> as in this case) is specified in [class.base.init] p5:
>
> "If a given nonstatic data member or base class is not named by a
> mem-initializer-id (including the case where there is no
> mem-initializer-list because the constructor has no ctor-initializer), then
> â If the entity is a nonstatic data member of (possibly cv-qualified) class
> type (or array thereof) or a base class, and the entity class is a non-POD
> class [..]
> â Otherwise, the entity is not initialized. [..]
>
> The first bullet here does not apply, because the member is of type double
> and thus does not match a class type. The second bullet therefore
> unconditionally applied and says that the member is not initialized at all.
>
> > * If T is an array type, each element is default-initialized.
>
> This bullet does not apply
>
> > * Otherwise, the object is zero-initialized.
>
> This bullet does not apply.
>
> > In case of c++ it should be zero initialized if it is the member of a
> > class/struct.
>
> No, you are incorrectly interpreting the Standard.
>
> > As far as I know I have to force to not doing zero initialization something
> > like that Foo* f = new Foo;
>
> That has essentially the same initialization semantics as your example code.
You are right, I missed it, thanks for your quick answer. Sorry to waste your
time.