https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63526
Daniel Krügler <daniel.kruegler at googlemail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |daniel.kruegler@googlemail.
| |com
--- Comment #3 from Daniel Krügler <daniel.kruegler at googlemail dot com> ---
(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.