I know it's not good to reply to your own diskusion, but there is new info:
Subject closed:
Other people have already answered in the forum. See also the discussion on the fpc mailing list: http://lists.freepascal.org/pipermail/fpc-devel/2015-June/thread.html ("ref count issue with out param"). Your remark regarding the warning (or rather, why a warning that always works is impossible to add) is addressed in http://lists.freepascal.org/pipermail/fpc-devel/2015-June/035706.html
I am not so happy that the issue is marked resolved.
Because (i hope) there is an ongoing discusion about this.
Nobody seems to care about the point I try to make:
You start with a
function foo(aPar1:TSomething;var aPar2:TSomething):TSomethingElse;
You test is, release it.--> Valid.
SomeOne (else) uses your function.
while foo(s1,s1) do [...]
He tests his code, still valid.
Years later the compiler has a new feature (Hints and out-params)
You came across your old function
and since you only write to aPar2 (and you want get rid of the annoying hint that the variable is not initialized.
you change the var to out.
by this you make someone else's code WRONG.
I think that some deserves a warning that his formerly valid code may have problems now.
I am fully aware that you can not warn everybody with everything. But a warning when a parameter is obviously handed twice (or more) to a routine with one of which is an "out" would be a start.
[...]
Found Workaround3: declare the function inline
And also a function should not change it's (obvious) behavior when declared inline (or not). If you are a good programmer then you normally put your "inline" in a compiler
-def like
function foo([...]):TSomething; {$IFDEF SUPPORTS_INLINE}inline;{$ENDIF}
The next point is:
You use this function:
var p1,p2:string;
[...]
p1:='ABCDE';
while foo(p1,p2) do
p1:=p2;
[...]
That is obviously VALID code.
then someone ads a new fancy optimization to the compiler
Namely: when a variable is only used to fill a parameter it can be replaced with that variable, to get rid of an obvious unnecessary copy.
The formerly valid code starts to behave erratic. which is a very unpleasant thing, if you try to debug a large project.
At some point
i := i + 1;
is not valid anymore because you use variable i as an input and also as a target of that code.
(just kidding)