This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/40440] Automatic deallocation component of DT function return value
- From: "burnus at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 18 Jun 2009 14:45:02 -0000
- Subject: [Bug fortran/40440] Automatic deallocation component of DT function return value
- References: <bug-40440-15192@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #8 from burnus at gcc dot gnu dot org 2009-06-18 14:45 -------
> I am not sure that your testcase should be allowed at all! I am not sure that
> I understand what it means.
I think it is valid and not different from:
integer, pointer :: ptr
allocate(ptr)
ptr = 5
call f(ptr)
where you don't pass the pointer "ptr" to "f" but the target of pointer "f".
My example is invalid, however, as I never set the return value. Add
allocate(func)
if you want. That should make it valid as one now has a pointer target. But it
shouldn't matter regarding the bug. (The not-needed "target" attribute can also
be removed.)
Regarding the big program:
function f(tgt)
integer,target :: tgt
f => tgt
end function f
I am not sure that using "tgt" as return value is valid; I think as soon as one
leaves "f", the "tgt" dummy ceases to exist, which would make it invalid. But I
might be wrong and it is valid. In practice, it should work if the actual
argument is either in static memory or one uses the pointer while the target is
still on the stack (or on the heap).
(If one wants to check the validity, one needs to read all about pointers,
targets and argument association - and maybe scope - in the standard.)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40440