This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]