No, out-parameters of managed types lead to the finalization of the corresponding variable while var does not.
In Delphi it does not, with long strings. It is inconsistent and frankly is a bug.
But is FPC aimed at bug-compatibiltiy with Delphi or feature-compatibility?
Regarding the calling ABI we're indeed trying for compatibility, because user code might rely on this.
User code might rely on `Result` var value implicitly passed form caller to callee??? Not a hackerish showing off, but actual production code?
Ж8-[...]
Personally I, when developing apps, was only hit by the opposite, when i was forgetting to set Result in some code paths, and the compiler did not throw a error at me. It was a type bugs rather hard to reproduce and find :-(
Why can not FPC make Result of funcitons out-parameteer instead of var-parameter?
...cause existing code (for example the RTL itself) relies on this behaviour
RTL relies upon Result var pre-initialized with value??? Relies on a de facto compiler bug, albeit old one? I don't want to believe it.
Second this would result in a performance impact, cause the corresponding variable would be finalized even if it might not be needed.
There is always a code flow analysis w.r.t. "use of uninitialized variable" - it can be used to choose if to pre-Finalize or not. This would be some complication, but not much.
And i do not think "pre-Finalize always" would have an impact really. You do finalizing anyway when you assign something to Result. So it would be just split into two operations. And the assignments then would only have one nil-check added to the flow. Compared to the asisgnment itself (CPU bus locking for ARC) it does not seem much delay adding one extra nil-comparison to the function control flow.
The only real performance impact would be when developer forgot to assign Result at all, but in my view that constitutes a bug that should be fixed anyway. However, you seem to think that intentional non-assigning Result for long strings is a valid implementation of functions.