[fpc-devel] 019605: Safety check for "const s: string" (similar to Range or Overflow checks)
Florian Klämpfl
florian at freepascal.org
Thu Jun 23 22:44:12 CEST 2011
Am 23.06.2011 22:31, schrieb Martin:
>
> This is about finding screwups of the refcount. The data modification
> detection of strings is a side effect only.
>
Why is a "screwup" of the ref. count a problem? It is only a problem if
it gets 0 and the string is disposed?
>
>
>
> Anyway, I repeat. I do not try to detect, if the string content was
> changed => that is a side effect
>
> I try to catch issues with the refcount.
>
> They do not happen, if the string is part of a const param record
>
Why not?
This ...
{$h+}
type
tr = record
s : string;
end;
var
r : tr;
procedure proc;
begin
r.s:='1234';
end;
procedure Foo(const r : tr);
begin
proc;
// r.s is invalid now ...
end;
begin
setlength(r.s,10);
Foo(r);
end.
... hurts as well because r is passed by value because it is small.
More information about the fpc-devel
mailing list