The following test case demonstrates a problem with gfortran, and several
other, compilers that are not properly checking intents.  This happens when
using an interface block to define a dummy argument for passing subprograms. 
The interface of the actual routine being passed is not fully compared to the
dummy argument definition, the code compiles without warning, and bad results
occur at runtime.

NAG is one of a very few compilers that detect the error at run time.

module testsub
  contains
  subroutine test(sub)
    interface
      subroutine sub(x)
        integer, intent(in), optional:: x
      end subroutine
    end interface
    print *, "In test(), about to call sub()"
    call sub()
  end subroutine
end module

module sub
  contains
  subroutine subActual(x)
    ! actual subroutine's argment is different in intent and optional
    integer, intent(inout):: x
    print *, "In subActual():", x
  end subroutine
end module

program interfaceCheck
  use testsub
  use sub

  integer :: a

  call test(subActual)
end program


-- 
           Summary: accepts-invalid
           Product: gcc
           Version: 4.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: w6ws at earthlink dot net
 GCC build triplet: Attributes not fully checked comparing actual vs dummy
                    procedure


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

Reply via email to