Closed
Description
[dcl.init.general] p16.6.1
[Example 2: T x = T(T(T())); calls the T default constructor to initialize x. — end example]
The result object x
is not definitely initialized by the default constructor. The result object is actually value-initialized.
If the initializer is (), the object is value-initialized.
In this case, the result object will be zero-initialized if T
has a trivial default constructor. This point can be shown by this example.
struct A{
int a;
};
int main(){
A a = A(A(A())); // #1
A b;
std::cout<<"a.a: "<< a.a<<std::endl;
std::cout<< "b.a: "<< b.a<<std::endl;
}
The result printed by Clang is
a.a: 0 // the subobject is zero-initialized
b.a: -1215191136 // indeterminate value
If the default constructor were called for #1
, the subobject A::a
would be uninitialized.
The comment should just say x
is value-initialized.
Metadata
Metadata
Assignees
Labels
No labels
Activity
frederick-vs-ja commentedon Mar 2, 2023
This should have been fixed by #5984.
[-]The comment of the example in [dcl.init.general] p16.6.1 is wrong[/-][+]The comment of the example in [dcl.init.general] p16.6.1 is wrong CWG2612[/+]jensmaurer commentedon Mar 2, 2023
Fixed by CWG2612.