This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 110b. See for the official list.


703. Narrowing for literals that cannot be exactly represented

Section: 9.4.5  [dcl.init.list]     Status: CD2     Submitter: Jason Merrill     Date: 2 July, 2008

[Voted into WP at October, 2009 meeting.]

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?

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.

Proposed resolution (July, 2009):

Change 9.4.5 [dcl.init.list] paragraph 6 as follows:

A narrowing conversion is an implicit conversion