Since switching on the C++0x standard in g++, I’ve started seeing ‘narrowing conversion’ errors, particularly when converting from an ‘int’ to a ‘short’ although I understand the error covers a much broader swath of conversions.
Can anyone shed some light on the rational for introducing this extra level of safety?, What are the possible consequences of disabling this error? (apart from the potential loss of precision).
Thanks.
From Assignment and compound assignment operators [expr.ass]
and from List-initialization [dcl.ini.list]
So basically you can’t ignore it, your program is ill-formed in presence of narrowing conversions.
From Implementation compliance:
Bjarne Stroustroup say this:
int x = 7.3; // Ouch! void f(int); f(7.3); // Ouch!So in a way, narrowing also increases type safety.