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

            Bug ID: 119812
           Summary: Bogus rank and type mismatch errors with procedure
                    pointer
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: abensonca at gcc dot gnu.org
  Target Milestone: ---

The following code causes bogus errors when compiled with the latest trunk
using the -Wall option:

module bugMod

  type :: c
     integer :: a
  end type c

  type, extends(c) :: c1
  end type c1

  type, extends(c) :: c2
  end type c2

  type :: s
     type(c1) :: c1_
     type(c2) :: c2_
   contains
     procedure :: map => map_
  end type s

contains

  subroutine mf(self)
    implicit none
    class(c), intent(inout) :: self

    self%a=1
    return
  end subroutine mf

  subroutine map_(self,mapFunction)
    implicit none
    class(s), intent(inout) :: self
    procedure(mf), pointer :: mapFunction 

    call mapFunction(self%c1_)
    call mapFunction(self%c2_)
    return
  end subroutine map_

end module bugMod


> gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/carnegie/nobackup/users/abenson/upstream/libexec/gcc/x86_64-pc-linux-gnu/15.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure
--prefix=/carnegie/nobackup/users/abenson/upstream --disable-multilib
--enable-checking=release --enable-host-shared --with-pic
--enable-languages=c,c++,fortran,jit,lto
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 15.0.1 20250410 (experimental) (GCC) 



> gfortran -c bugFP.F90  -Wall
bugFP.F90:36:30:

   35 |     call mapFunction(self%c1_)
      |                              2
   36 |     call mapFunction(self%c2_)
      |                              1
Warning: Different argument lists in external dummy subroutine mapfunction at
(1) and (2) [-Wexternal-argument-mismatch]
bugFP.F90:36:21:

   35 |     call mapFunction(self%c1_)
      |                     2
   36 |     call mapFunction(self%c2_)
      |                     1
Error: Type mismatch between actual argument at (1) and actual argument at (2)
(TYPE(c2)/TYPE(c1)).



The `mapFunction` procedure pointer uses subroutine `mf` as its interface,
which accepts a `class(c)` argument, such that either of the child types (`c1`
and `c2`) should be acceptable.

The error goes away if compiled without -Wall, or if the calls to `mapFunction`
are replaced with calls to `mf` directly.

This doesn't occur with gfortran 13.3.0 so appears to be a regression.

Reply via email to