http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48959

           Summary: Dummy procedure: Argument mismatch not diagnosed
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: bur...@gcc.gnu.org


Found at:
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/1a40cc3e6e4546de/

The dummy procedure has as first dummy argument:
      real, intent(in) :: p(:)
whereas the procedure which is passed as actual argument has as dummy argument:
      real, intent(in) :: param(3)

However, gfortran fails to diagnose this. I think the reason is that as dummy
argument "p" and "param" are compatible; however, as dummy argument of a
procedure they are not.


The check has to be added into interface.c's gfc_compare_interfaces - which
should be rather simple.

Currently, for each argument rank, optional attribute and intent is checked.
One there as to add a check that either both or neither is an assumed-shape
array. (Deferred-shape can be handled via an ALLOCATABLE/POINTER attribute
check.) Additionally, one should check for other characteristics (cf. 12.3.2):
CONTIGUOUS, VALUE, ALLOCATABLE, POINTER, TARGET, ASYNCHRONOUS, VOLATILE, type
parameters (currently, only: string lengths), corank. The procedure itself
should be checked for BIND(C) and PUREness.

Cf. also:

"12.5.2.9 Actual arguments associated with dummy procedure entities

"If the interface of a dummy procedure is explicit, its characteristics as a
procedure (12.3.1) shall be the same as those of its effective argument, except
that a pure effective argument may be associated with a dummy argument that is
not pure and an elemental intrinsic actual procedure may be associated with a
dummy procedure (which cannot be elemental)."


NAG diagnoses the problem as:
  Error: line 31: Dummy proc SUBR arg 1 is assumed-shape, actual proc
                  MYSUB arg is not
  Error: line 31: Incompatible procedure argument for SUBR (no. 2) of MINIM


Example program by Clive Page:

module mymod
implicit none
contains
!---------------------------------------------------------
subroutine mysub(param, result)
real, intent(in) :: param(3)
real, intent(out) :: result
print *,'param=', param
result = 0.0
end subroutine mysub
!---------------------------------------------------------
subroutine minim(param, subr, result)
real, intent(in) :: param(:)
interface
    subroutine subr(p, r)
      real, intent(in) :: p(:)
      real, intent(out) :: r
    end subroutine subr
end interface
real, intent(out):: result
!
call subr(param, result)
end subroutine minim
end module mymod
!----------------------------------------------------------

program main
use mymod
implicit none
real :: param(3) = [1.0, 2.0, 3.0], result
call minim(param, mysub, result)
end program main

Reply via email to