https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109076
Bug ID: 109076
Summary: class extending abstract type with deferred
procedures, with another unrelated procedure
interface, crashes on valid code
Product: gcc
Version: 12.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: federico.perini at gmail dot com
Target Milestone: ---
Hello gfortran/gcc team,
I've reduced my issue to the following minimum viable example.
Please note I haven't shortened the names because changing them sometimes
solves this issue.
- The abstract class has deferred procedures, with their abstract interface
- The extended type implements them, AND it has another unrelated subroutine
that contains a procedure interface
- A casual solution is found by either shortening the unrelated subroutine
name, or
removing some imports from the abstract interface
==> With all gfortran versions from 12.2.0 down to 4.9, I get an "interface
mismatch" issue:
/app/example.f90:13:15:
13 | procedure :: expand => i_expand
| 1
Error: Argument mismatch for the overriding procedure 'expand' at (1): Shape
mismatch in argument 'array'
The code can be found to play with here: https://godbolt.org/z/GfKGE1cYa
And is also here:
module my_mod
use iso_fortran_env, only: real64
implicit none
private
type, abstract, public :: parallel_class
contains
procedure(par_expand_r64), pass(this), deferred :: expand
end type parallel_class
type, public, extends(parallel_class) :: interpolator
contains
procedure :: expand => i_expand
end type interpolator
abstract interface
pure subroutine par_expand_r64(this,array)
import parallel_class,real64
class(parallel_class), intent(inout) :: this
real(real64), intent(in) :: array(:)
end subroutine par_expand_r64
pure function interp_fun(ndim,x) result(fun_values)
! ****** SOLUTION #1 *******
!import real64 ! works with this
import real64,interpolator ! this crashes gfortran-12
integer , intent(in) :: ndim
real(real64) , intent(in) :: x
real(real64) , dimension(ndim) :: fun_values
end function interp_fun
end interface
contains
!****** SOLUTION #2 ******
!subroutine create_object(this,fun) ! works with this name
subroutine interpolator_create_fromfun_fixedstep(this,fun) ! crashes with
this name
class(interpolator) , intent(inout) :: this
procedure(interp_fun) :: fun
print *, 'hello world'
end subroutine
! Get comm size
pure subroutine i_expand(this,array)
class(interpolator), intent(inout) :: this
real(real64), intent(in) :: array(:)
end subroutine i_expand
end module my_mod
Thank you,
Federico