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

            Bug ID: 113338
           Summary: Valid Code Rejected, bind(C) procedure with pointer
                    argument
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: everythingfunctional at protonmail dot com
  Target Milestone: ---

The following example is rejected by gfortran, but should be valid.

Fortran Program:

program example
    use iso_c_binding

    implicit none

    type :: t
        integer :: i
    end type

    interface
        subroutine c_proc(x) bind(c)
            import t
            implicit none
            type(t), pointer, intent(in) :: x
        end subroutine
    end interface

    type(t), target :: x

    x%i = 42
    call c_proc(x)
contains
    subroutine f_proc(x) bind(c)
        type(t), pointer, intent(in) :: x

        print *, x%i
    end subroutine
end program

C code:

#include <ISO_Fortran_binding.h>

extern void f_proc(CFI_cdesc_t* x);

extern void c_proc(CFI_cdesc_t* x)
{
    f_proc(x);
}

Is rejected with the following messages:

main.f90:11:27:

   11 |         subroutine c_proc(x) bind(c)
      |                           1
Error: Variable ‘x’ at (1) is a dummy argument to the BIND(C) procedure
‘c_proc’ but is not C interoperable because derived type ‘t’ is not C
interoperable
main.f90:23:23:

   23 |     subroutine f_proc(x) bind(c)
      |                       1
Error: Variable ‘x’ at (1) is a dummy argument to the BIND(C) procedure
‘f_proc’ but is not C interoperable because derived type ‘t’ is not C
interoperable

But the standard says:

> 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 allocatable, assumed-shape, assumed-rank, or a 
> pointer without the CONTIGUOUS attribute, and the formal parameter is a 
> pointer to CFI_cdesc_t

I.e., that argument need not be interoperable, because it has the pointer
attribute.
  • [Bug fortran/11333... everythingfunctional at protonmail dot com via Gcc-bugs

Reply via email to