This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/53851] New: Automatic silent allocation/deallocation of allocatable variables in several instances
- From: "liluli2011 at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 04 Jul 2012 10:29:37 +0000
- Subject: [Bug fortran/53851] New: Automatic silent allocation/deallocation of allocatable variables in several instances
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53851
Bug #: 53851
Summary: Automatic silent allocation/deallocation of
allocatable variables in several instances
Classification: Unclassified
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: liluli2011@gmail.com
I have found that gfortran (v4.6) performs implicit allocation and deallocation
of allocatable variables when these are assigned values using a constructor,
like in the example code below. I wonder whether this is intentional and
complying with the Fortran standard. I have checked with ifort and there seems
not to be such implicit allocation/deallocation for it (neither gfortran nor
ifort compilers give compilation or execution error messages in connection with
the example below, but the respective outputs are very different).
implicit none
integer, allocatable, dimension(:) :: vec
integer, allocatable, dimension(:,:) :: aa
integer :: i
! allocate ( vec(20) )
vec = (/ ( 1, -1, i = 1, 20 ) /)
print*, "vector size", size(vec)
! allocate ( aa(4,4) )
aa = reshape ( vec , shape = (/ 4,4 /) ) ! It is like reshape implies a
silent previous allocation of an otherwise not explicitly allocated variable
print*, "array shape", shape(aa)
do i = 1, 4
print*, aa(i,:)
end do
! deallocate ( aa ) ; allocate ( aa(5,5) )
aa = reshape ( vec , shape = (/ 5,5 /) ) ! Now the variable is reallocated
implicitly to a new shape without having been explicitly deallocated
print*, "new array shape", shape(aa)
do i = 1, 5
print*, aa(i,:)
end do
vec = (/ ( 1, -1, i = 1, 25 ) /) ! same for this rank-1 array
print*, "new vector size", size(vec)
end program