Skip to content

Commit 38e4cae

Browse files
WalterBrightdlang-bot
authored andcommitted
Make out of range shift implementation defined
1 parent 0899863 commit 38e4cae

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

spec/expression.dd

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -779,13 +779,21 @@ $(GNAME ShiftExpression):
779779
$(LI $(D >)$(D >)$(D >) is an unsigned right shift.)
780780
)
781781

782-
$(P It's illegal to shift by the same or more bits than the size of the
783-
quantity being shifted:)
782+
$(IMPLEMENTATION_DEFINED
783+
The result of a shift by a negative value or by the same or more bits
784+
than the size of the quantity being shifted is undefined.
785+
When the shift amount is known at compile time, doing this results in
786+
a compile error.
784787

785788
-------------
786789
int c;
787-
auto x = c << 33; // error
790+
791+
int s = -3;
792+
auto y = c << s; // implementation defined value
793+
794+
auto x = c << 33; // error, max shift count allowed is 31
788795
-------------
796+
)
789797

790798
$(H2 $(LNAME2 add_expressions, Add Expressions))
791799

0 commit comments

Comments
 (0)