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

            Bug ID: 109575
           Summary: Implement runtime check for valid function result
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: anlauf at gcc dot gnu.org
  Target Milestone: ---

Split off from the discussion in pr109500: consider

program main
  implicit none
  integer, allocatable  :: p
  p = f()          ! <- this assignment may fail
  print *, allocated (p)
contains
  function f()
    integer, allocatable :: f
    allocate (f, source=42)
    deallocate (f) ! <- this renders the function invalid
  end function
end

This code is invalid as the function result must be defined:

F2018:15.6.2.2

On completion of execution of the function, the value returned is that
of its function result. If the function result is a data pointer, the
shape of the value returned by the function is determined by the shape
of the function result when the execution of the function is completed.
If the function result is not a pointer, its value shall be defined by
the function. If the function result is a pointer, on return the pointer
association status of the function result shall not be undefined.


A runtime check that can detect the failing assignment needs to check
that the function result is defined when the function returns.

Reply via email to