Skip to content

Commit ec9102b

Browse files
ntreldlang-bot
authored andcommitted
[spec/type] Document that constant variables can track value range
1 parent 467f934 commit ec9102b

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

spec/type.dd

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -492,15 +492,22 @@ $(H3 $(LNAME2 vrp, Value Range Propagation))
492492
s = b + b; // OK, 0 ... b.max + b.max
493493
---
494494
)
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
497499
---
498500
extern int i;
499-
short s = i & 0xff; // OK
501+
ushort s = i & 0xff; // OK
500502
// 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
503509
---
510+
)
504511
* For more information, see $(LINK2 https://digitalmars.com/articles/b62.html, the dmc article).
505512
* See also: $(LINK https://en.wikipedia.org/wiki/Value_range_analysis).
506513

0 commit comments

Comments
 (0)