(Re)allocation of allocatable arrays on assignment - F2003

Paul Richard Thomas paul.richard.thomas@gmail.com
Sat Oct 9 09:27:00 GMT 2010


Dear Tobias,

Thanks for giving it a whirl.

> a) The test case uses "N" (implicitly defined) but does not initialize it to
> 15

Ah yes - a cut and paste error.  Evidently, every time I tried it, N
was >=15 :-)

> b) The test case fails for me for:
>
>  if (any (b .ne. a)) call abort
>
> as "a(10)" == 0 while "b(10)" == -134744073.

That is very mysterious.

>
> c) Allocatable scalars do not work (unhandled)

Indeed, I have not turned to allocatable scalars yet.  Also, although
I have not tried it, I am rather sure that some cases of characters
will fail.
>
> d) The bounds are wrongly set; for
>  integer :: b(2:4)
>  a = b
> the result is:
>        a.dim[0].lbound = 1;
>        a.dim[0].ubound = 3;
> However, the lower bound should be the one of the expression, i.e. "2:4"
> ("it is then allocated with... if expr is an array, the shape of expr with
> each lower bound equal to the corresponding element of LBOUND (expr).")
>

This was an issue with allocatable components.  Is this true for all
expressions or just variables and parameters?  I cannot recall... I'll
take a look at the standard.

> e) If the variable is unallocated, the bound values are not set but still
> they are used:
>  struct array1_integer(kind=4) a;
>      a.data = 0B;
>        D.1531 = a.offset;
>        D.1532 = a.dim[0].lbound;
>        D.1534 = D.1532 + -1;
>        D.1530 = (integer(kind=4)[0:] * restrict) a.data;
>          S.0 = 1;
>              (*D.1530)[(S.0 + D.1534) + D.1531] = b[S.0 + -1];
>
> Thus, one accesses the freshly allocated a.data at "a.data[(0 + <uninit>) +
> <uninit>)" -- however, that only works if "a.offset" and "a.lbound" are
> either by chance or via SAVE initialized to 0.

Ah yes, that must be the reason for the problem that I commented upon.
 You have saved me a bit of diagnosis.

>
> f) The following is valid Fortran 2008 (LHS polymorphic but allocatable),
> invalid Fortran 2003 and currently rejected (LHS is polymorphic):
>
> type t
>  integer :: x
> end type t
> type, extends(t) :: t2
>  integer :: j(4)
> end type t2
> class(t), allocatable :: y(:)
> y = [ t2(x=3,j=[1,2,3,4]) ]
> end

I'll do F2003 first.  If you recall the second of the two commitments
that I made was on OOP arrays; although I would be happy to sort out
F2003 there :-)

The most worrying of the above is the failure of
>  if (any (b .ne. a)) call abort

I don't quite know who to deal with that since it works for me.  I had
better check that the version of the patch that I posted is the
correct one......

Anyway, once again, thanks for giving it a try.  The reason for
posting it was to indicate progress.

Paul



More information about the Fortran mailing list