Created on 2008-07-02.00:00:00 last changed 178 months ago
[Voted into WP at October, 2009 meeting.]
Proposed resolution (July, 2009):
Change 9.4.5 [dcl.init.list] paragraph 6 as follows:
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
will fit into the target type and will produce the original value when converted back to the original typeis within the range of values that can be represented (even if it cannot be represented exactly), or...
Notes from the September, 2008 meeting:
The CWG agreed that the second initialization should not be a narrowing error; furthermore, this exemption should apply not only to literals but to any floating-point constant expression. Instead of the current formulation, requiring exact bidirectional convertibility, the Standard should only require that the initializer value be within the representable range of the target type.
Both of the following initializations are ill-formed because of narrowing, although they were previously well-formed:
struct A { int i; } a = { 1.0 }; struct B { float f; } b = { 1.1 };
The first one doesn't seem like a big problem, as there probably isn't much code that has this kind of aggregate initialization. The second might be of more concern, because 1.1 is not representable in either float or double. Is the resulting loss of precision a kind of narrowing that we want to diagnose?
History | |||
---|---|---|---|
Date | User | Action | Args |
2010-03-29 00:00:00 | admin | set | status: dr -> cd2 |
2009-11-08 00:00:00 | admin | set | messages: + msg2462 |
2009-11-08 00:00:00 | admin | set | status: ready -> dr |
2009-08-03 00:00:00 | admin | set | messages: + msg2166 |
2009-08-03 00:00:00 | admin | set | status: drafting -> ready |
2008-10-05 00:00:00 | admin | set | messages: + msg1781 |
2008-10-05 00:00:00 | admin | set | status: open -> drafting |
2008-07-02 00:00:00 | admin | create |