[fpc-pascal] SetLength warnings - request

Martok listbox at martoks-place.de
Wed Jan 2 18:31:17 CET 2019


Am 02.01.2019 um 17:23 schrieb Sven Barth via fpc-pascal:
> Even in Delphi situations can occur where a dynamic array Result variable is
> non-Nil already upon entry and then SetLength will simply manipulate that
> preexisting array instead of working on a new array. In most cases that probably
> won't have a real effect as the array is either set to empty anyway or all it's
> elements are initialized by the function. That doesn't change the fact however
> that the behavior *is* there and can potentially lead to hard to debug problems. 

> Anything else can potentially be a bug lying in wait. 
Again, why is this not changed?

Clearly we can't change Delphi, but there is no real reason not to be better
than them. And it *is* undocumented for them, so we'd still be compatible, just
compatible-on-the-safe-side.

Document that managed variables are initialized (this also means calling
operator Initialize) regardless of global/local, make sure that they always are
(which is currently only missing the Result pseudovariable), and bam - problem
solved.
Shouldn't even cause any extra code to be emitted since it's either already
there or could be eliminated as a dead store.

-- 
Regards,
Martok





More information about the fpc-pascal mailing list