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
[dcl.init.general] Fix the informative description in 16.6.1 Example 2 CWG2612 #5489
[dcl.init.general] Fix the informative description in 16.6.1 Example 2 CWG2612 #5489
Conversation
by only using "value-initializes"
The redundant |
@JohelEGP The multi-level |
I think it's unobservable whether a trivial default constructor is called or not. |
The
To value-initialize an object of class The comment just says the object will be initialized by the default constructor, which is just wrong. I think it is observable if the object is used in a constant expression. struct T{
int a;
};
constexpr T obj = T(); //ok
constexpr T obj2; // error The reason for the error at |
I meant we can observe whether the default constructor is called in this case. The issue is that the comment arbitrarily says the default constructor is called for |
Isn't 9.1.2 indicating that both zero-initialization and default-initialization are performed if the default constructor is defaulted and non-trivial? msvc accepts the following example, while gcc, icc, and clang rejects it (link). struct Foo {
int a;
int b = 1;
};
static_assert(Foo().a == 0); IIUC, msvc is doing the right thing here.
Yes. However, if it's confirmed that a trivial default constructor is not needed to skip, can we simplify [dcl.init.general]/(9.1.2) as following?
And I still think "value-initializes" should be used, because both zero- and default-initialization may matter when both are present. |
Seems that you're right. GCC and Clang might have a misreading here. It might also be the intent here is that the value-initialization of an object of class type(its default constructor is defaulted and non-trivial) is either zero-initialized or default-initialized but not both? GCC and Clang implement the right things just didn't embody them in the current wording? |
Perhaps a CWG issue is needed. I've opened cplusplus/CWG#40 for this (and possibly another issue touching the same paragraph). |
Can we close this issue in favour of the CWG issue then? |
The core issue hasn't been created, yet. |
Created a CWG issue in cplusplus/CWG#117 |
No. That's the inbox for new core issues, not the actual core issues list. |
See CWG2612 |
Done in #5984. Closing. |
T x = T(T(T()));
value-initializesx
, and according to [dcl.init.general]/(9.1.2), the initialization (when well-formed) skips the constructor call if the default constructor is trivial.Fixes #5488.