public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/113338] New: Valid Code Rejected, bind(C) procedure with pointer argument
@ 2024-01-11 18:48 everythingfunctional at protonmail dot com
  2024-01-11 19:56 ` [Bug fortran/113338] " anlauf at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: everythingfunctional at protonmail dot com @ 2024-01-11 18:48 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-01-29 17:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-11 18:48 [Bug fortran/113338] New: Valid Code Rejected, bind(C) procedure with pointer argument everythingfunctional at protonmail dot com
2024-01-11 19:56 ` [Bug fortran/113338] " anlauf at gcc dot gnu.org
2024-01-12  1:51 ` everythingfunctional at protonmail dot com
2024-01-12 20:23 ` [Bug fortran/113338] [F2018] " anlauf at gcc dot gnu.org
2024-01-29 17:59 ` anlauf at gcc dot gnu.org

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).