I hope I have detailed enough?
I still had to guess quite a bit. A simple program I can stuff into the compiler is quite essential! Nevertheless I came up with the following:
program trangeerr;
{$mode delphi}
const
EDIT_TRUE = $FFFFFFFFF; // <--- typo (I did it on purpose)
var
EditMode : LongWord; // Byte or Word - ignored if not more LongWord
const
ACTIVE = 2;
type
TEdit = record
Flags: LongWord;
end;
procedure Test;
const
EditOne = 1;
var
newEdit: array[0..1] of TEdit;
begin
//if not (EditMode and EDIT_TRUE) = 0 then
begin
EditMode := EditMode or EDIT_TRUE; // <-- work!!! always
EditMode := EditMode or $100000000; // <-- when debugging is enabled, the dimension
// checking code is inserted next
// and even if the program was working, it will not work when debugging
// (overflow enabled)
newEdit[EditOne].Flags := newEdit[EditOne].Flags or ACTIVE;
end;
end;
begin
Test;
end.
When compiled without
-Cr no error will happen, but if compiled with
-Cr there'll be a runtime error at line 27
as it should be.
It is right that the compiler currently does not complain at compile time, because it
can't. Once the compiler does the
EditMode or EDIT_TRUE operation (which will result in a value of native width, in the case of a 64-bit target indeed a 64-bit value) it no longer
knows that a constant was involved and thus it
can't generate an error at compile time when that value is assigned to
EditMode. And
EditMode or EDIT_TRUE is a valid expression even if
EDIT_TRUE is larger than the size of
EditMode.