Skip to content

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

Closed
@xmh0511

Description

@xmh0511
Contributor

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

Activity

frederick-vs-ja

frederick-vs-ja commented on Mar 2, 2023

@frederick-vs-ja
Contributor

This should have been fixed by #5984.

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[/+] on Mar 2, 2023
jensmaurer

jensmaurer commented on Mar 2, 2023

@jensmaurer
Member

Fixed by CWG2612.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @xmh0511@frederick-vs-ja@jensmaurer

      Issue actions

        The comment of the example in [dcl.init.general] p16.6.1 is wrong CWG2612 · Issue #5488 · cplusplus/draft