https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94110

--- Comment #2 from José Rui Faustino de Sousa <jrfsousa at gmail dot com> ---
Hi Thomas!

IIRC assumed-size arrays are implemented has packaged descriptor less arrays.
In order to point to them or to pass them to a procedure expecting an assumed
or deferred-shape array one has to create an array descriptor. To create such
descriptor one must know the array bounds, which one does not for assumed-size
arrays.

Fortran pointers, unlike their C brethren, also carry bound information and
AFAIK one can not have an array, or a pointer to an array, which has undefined
bounds (what would the intrinsics like shape, ubound and size return?).

So in order to point to, or pass, an assumed-size array to a procedure
expecting an assumed or deferred-shape array the user must provide the missing
bound information, which can be done by specifying an array section effectively
creating an explicit-shape array (see PR94022).

So if one has an assumed-size array “arr”, rank 3, and a procedure “sub”, with
either an assumed or deferred-shape array dummy argument, one can do:

a = arr(:,:,1:n)
p => arr(:,:,1:n)
call sub(arr(:,:,1:n))

Assuming appropriate declarations of both “a” and “p”.
But one can not address the whole assumed-size array:

a = arr ! already generates error 
p=> arr ! already generates error
call sub(arr) ! The case here

What IMHO might be relevant and that I could find in the standard:

8.5.8.3 Assumed-shape array (par 1):
“An assumed-shape array is a nonallocatable nonpointer dummy argument array
that takes its shape from its effective argument.”

8.5.8.5 Assumed-size array:

C835:
“An object whose array bounds are specified by an
implied-shape-or-assumed-size-spec shall be a dummy data object or a named
constant.”

(par. 4):
“An assumed-size array shall not appear in a context that requires its shape.”

9.5.2 Whole arrays (par. 2):
“An assumed-size array (8.5.8.5) is permitted to appear as a whole array in an
executable construct or specification expression only as an actual argument in
a procedure reference that does not require the shape.”

10.1.2.2 Primary:
C1002 (R1001) The designator shall not be a whole assumed-size array.

10.2.2.2 Syntax of the pointer assignment statement C1025:
“The expr shall be a designator that designates a variable with either the
TARGET or POINTER attribute and is not an array section with a vector
subscript, or it shall be a reference to a function that returns a data
pointer.”

15.5.2.4 Ordinary dummy variables (par. 16):
“If a dummy argument is an assumed-shape array [...] the actual argument shall
not be an assumed-size array.”

15.5.2.7 Pointer dummy variables (par. 2):
“If the dummy argument does not have INTENT (IN) [...]. Otherwise, the actual
argument shall be a pointer or a valid target for the dummy pointer in a
pointer assignment statement. If the actual argument is not a pointer, the
dummy pointer becomes pointer associated with the actual argument.”

Should the compiler diagnose the error? Well it seems possible to do it and
error reports are always better than surprising results... Is it required to? I
would believe so... But I am interested on having the compiler hand hold me as
much as possible... ;-)

Best regards,
José Rui

Reply via email to