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

2024-12-19


1538. C-style cast in braced-init-list assignment

Section: 7.6.19  [expr.ass]     Status: CD3     Submitter: Daniel Krügler     Date: 2012-08-14

[Moved to DR at the April, 2013 meeting.]

According to 7.6.19 [expr.ass] paragraph 9,

The meaning of x={v}, where T is the scalar type of the expression x, is that of x=T(v) except that no narrowing conversion (9.4.5 [dcl.init.list]) is allowed. The meaning of x={} is x=T().

This definition adds a gratuitous C-style cast to the right-hand operand, inadvertently allowing such things as base-to-derived conversions and circumvention of access checking.

Proposed resolution (October, 2012):

Change 7.6.19 [expr.ass] paragraph 9 as follows:

The meaning of x={v}, where T is the scalar type of the expression x, is that of x=T(v) except that no narrowing conversion (9.4.5 [dcl.init.list]) is allowed x=T{v}. The meaning of x={} is x=T() x=T{}.