public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jrfsousa at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/94110] Erroneous code compiling
Date: Tue, 14 Apr 2020 15:29:34 +0000	[thread overview]
Message-ID: <bug-94110-4-chhpAbr0IZ@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-94110-4@http.gcc.gnu.org/bugzilla/>

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

  parent reply	other threads:[~2020-04-14 15:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-09 20:27 [Bug fortran/94110] New: " jrfsousa at gmail dot com
2020-04-13 17:19 ` [Bug fortran/94110] " tkoenig at gcc dot gnu.org
2020-04-14 15:29 ` jrfsousa at gmail dot com [this message]
2020-04-14 16:54 ` [Bug fortran/94110] Passing an assumed-size to an assumed-shape argument should be rejected tkoenig at gcc dot gnu.org
2020-09-01 13:08 ` jrfsousa at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-94110-4-chhpAbr0IZ@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).