Reported by Hallvard Vassbotn; checked by Rune Moberg
The following three files demonstrate the problem:
LOCBUG.DPR:
program LocBug;
uses
LocBugA;
begin
end.
LOCBUGA.PAS:
unit LocBugA;
interface
{$HINTS OFF} {$WARNINGS OFF} {$ALIGN OFF}
type
TObjectA = class
private
UnusedA: integer; // Should not get hint, and we don't
public
procedure Destroy; // Should not get warning, and we don't
end;
TRecA = record // SizeOf(TRecA) should be 5, and it is
A: char;
L: longint;
end;
implementation
uses
LocBugB;
{.$HINTS OFF} // Remove dots to work around the buggy behavior
{.$WARNINGS OFF}
type
TObjectB = class
private
UnusedB: integer; // Should not get hint, but we do in D3 (sometimes)
public
procedure Destroy; // Should not get warning, but we do (sometimes)
end;
{.$ALIGN ON} // If you remove the dot, you will get an invalid typecast below
TRecB = record // SizeOf(TRecA) should be 5, and it is
A: char;
L: longint;
end;
procedure TObjectA.Destroy; begin end;
procedure TObjectB.Destroy;
var
A: TRecA;
begin
TRecB(A).L := 123; // This is Ok because SizeOf(TRecA) = SizeOf(TRecB)
end;
end.
LOCBUGB.PAS:
unit LocBugB;
interface
implementation
{$HINTS ON} {$WARNINGS ON} {$ALIGN ON}
end.
The problem is that whenever the compiler re-compiles the LocBugB unit,
the HINTS and WARNINGS are turned on and kept on from the point the unit
is used in other units. The same does not happen with the ALIGN directive.
So the "(sometimes)" in the comments above refers to whenever the LocBugB
unit is re-compiled.
This means that to make sure HINTS and WARNINGS are turned off in a
given unit you have to include {$HINTS OFF} and {$WARNINGS OFF} directives
after the uses clause in the interface section _and_ after the uses clause
in the implementation section.
This bug might seem innocent, but in combination with
the very dangerous hints-bug
I've written about before (it causes an access
violation that forces you to close down D3), this new bug is very annoying.
One of the suggested work-arounds for the first bug was to turn off hints
for all code. This new bug means that this is not a simple task. |