access to forward-declared base type of pointer gives wrong results in same type block
Original Reporter info from Mantis: Gerold Veith
-
Reporter name: Gerold Veith
Original Reporter info from Mantis: Gerold Veith
- Reporter name: Gerold Veith
Description:
In the test program below High(Bar) is 0.
But it should be SizeOf(Integer) * (10 - 0 + 1) => on 32Bit: 44
I guess this happens, because the forward-declaration of TFoo is only resolved at the end of the type block (here at the "var").
The same result occurs if the order of the declarations of TFoo and TBar is reversed in the program.
It should either use the correct value (44 on 32bit for example) or produce an error (or at least a warning) that the type PFoo/TFoo is not (completely) defined.
In case the order of the declarations is reversed it should always be the error.
Steps to reproduce:
program TestForwardDeclarations;
{$mode objfpc}{$H+}
type
PFoo = ^TFoo;
TFoo = array[0..10] of Integer;
TBar = array[0..SizeOf(PFoo(nil)^)] of Integer;
var
Bar: TBar;
begin
if High(Bar) <> SizeOf(TFoo) then
WriteLn('Error: ', High(Bar), ' <> ', SizeOf(TFoo));
end.
Additional information:
If it is any relief, in Delphi, it seems, always the size 4 (SizeOf(Integer)?) is used, instead of the 0 in FPC.
Mantis conversion info:
- Mantis ID: 14354
- Platform: Win32
- Version: 2.2.2
- Fixed in version: 2.6.0
- Fixed in revision: 16112 (#db8a6774)