@@ -350,23 +350,27 @@ $(H3 $(LNAME2 vrp, Value Range Propagation))
350350 expressions to implicitly convert to a narrower type after
351351 integer promotion. This works by analysing the minimum and
352352 maximum possible range of values for each expression.
353- If that range of values matches or is a subset of a narrower type's value range, implicit
353+ If that range of values matches or is a subset of a narrower
354+ target type's value range, implicit
354355 conversion is allowed. If one of the values is known at compile-time,
355356 that can further reduce the range of values.)
356357
357358 $(SPEC_RUNNABLE_EXAMPLE_COMPILE
358359 ---
359360 extern char c;
360- short s = c + 100; // promoted to int, but narrowed to `c.min + 100` ... `c.max + 100`
361+ // min is c.min + 100 > short.min
362+ // max is c.max + 100 < short.max
363+ short s = c + 100; // OK
361364
362365 extern int i;
363- ubyte j = i & 0x3F;
366+ ubyte j = i & 0x3F; // OK, 0 ... 0x3F
364367 //ubyte k = i & 0x14A; // error, 0x14A > ubyte.max
365368 ushort k = i & 0x14A; // OK
366369
367370 extern ubyte b;
368- //ubyte p = b + b; // error, ubyte.max + ubyte.max > ubyte.max
369- short p = b + b; // OK
371+ k = i & b; // OK, 0 ... b.max
372+ //b = b + b; // error, b.max + b.max > b.max
373+ s = b + b; // OK, 0 ... b.max + b.max
370374 ---
371375 )
372376 $(P For more information, see $(LINK2 https://digitalmars.com/articles/b62.html, here).)
0 commit comments