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

            Bug ID: 85448
           Summary: the compiler selects the wrong subroutine because of
                    bind(c,name=...)
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: francois.jacq at irsn dot fr
  Target Milestone: ---

In the following example, the subroutine c_open of the module m2, which should
call the subroutine odopen of the module m1, calls itself instead...

Tested with gcc 4.9.2 , 5.3.0, 6.3.0

result :

dev005{bug} 114 : gfortran -c m1.f90 m2.f90
dev005{bug} 114 : gcc main.c *.o -lgfortran
dev005{bug} 114 : ./a.out
c_odopen
c_odopen
c_odopen
...

module m1
   implicit none
   contains
   subroutine odopen(unit)
      integer,intent(out) :: unit
      write(*,*) 'odopen'
      unit=8
   end subroutine
end module

module m2
   use iso_c_binding
   use m1
   implicit none
   contains
   subroutine c_odopen(unit) bind(c,name="odopen")
      integer(c_int),intent(out) :: unit
      write(*,*) 'c_odopen'
      call odopen(unit)
   end subroutine
end module

#include <stdio.h>
void odopen(int*);
int main(){
   int unit;
   odopen(&unit);
   printf("unit=%d \n",unit);
   return 0;
}

Reply via email to