Title
Narrowing and the usual arithmetic conversions
Status
nad
Section
9.4.5 [dcl.init.list]
Submitter
Jason Merrill

Created on 2010-06-14.00:00:00 last changed 170 months ago

Messages

Date: 2010-11-15.00:00:00

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).

Date: 2022-11-20.07:54:16

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.

History
Date User Action Args
2010-11-29 00:00:00adminsetmessages: + msg3217
2010-11-29 00:00:00adminsetstatus: open -> nad
2010-06-14 00:00:00admincreate