This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115c. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-09-25


1078. Narrowing and the usual arithmetic conversions

Section: 9.4.5  [dcl.init.list]     Status: NAD     Submitter: Jason Merrill     Date: 2010-06-14

Consider the example,

    struct A { char c; };
    void f (char d) {
       A a = { d + 1 };
    }

This code is now ill-formed because of the narrowing conversion from the int result type of the addition, not because of any real narrowing. This seems like an embarrassment for C++0x. It would be better not to get an error about any arithmetic involving non-constant operands just because it might overflow with some values.

Rationale (November, 2010):

The CWG agreed that this behavior is unfortunate but felt that it would be too difficult to formulate a satisfactory set of rules for handling complex expressions correctly for a small gain in utility (the user can simply add a cast in order to avoid the error).