Bug 48959 - Dummy procedure: Argument mismatch not diagnosed
Summary: Dummy procedure: Argument mismatch not diagnosed
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2011-05-11 07:57 UTC by Tobias Burnus
Modified: 2013-08-27 11:18 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2011-05-11 07:57:10 UTC
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
Comment 1 Mikael Morin 2013-08-27 11:18:21 UTC
Both 4.8 and trunk(4.9) now output:

comment_0.f90:32.18:

call minim(param, mysub, result)
                  1
Error: Interface mismatch in dummy procedure 'subr' at (1): Shape mismatch in argument 'p'


I think that's acceptable as a diagnostic.
Closing as FIXED.