File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -492,15 +492,22 @@ $(H3 $(LNAME2 vrp, Value Range Propagation))
492
492
s = b + b; // OK, 0 ... b.max + b.max
493
493
---
494
494
)
495
- $(P Note the implementation does not track the range of possible values for variables,
496
- only expressions:)
495
+ $(P Note the implementation does not track the range of possible values for
496
+ mutable variables:)
497
+
498
+ $(SPEC_RUNNABLE_EXAMPLE_COMPILE
497
499
---
498
500
extern int i;
499
- short s = i & 0xff; // OK
501
+ ushort s = i & 0xff; // OK
500
502
// s is now assumed to be s.min ... s.max, not 0 ... 0xff
501
- //byte b = s; // error
502
- byte b = s & 0xff; // OK
503
+ //ubyte b = s; // error
504
+ ubyte b = s & 0xff; // OK
505
+
506
+ const int c = i & 0xff;
507
+ // c's range is fixed and known
508
+ b = c; // OK
503
509
---
510
+ )
504
511
* For more information, see $(LINK2 https://digitalmars.com/articles/b62.html, the dmc article).
505
512
* See also: $(LINK https://en.wikipedia.org/wiki/Value_range_analysis).
506
513
You can’t perform that action at this time.
0 commit comments