http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46487

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 2010-11-16 
13:49:58 UTC ---
Well, the problem is actually simple:

program test
  implicit none
  integer :: b
  b = func()
contains
  function func ()
    integer, allocatable ::  func
    allocate(func)
    func = 5332
  end function func
end program test

The function "func" returns the allocatable scalar as:
  return __result_func;

In the main program, one has:
  b = *func ();
or - if "b" is allocatable:
  *b = *func ()

However, the proper method should be:
  {
     tmp = func()
     b = *tmp
     free (tmp);
  }

(Or replace: "free (tmp)" by "if (tmp != NULL) free(tmp)", which is identical
as free also accepts NULL.)

For arrays, it currently works without this detour as there the argument is
passed by value; doing likewise for allocatable scalars would be one -- ABI
breaking -- alternative.

Reply via email to