FPC issues "unreachable code" warning wherever the mod operator is, when compiling in ISO mode
Original Reporter info from Mantis: juancdiaz
-
Reporter name: Juan Díaz
Original Reporter info from Mantis: juancdiaz
- Reporter name: Juan Díaz
Description:
When compiling in ISO mode a program that uses the mod operator, fpc issues warning "unreachable code" at lines and columns where this operator is. For instance, when compiling the following program in ISO mode
1 program ModOperatorTest(output);
2
3 var
4 n, remainder: 0..maxint;
5 digit: 0..9;
6
7 begin
8 n := 1024;
9 remainder := n mod 2;
10 writeln(n :1, ' mod 2 = ', remainder :1);
11 writeln;
12 writeln('The digits of ', n :1, ', beginning with the rightmost digit, 13 are:');
13 while n <> 0 do
14 begin
15 digit := n mod 10;
16 writeln(digit);
17 n := n div 10
18 end
19 end.
fpc -Miso ModOperatorTest.pas
FPC issues the following warnings:
ModOperatorTest.pas(9,18) Warning: unreachable code
ModOperatorTest.pas(9,18) Warning: Comparison might be always true due to range of constant and expression
ModOperatorTest.pas(9,18) Warning: unreachable code
ModOperatorTest.pas(15,16) Warning: unreachable code
ModOperatorTest.pas(15,16) Warning: Comparison might be always true due to range of constant and expression
ModOperatorTest.pas(15,16) Warning: unreachable code
Curiously, in this case the compiler also warns about a comparison possibly being always true due to range of constant and expression, which disappears when replacing only 0..maxint with integer, and not when replacing only the subrange 0..9 with integer. However, when compiling in other modes, the original code compiles with no warnings, neither the "unreachable code" one nor the "Comparison might be always true due to range of constant and expression" one, without requiring the replacement of either of the subrange types.
Steps to reproduce:
Copy the piece of code above, or write a program which uses the mod operator and compile in ISO mode from the command line.
fpc -Miso ModOperatorTest.pas
or
fpc -Miso myprogram.pas
Mantis conversion info:
- Mantis ID: 36341
- OS: Windows 7
- Platform: win32
- Version: 3.0.4
- Fixed in version: 3.2.0