------- Comment #7 from paul dot richard dot thomas at cea dot fr 2006-08-04 07:50 ------- Just to reinforce the above, I should remark that an explicit interface in the main program makes the code behave correctly (see below).
The standard requires that references to a procedure with an implicit interface have the same number of actual arguments with the same type characteristics. As Andrew says, gfortran does not check implicitly defined procedure arguments; either for consistency of references within one scope or for a formal interface generated by the procedure happening to be in the same file. Paul program test_string_present interface subroutine test_present(a, b) integer :: a character*(*), optional :: b end subroutine test_present end interface call test_present(1, "foo") call test_present(2) end program subroutine test_present(a, b) integer :: a character*(*), optional :: b if (present(b)) then write (0,*) "b is present." else write (0,*) "b is not present." end if end subroutine test_present -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28443