https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109500

--- Comment #3 from kargl at gcc dot gnu.org ---
(In reply to Leandro Lupori from comment #2)
> Thanks for the quick response.
> 
> What if 'f' is changed to this:
> 
> function f()
>   integer, allocatable :: f
> 
>   allocate(f)
>   f = 123
>   deallocate(f)
> end function
> 
> Is the program still invalid? gfortran -Wall doesn't complain in this case,
> but I get a SIGSEGV instead of SIGABRT.

Yes.  It is not valid Fortran.  You've deallocated 'f', which means
the function result is not set.

Your example is also likely why the warning is hidden 
behind -Wall.  I suspect there are too many false
positive and with your code you're getting a false
negative (ie., no warning).

  F2023, p. 331

  15.5.3 Function reference

  A function is invoked during expression evaluation by a
  function-reference or by a defined operation (10.1.6).
  When it is invoked, all actual argument expressions are
  evaluated, then the arguments are associated, and then
  the function is executed. When execution of the function
  is complete, the value of the function result is available
  for use in the expression that caused the function to be
  invoked.

In 'print *, is_allocated(f())', the function-reference is
evaluated.

  F2023, p. 336

  On completion of execution of the function, the value
  returned is that of its function result. ...
  If the function result is not a pointer, its value shall
  be defined by the function.


19.6.6 Events that cause variables to become undefined
...
(10) When an allocatable entity is deallocated, it becomes undefined.

Reply via email to