[Bug fortran/53851] New: Automatic silent allocation/deallocation of allocatable variables in several instances

2012-07-04 Thread liluli2011 at gmail dot com
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: unassig...@gcc.gnu.org
ReportedBy: liluli2...@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


[Bug fortran/53851] Automatic silent allocation/deallocation of allocatable variables in several instances

2012-07-06 Thread liluli2011 at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53851

--- Comment #3 from liluli2011 at gmail dot com 2012-07-06 16:06:12 UTC ---
Thank you Harald and karql. I should have read the new (or not so new) features
of the 2003 standard before posting instead of relying so much on the
comparison with ifort. In fact, (re)allocation on assignment does make sense,
although it can be also potentially dangerous. Thus it is convenient that there
are ways to disable it.


[Bug fortran/53851] Automatic silent allocation/deallocation of allocatable variables in several instances

2012-07-06 Thread liluli2011 at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53851

--- Comment #4 from liluli2011 at gmail dot com 2012-07-06 16:09:08 UTC ---
Thank you Harald and karql. I should have read the new (or not so new) features
of the 2003 standard before posting instead of relying so much on the
comparison with ifort. In fact, (re)allocation on assignment does make sense,
although it can be also potentially dangerous. Thus it is convenient that there
are ways to disable it.