From 0705a337b04214099bbb5c4d368ff519ed2cb714 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Wed, 12 Oct 2016 19:15:35 -0500 Subject: [PATCH] Allow case labels in switch statements that are out of range of the type being switched on. The case label values are converted to the promoted type of the expression being switched on, as if by a cast. In practice, this means discarding the high bits of a 32-bit value to produce a 16-bit one. Code requiring this is dubious and would be a good candidate for a warning or a lint error, but it's allowed under the C standards. The following code demonstrates the issue: #include int main(void) { int i = 0x1234; switch (i) { case 0xABCD1234: puts("good"); break; default: puts("bad"); } } --- Parser.pas | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Parser.pas b/Parser.pas index ea4f9b0..318ae71 100644 --- a/Parser.pas +++ b/Parser.pas @@ -427,7 +427,7 @@ var val := long(expressionValue).lsw; if val <> expressionValue then if not stPtr^.isLong then - Error(71); + expressionValue := val; {convert out-of-range value to (U)Word} if stPtr = nil then Error(72) else begin