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

--- Comment #10 from Tobias Burnus <burnus at gcc dot gnu.org> ---
First, the committed patch handles something which was wrong with *and* without
BIND(C) and fixed a genuine bug.

 * * *

(In reply to kargl from comment #9)
> Please commit the patch in comment #7.  character(kind=4) is not interoperable
> (unless C_CHAR is CHARACTER(KIND=4) which it isn't).  This is an extension and
> gfortran should flag.

While I concur that the example in comment 1 is not interoperable according to
the Fortran 2018 standard, I think the patch of comment 7 rejects too much (cf.
'(b)' below.)

Still, I think something should/could be done – hence, I did not close this PR.
Namely:

 * * *

For C interoperability, I think there are two parts to this:

(a.1) module m; character(kind=4) :: c; end module m
(a.2) subroutine foo(x) bind(C)
        character(kind=4) :: x

To both the following applies (F2018, 18.3.1 Interoperability of intrinsic
types):

"A Fortran intrinsic type with particular type parameter values is
interoperable with a C type if the type and kind type parameter value are
listed in the table on the same row as that C type. If the type is character,
the length type parameter is interoperable 
if and only if its value is one."

Hence, neither 'foo' nor 'c' are interoperable.


(b) subroutine bar(x, y, z) bind(C)
      character(kind=4,len=*) :: x
      character(kind=4) :: y(:)
      character(kind=4), allocatable :: z

This one is valid as F2018's "18.3.6 Interoperability of procedures and
procedure interfaces" states:

"A Fortran procedure interface is interoperable with a C function prototype if
...
(5) any dummy argument without the VALUE attribute corresponds to a formal
parameter of the prototype that is of a pointer type, and either
...
• the dummy argument is a nonallocatable nonpointer variable of type CHARACTER
with assumed character length and the formal parameter is a pointer to
CFI_cdesc_t,
• the dummy argument is allocatable, assumed-shape, assumed-rank, or a pointer
without the
CONTIGUOUS attribute, and the formal parameter is a pointer to CFI_cdesc_t, or
..."

Reply via email to