[fpc-devel] Const optimization is a serious bug
Max Vlasov
max.vlasov at gmail.com
Mon Jul 11 06:30:42 CEST 2011
On Mon, Jul 11, 2011 at 4:45 AM, Chad Berchek <ad100 at vobarian.com> wrote:
>
> 1. It seems that if a string is a (non-const) local variable it should be
> safe. I base this on the following reasoning:
>
looks like it's not:
procedure TForm1.Button1Click(Sender: TObject);
var
S: string;
procedure SideEffectCall;
begin
SetLength(S, 0);
end;
function CalcSomething(const T: string): integer;
begin
Result:=0;
SideEffectCall;
MessageDlg(T, mtInformation, [mbOk], 0); // crash here
end;
begin
S:='12345678901234567890';
S:=S + S;
CalcSomething(S);
end;
More information about the fpc-devel
mailing list