http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47051

--- Comment #4 from Dominique d'Humieres <dominiq at lps dot ens.fr> 2010-12-23 
15:13:46 UTC ---
I have raised a similar question in

http://gcc.gnu.org/ml/fortran/2010-11/msg00004.html answered in the following
posts in this thread.

The relevant part of the standard (from f2008 draft) is

7.2.1.3 Interpretation of intrinsic assignments

...

3 If the variable is an unallocated allocatable array, expr shall have the same
rank. If the variable is an allocated allocatable variable, it is deallocated
if expr is an array of different shape, any of the corresponding length type
parameter values of the variable and expr differ, or the variable is
polymorphic and the dynamic type of the variable and expr differ. If the
variable is or becomes an unallocated allocatable variable, it is then
allocated with
 if the variable is polymorphic, the same dynamic type as expr,
 each deferred type parameter equal to the corresponding type parameter of
expr,
 if the variable is an array and expr is scalar, the same bounds as before,
and
 if expr is an array, the shape of expr with each lower bound equal to the
corresponding element of
LBOUND (expr).
NOTE 7.36
For example, given the declaration
CHARACTER(:),ALLOCATABLE :: NAME
then after the assignment statement
NAME = 'Dr. '//FIRST_NAME//' '//SURNAME
NAME will have the length LEN(FIRST NAME)+LEN(SURNAME)+5, even if it had
previously been
unallocated, or allocated with a dierent length. However, for the assignment
statement
NAME(:) = 'Dr. '//FIRST_NAME//' '//SURNAME
NAME must already be allocated at the time of the assignment; the assigned
value is truncated or blank
padded to the previously allocated length of NAME.

For which a strict reading of " If the variable is or becomes an unallocated
allocatable variable, ... the shape of expr with each lower bound equal to the
corresponding element of
LBOUND (expr)." support this PR since a is not deallocated. If this reading is
right it will be a very strong restriction for "reallocate on assignement":

 INTEGER, DIMENSION(:), ALLOCATABLE :: a,b,c,d
 ALLOCATE(a(-1:1),b(1:3),c(2:3),d(3:6))
 b=0
 c=0
 d=0
 a=b
 write(6,*) LBOUND(a), size(a)
 a=c
 write(6,*) LBOUND(a), size(a)
 a=d
 write(6,*) LBOUND(a), size(a)
END

will give

          -1           3
           2           2
           3           4

Note that there are two work-around:
(1) compile with -fno-realloc-lhs,
(2) use a(:).

Reply via email to