I have the following code:
int x = {{}};
Is this syntax valid according to the C++ standard? (I'm interested in C++11 and later.)
When using the latest compilers there is no problem, however in some older ones (e.g. GCC 4.8.5) it gives following error:
error: braces around scalar initializer for type 'int'
This is ill-formed. gcc is wrong to accept it and clang seems to allow it as an extension, as it warns about it.
I'm going to quote the latest draft, but it doesn't make a difference. List initialization works as follows as per [dcl.init.list], where T is int
in this case:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With