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: unassig...@gcc.gnu.org ReportedBy: bur...@gcc.gnu.org CC: pa...@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