[Bug fortran/56201] New: Realloc on assignment: Wrong code when assigning a zero-sized array

burnus at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Feb 4 12:19:00 GMT 2013


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

             Bug #: 56201
           Summary: Realloc on assignment: Wrong code when assigning a
                    zero-sized array
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: burnus@gcc.gnu.org
                CC: pault@gcc.gnu.org


Reported by Vladimír Fuka at
https://groups.google.com/d/topic/comp.lang.fortran/Qhrw1XU7U8o/discussion


Assigning a zero-sized array to an *unallocated* allocatable works;
re-assigning to a zero-sized array works as well. But:

Assigning a zero-sized array to an allocated non-zero-size array wrongly
deallocates the array.


real, allocatable :: r(:)

r = [real :: ]         ! Zero-sized array
print *, allocated(r)  ! OK: Allocated
print *, size(r)
if (.not.allocated(r) .or. size(r) /= 0) call abort()

r = [real :: ]         ! Zero-sized array
print *, allocated(r)  ! OK: Allocated
print *, size(r)

deallocate(r)   ! REALLOCATE to nonzero sized
allocate(r(5))  !

r = [real :: ]         ! <<<<<<<<< Zero-sized array
print *, allocated(r)  ! <<<<<<<<< ERROR: Not allocated
print *, size(r)
if (.not.allocated(r) .or. size(r) /= 0) call abort()
end



More information about the Gcc-bugs mailing list