Bug ID 1023894
Summary Bug: gfortran module procedures in submodules - interface defined in parent module
Classification openSUSE
Product openSUSE Distribution
Version Leap 42.2
Hardware x86-64
OS openSUSE 42.2
Status NEW
Severity Normal
Priority P5 - None
Component Development
Assignee bnc-team-screening@forge.provo.novell.com
Reporter cc162@humboldt.edu
QA Contact qa-bugs@suse.de
Found By ---
Blocker ---

Hello bugzilla.opensuse.org

My request to create a new account on gcc bugzilla was denied, so I'm posting
this here as the next best option. Feel free to delete if inappropriate -
hopefully someone with more karma than me can see that it gets the right
attention.

I'm trying to move the implementation of a procedure in my code out of its
module and into a submodule. To avoid writing and having to maintain the
interface/dummy variables of the same routine in multiple places, I want to
write the interface in the module itself, and use `module procedures` within
submodules. This is an option made aware to me by the wonderful fortranwiki
(http://fortranwiki.org/fortran/show/Submodules).

Doing this works for dummy variables that have a 0-rank, but when trying to
pass arrays between functions (either as input or output) I run into the
following compiler error:

    internal compiler error: in gfc_get_symbol_decl, at
fortran/trans-decl.c:1423
    Please submit a full bug report,
    with preprocessed source if appropriate.

I'm using gcc version 6.3.1 20170131 [gcc-6-branch revision 245058] (SUSE
Linux) on openSUSE Leap 42.2. I wrote a sample code snippet that reproduces the
bug on my machine
(https://gist.github.com/cbcoutinho/cf22a60c971d4d4fa9330c064121ba18). Code
reproduced below for convenience.

The code snippet contains a module, a submodule, and a main program. The
function interface is written in the module, and the implementation is written
in the submodule. This is supposed to represent how multiple implementations
could be written that are accessed according to their interfaces (i.e.
procedure overloading). In the submodule, there are two implementations of the
function. The first is just restating the module function interface, which
compiles and runs as expected. The second option (currently commented out),
uses a module procedure, and produces the compiler error.


--- Example Code ---

module mod
  use iso_fortran_env, only: wp=>real64
  implicit none

  private
  public :: myfun
  interface myfun
    module function fun1(n, x) result(y)
      integer,  intent(in)    :: n
      real(wp), intent(in)    :: x
      real(wp), dimension(n)  :: y
    end function fun1
  end interface myfun

end module mod

submodule (mod) submod
  use iso_fortran_env, only: wp=>real64
  implicit none
contains

  module function fun1(n, x) result(y)
    integer,  intent(in)    :: n
    real(wp), intent(in)    :: x
    real(wp), dimension(n)  :: y

    y = x * 2.d0

  end function fun1

  ! module procedure fun1
  !
  !   y = x * 2.d0
  !
  ! end procedure fun1

end submodule submod

program main
  use mod, only: myfun
  use iso_fortran_env, only: wp=>real64
  implicit none

  integer :: n = 2

  print*, myfun(n, 1.d0)

end program main

--- End Example Code ---


You are receiving this mail because: