C++0x is going to make the following code and similar code ill-formed, because it requires a so-called narrowing conversion of a double
to a int
.
int a[] = { 1.0 };
I'm wondering whether this kind of initialization is used much in real world code. How many code will be broken by this change? Is it much effort to fix this in your code, if your code is affected at all?
For reference, see 8.5.4/6 of n3225
A narrowing conversion is an implicit conversion
- from a floating-point type to an integer type, or
- from long double to double or float, or from double to float, except where the source is a constant expression and the actual value after conversion is within the range of values that can be represented (even if it cannot be represented exactly), or
- from an integer type or unscoped enumeration type to a floating-point type, except where the source is a constant expression and the actual value after conversion will fit into the target type and will produce the original value when converted back to the original type, or
- from an integer type or unscoped enumeration type to an integer type that cannot represent all the values of the original type, except where the source is a constant expression and the actual value after conversion will fit into the target type and will produce the original value when converted back to the original type.
0
is already anint
anyway.) – aschepler Dec 13 '10 at 22:50{
curly brace initializers}
, and the only legacy usage of those is for arrays and POD structs. Also, if existing code has explicit casts where they belong, it won't break. – aschepler Dec 13 '10 at 22:53int a = 1.0;
is still valid. – Johannes Schaub - litb Dec 14 '10 at 10:26