Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The comment of the example in [dcl.init.general] p16.6.1 is wrong CWG2612 #5488

Closed
xmh0511 opened this issue May 24, 2022 · 2 comments · Fixed by #5984
Closed

The comment of the example in [dcl.init.general] p16.6.1 is wrong CWG2612 #5488

xmh0511 opened this issue May 24, 2022 · 2 comments · Fixed by #5984

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented May 24, 2022

[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.

@frederick-vs-ja
Copy link
Contributor

This should have been fixed by #5984.

@jensmaurer jensmaurer changed the title 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 Mar 2, 2023
@jensmaurer
Copy link
Member

Fixed by CWG2612.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants