This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/56201] New: Realloc on assignment: Wrong code when assigning a zero-sized array
- From: "burnus at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 04 Feb 2013 12:19:02 +0000
- Subject: [Bug fortran/56201] New: Realloc on assignment: Wrong code when assigning a zero-sized array
- Auto-submitted: auto-generated
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