On Thursday, October 11, 2018 at 1:21:42 PM UTC-4, Thiago Adams wrote:
> #include <stdio.h>
>
> struct X {
> int i;
> };
>
>
> int main()
> {
> X *p = new X();
"If there is no user-declared constructor for class X, a non-explicit constructor having no parameters is implicitly declared as defaulted
(9.4). An implicitly-declared default constructor is an inline public
member of its class." (10.3.4p4).
"The implicitly-defined default constructor performs the set of
initializations of the class that would be performed by a user-written
default constructor for that class with no ctor-initializer (10.9.2) and
an empty compound-statement." (10.3.4p7)
"In a non-delegating constructor, if a given potentially constructed
subobject is not designated by a meminitializer-id (including the case
where there is no mem-initializer-list because the constructor has no
ctor-initializer), then
[several options that don't apply]
— otherwise, the entity is default-initialized (9.3)." (10.9.2p9)
"To default-initialize an object of type T means:
(7.1) — If T is a (possibly cv-qualified) class type (Clause 10), ...
(7.2) — If T is an array type, ...
(7.3) — Otherwise, no initialization is performed." (9.3p7)
> X x = {};
> printf("%d %d", p->i, x.i);
> delete p;
> }
>
> This code is printing 0 0 in release mode. (VC++ 17)
>
> Is it guarantee to initialize 'i' with '0'?
No.