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

--- Comment #13 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
On Tue, Oct 18, 2022 at 10:40:59AM +0000, burnus at gcc dot gnu.org wrote:
> 
> (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.

I'm confused by what you are trying to show with (a.1).
The standard has "If the length is not specified in a
char-selector or a * char-length, the length is 1.", so
that last sentence is no relevant.  Moreover, there is
no C binding issue as you did not write

module m
   character(kind=4), bind(c) :: c
end module m

gfortran accepts the above when it should be rejected
because of

C820 A variable with the BIND attribute shall be interoperable (18.3).

For (a.2), this should also be rejected per

C1556 A variable that is a dummy argument of a procedure that has ar
   proc-language-binding-spec shall be assumed-type or of interoperable
   type and kind type parameters.

> (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:
> 

It's not valid per C1556 above and 

C1555 If proc-language-binding-spec is specified for a procedure, each
   dummy argument of type CHARACTER with the ALLOCATABLE or POINTER
   attribute shall have deferred character length.

Reply via email to