Re: Was this a bug



Richard Maine <nospam@xxxxxxxxxxxxx> wrote:
David Flower <DavJFlower@xxxxxxx> wrote:
(snip)
MODULE FRED
INTEGER, ALLOCATABLE :: IARRAY(:)
END MODULE
...
USE FRED
CALL SUB ( IARRAY(7) )
...
SUBROUTINE SUB ( I )
USE FRED
(Reallocate IARRAY larger, making lower bound more negative)

Yes. It is illegal per the standard. Not worth looking up the exact
words, but there is a restriction against a subroutine defining or
undefining something that is an actual argument; you can only do such
definition or undefinition through the corresponding dummy. You mention
that you "reallocate" the array. The first step of such a reallocation
is a deallocation, which undefines the array and thus the actual
argument in question.

Isn't it illegal even without reallocation, from aliasing rules?

With reallocation it is somewhat worse, though, as the address of
IARRAY may change, and that address was likely passed to SUB.

Making the lower bound more negative has a high probability
of moving the array. It might, then fetch I as IARRAY(7)
from the previous location. Call by value result would store
the value back in unallocated memory.

-- glen
.