The following code does not generate a runtime error using FTN95 or gfortran, but NAG issues a message at line 5 (the call to s2) indicating that there is a reference to optional argument r which is not present. I thought the NAG compiler was in error, but apparently it is correct because line 5 should be written as:
Call s2 (r=r)
to avoid a declaration that argument r is present.
Module m
Contains
Subroutine s1 (r)
Integer, Dimension(:), Optional :: r
Call s2 (r=r(:))
Return
End Subroutine s1
Subroutine s2 (r)
Integer, Dimension(:), Optional :: r
Return
End Subroutine s2
End Module m
Program p
Use m, Only: s1
Implicit None
Call s1 ()
End Program p