fpc/tests/webtbs/tw28279.pp
Jonas Maebe 9118146bc1 * ensure that managed out-parameters are processed before any other
parameters:
   1) since they are finalised on the caller side, if that same value
      is passed as a value parameter as well and its reference count
      was 1, then the value parameter will contain an invalid pointer
   2) since finalisation involves a call, for optimal code generation
      purposes they should also be evaluated first
    (mantis #28279, #28390)

git-svn-id: trunk@31201 -
2015-07-10 22:04:35 +00:00

59 lines
982 B
ObjectPascal

{$mode objfpc}
program Project1;
var
value_para_must_be_empty: boolean;
procedure Foo1(a: AnsiString; out b: AnsiString);
begin
WriteLn(length(a)); WriteLn(length(b));
if value_para_must_be_empty and
(a<>'') then
halt(2);
if b<>'' then
halt(3);
b := 'a';
end;
procedure Foo2(out a: AnsiString; b: AnsiString);
begin
WriteLn(length(a)); WriteLn(length(b));
if a<>'' then
halt(4);
if value_para_must_be_empty and
(b<>'') then
halt(5);
b := 'a';
end;
var s1: AnsiString;
function f: ansistring;
begin
{ the s1 parameter must be finalised first to prevent accidental use of
the finalised value }
if s1<>'' then
halt(1);
f:='a';
f:=f+'b';
end;
const x: AnsiString = 'abcde';
begin
value_para_must_be_empty:=true;
s1 := copy(x,2,3)+'x';
Foo1(s1,s1);
s1 := copy(x,2,3)+'x';
Foo2(s1,s1);
value_para_must_be_empty:=false;
s1 := copy(x,2,3)+'x';
Foo1(f,s1);
s1 := copy(x,2,3)+'x';
Foo2(s1,f);
end.