Bug 44814 - ISO_C_BINDING types inherited from a USEd module are corrupted
ISO_C_BINDING types inherited from a USEd module are corrupted
Status: RESOLVED DUPLICATE of bug 37829
Product: gcc
Classification: Unclassified
Component: fortran
4.6.0
: P3 normal
: ---
Assigned To: Not yet assigned to anyone
: rejects-valid
Depends on:
Blocks: 32630
  Show dependency treegraph
 
Reported: 2010-07-04 18:57 UTC by Joe Krahn
Modified: 2010-07-09 08:38 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-07-04 19:44:59


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joe Krahn 2010-07-04 18:57:16 UTC
$ cat ptr_bug.f90
module mod1
  use iso_c_binding, only: C_ptr
end module mod1
module mod2
  use mod1
  use iso_c_binding, only: C_NULL_ptr
contains
  subroutine bug
    type(C_ptr) :: ptr
    ptr=C_NULL_ptr
  end subroutine bug
end module mod2

$ /usr/local/gfortran/bin/gfortran -c ptr_bug.f90
ptr_bug.f90:10.8:

    ptr=C_NULL_ptr
        1
Error: Can't convert TYPE(_gfortran_iso_c_binding_c_ptr) to TYPE(c_ptr) at (1)


The inherited name gets an internal "_gfortran_iso_c_binding_" prefix, but the locally inherited name does not. This is mentioned in bug37829, where it was suggested to be low priority or even just an enhancement. IMHO, anything that prevents perfectly valid code form compiling should be at least normal status.
Comment 1 Joe Krahn 2010-07-04 19:09:20 UTC
I updated my code to use ISO_C_BINDING directly, but still get this bug. In order to avoid corruption by the USEd module, the ISO_C_BINDING imports must all be done on the first USE statement.

This code still fails:
module mod1
  use iso_c_binding, only: C_ptr
end module mod1
module mod2
  use iso_c_binding, only: C_NULL_ptr
  use iso_c_binding, only: C_ptr
  use mod1
contains
  subroutine bug
    type(C_ptr) :: ptr
    ptr=C_NULL_ptr
  end subroutine bug
end module mod2


This code works, with the latter two "use iso_c_binding" statements merged:
module mod1
  use iso_c_binding, only: C_ptr
end module mod1
module mod2
  use iso_c_binding, only: C_ptr, C_NULL_ptr
  use mod1
contains
  subroutine bug
    type(C_ptr) :: ptr
    ptr=C_NULL_ptr
  end subroutine bug
end module mod2


The merged statement still fails if mod1 is used first:
module mod1
  use iso_c_binding, only: C_ptr
end module mod1
module mod2
  use mod1
  use iso_c_binding, only: C_ptr, C_NULL_ptr
contains
  subroutine bug
    type(C_ptr) :: ptr
    ptr=C_NULL_ptr
  end subroutine bug
end module mod2

This should also be tested against procedure interface IMPORT and USE statements.
Comment 2 Tobias Burnus 2010-07-09 08:38:36 UTC

*** This bug has been marked as a duplicate of 37829 ***