Compiler generates wrong warning
While searching for invalid pointer casts I ran into a case where then compiler emits a warning where it shouldn't. The following code should only generate hints, but it emits 2 unexpected warnings. This happens with version 3.2.0 and trunk 99e449ea
program ptrcast;
{$mode objfpc}
var
P1, P2: Pointer;
d: Integer;
begin
P1 := nil;
P2 := P1 + 10;
d := (PtrUint(P1) - PtrUint(P2)) div 4; // emits hint
d := (PtrUint(P1) - PtrUint(P2)) mod 4; // emits hint and warning
end.
output:
C:\Users\marc\Lazarus>ppcx64.exe -vwhq ptrcast.pp
Hint: (11030) Start of reading config file C:\lazarus\fpc\3.3.1\bin\x86_64-win64\fpc.cfg
Hint: (11031) End of reading config file C:\lazarus\fpc\3.3.1\bin\x86_64-win64\fpc.cfg
Free Pascal Compiler version 3.3.1 [2021/09/28] for x86_64
Copyright (c) 1993-2021 by Florian Klaempfl and others
(1002) Target OS: Win64 for x64
(3104) Compiling ptrcast.pp
ptrcast.pp(13,9) Hint: (4055) Conversion between ordinals and pointers is not portable
ptrcast.pp(13,23) Hint: (4055) Conversion between ordinals and pointers is not portable
ptrcast.pp(15,9) Hint: (4055) Conversion between ordinals and pointers is not portable
ptrcast.pp(15,23) Hint: (4055) Conversion between ordinals and pointers is not portable
ptrcast.pp(15,9) Warning: (4056) Conversion between ordinals and pointers is not portable
ptrcast.pp(15,23) Warning: (4056) Conversion between ordinals and pointers is not portable
ptrcast.pp(7,3) Note: (5027) Local variable "d" is assigned but never used
(9015) Linking ptrcast.exe
(1008) 15 lines compiled, 0.1 sec, 34240 bytes code, 1604 bytes data
(1021) 2 warning(s) issued
(1022) 6 hint(s) issued
(1023) 1 note(s) issued
Edited by Marc Weustink