Looks like:
bool b = {2} ;
really is a narrowing transformation if we look at the draft C ++ 8.5.4 standard in paragraph 7 of the initialization of the list:
Narrowing a transform is an implicit transform
and enable the following bullet (my selection):
from an integer type or an enumerated type of an enumeration to an integer type that cannot represent all the values ββof the source type , except where the source is a constant expression, the value of which after the integral, the promotions will fit into the target type.
bool cannot represent the value 2 , so this is a narrowing of the conversion in the strict sense. What makes sense, all of the initialization {} is to prevent implicit conversions and increases type safety. What old style are you referring to:
bool b = 2
which depends on section 4.12 Boolean transformations, which states:
[...] A null value, a null pointer value, or a null element pointer value is converted to false; any other value is converted to true. [...]
Of course, the whole premise that {2} will be a narrowing transformation, assumes that true and false are 1 and 0 , which, as far as I can tell, is not guaranteed in the standard. Although the only standard promises in conversions are implied, but if we use a literal, we do not need to rely on this assumption, we have two absolutely good boolean literals for these true and false , which are what you should use.
To complete this transformation, the narrowing is poorly formed, it requires diagnostics, therefore either a warning or an error is permissible. if we look at paragraph 3, it says:
An initialization list of an object or link of type T is defined as follows:
and enable the following bullet (my selection):
Otherwise, if there is one element of type E in the list of initializers, and either T is not a reference type, or its reference type is associated with a binding to E, an object or reference is initialized from this element; if, to convert an element to T, a restriction transformation is required (see below), the program is poorly formed .
and includes the following example:
[ Example: int x1 {2}; // OK int x2 {2.0}; // error: narrowing βend example ]