What is the difference between initializing with = and initializing with {} ?
In general, the difference is that the first copy initialization , and the last direct - list initialization . The linked online link details all three forms of initialization. In particular, there is a difference that you have already quoted; List initialization cannot be used with narrowing conversions.
But the code on the right side loses some information even after using {}
The program on the right side is poorly formed.
As already mentioned, the standard does not allow narrowing down conversions in the context of list initialization. int to char is a narrowing transformation.
Since the program is poorly formed, the standard does not guarantee its behavior, except that the compiler must issue a diagnostic message. For example, g ++ - 5.3.0 will say:
warning: narrowing conversion of 'x' from 'int' to 'char' inside { } [-Wnarrowing]
Can you talk about the "poorly formed" part?
The standard says that the program should not do X. Your program does X. Therefore, it violates the standard, which makes the program poorly formed. Here X:
If converting any of the arguments requires narrowing the transform (see below), the program is poorly formed.
The program on the left is not badly formed. However, it, like the program on the right side, assigns a value of char y , which is not represented by type char (it can be represented in some implementation, where char is an unsigned type, but given the output, which seems to be not suitable for your implementation ) When an unrepresentable value is converted to a signed type, the resulting value is determined by the implementation.