[fpc-devel] Const optimization is a serious bug

Hans-Peter Diettrich DrDiettrich1 at aol.com
Mon Jul 11 08:48:44 CEST 2011


Max Vlasov schrieb:
> 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;

Replace it by
   S: TObject;
and
   S.Free
to see that you can force any undesireable effect with reference types 
by alias.

DoDi




More information about the fpc-devel mailing list