This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [4.5, Patch, Fortran] PR 36704: Procedure pointer as function result
Janus Weil wrote:
> Hi Mikael,
>
> first off: thanks a lot for your review!
>
>> Now, the details.
>>
>> About this:
>> +
>> + if (add_hidden_procptr_result (sym) == SUCCESS)
>> + sym = sym->result;
>> +
>> Is it really needed in the case of a subroutine ?
>
> Actually, yes. This snippet appearing inside gfc_match_subroutine is
> needed for cases like the one labeled "h" in my test case, where a
> function returns a pointer to a subroutine, and the subroutine is
> specified by an INTERFACE statement.
Yes, I missed that.
>
>
>> + sym = sym->result;
>> sym->name becomes invalid. Try this for example:
>> --- proc_ptr_13.f90 2008-12-08 16:44:13.000000000 +0100
>> +++ proc_ptr_13.f90.old 2008-12-08 16:44:08.000000000 +0100
>> @@ -57,7 +57,7 @@
>> function f()
>> pointer :: f
>> interface
>> - integer function f(x) bind(c)
>> + integer function f(x)
>> integer :: x
>> end function
>> end interface
>
> Hm, good point. In the error message the wrong name appears. However,
> I'm not sure how to fix this. Anyway I need to replace the symbol by
> sym->result here, so that the rest of the function interface is
> applied to the result, not to the original function symbol.
>
> I don't really want to add an extra check like "if (strcmp
> ("ppr@",sym->name) ..." to every possible error message :(
>
> Ideas, anyone?
What about keeping the original name?
>
> I also found one other thing that was missing: Up to now I only
> included cases where the function gets assigned some value. However it
> is also possible to assign another procptr to the return value inside
> the function (see my new testcase "k"), which I fixed now.
>
> Am I missing anything else? I think all other uses of a procptr return
> value inside the returning function would be recursive. Or ambiguous
> in some way. Example:
>
> function f()
> procedure(real),pointer :: f
> f => ...
> print *,f()
> end function
>
> How would one interpret this? Which function is called in the print
> statement? The function that is the return value of f? Or the function
> f itself (recursively)? Is this example legal at all?
12.5.2.1
/If RESULT is specified, the name of the result variable of the
function is result-name and all occurrences of the function name in
execution-part statements in the scoping unit refer to the function
itself. If RESULT is not specified, the result variable is function-name
and all occurrences of the function name in execution-part statements in
the scoping unit are references to the result variable./
I guess it is valid, and the f referenced is the (pointer) return value.
If one wants the function to be (recursively) called, I guess it would
need to use a result suffix. At least, that's what I would do.
Mikael