This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/40440] Automatic deallocation component of DT function return value



------- 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]