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

            Bug ID: 111952
           Summary: Allocatable of derived type with DTIO is not
                    deallocated going out of scope
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: federico.perini at gmail dot com
  Target Milestone: ---

Test program: 

```
module v
   public :: with_allocatable
   type, public :: t
      real :: r
      contains
         procedure, private :: wf
         generic :: write(formatted) => wf
   end type t
   contains
   subroutine wf(this, unit, iotype, v_list, iostat, iomsg)
      class(t), intent(in) :: this
      integer, intent(in) :: unit
      character(len=*), intent(in) :: iotype
      integer, intent(in) :: v_list(:)
      integer, intent(out) :: iostat
      character(len=*), intent(inout) :: iomsg
   end subroutine wf         

   subroutine with_allocatable(n)
      integer, intent(in) :: n
      type(t), allocatable :: x(:)
      allocate(x(n))
   end subroutine with_allocatable

end module v

program test
   use v
   call with_allocatable(10)
   call with_allocatable(10) ! crash 
end program     
```

Upon the second call, the following runtime error is returned: 
```
At line 22 of file /app/example.f90
Fortran runtime error: Attempting to allocate already allocated variable 'x'
```

I believe this may be related to bug 106731. 
On Compiler Explorer (https://godbolt.org/z/d3vfdhn6n), it seems like the issue
is present also on gfortran versions prior to that fix.

Reply via email to