mirror of
https://github.com/byteworksinc/ORCA-C.git
synced 2025-08-10 06:25:02 +00:00
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 <stdio.h> int main(void) { int i = 0x1234; switch (i) { case 0xABCD1234: puts("good"); break; default: puts("bad"); } }
This commit is contained in:
@@ -427,7 +427,7 @@ var
|
|||||||
val := long(expressionValue).lsw;
|
val := long(expressionValue).lsw;
|
||||||
if val <> expressionValue then
|
if val <> expressionValue then
|
||||||
if not stPtr^.isLong then
|
if not stPtr^.isLong then
|
||||||
Error(71);
|
expressionValue := val; {convert out-of-range value to (U)Word}
|
||||||
if stPtr = nil then
|
if stPtr = nil then
|
||||||
Error(72)
|
Error(72)
|
||||||
else begin
|
else begin
|
||||||
|
Reference in New Issue
Block a user