I found a little compiler bug. If I compile the program below, I find the following errors:
NVFORTRAN-S-0186-Argument missing for formal argument & (submod.f90: 74)
NVFORTRAN-S-0186-Argument missing for formal argument & (submod.f90: 75)
0 inform, 0 warnings, 2 severes, 0 fatal for totest
with
nvfortran --version
nvfortran 23.5-0 linuxarm64 target on aarch64 Linux -tp neoverse-n1
So if I uncomment the line with the reminder to use the withopt
function in the submodule subfunc
, it works
MODULE mod
USE, intrinsic :: iso_fortran_env, only : ip => INT32, rp => REAL64
implicit none
integer(ip), parameter :: lp = 4
INTERFACE
MODULE FUNCTION withopt( arg , default ) RESULT( opt )
logical(lp), intent(in), optional :: default
logical(lp), intent(in), optional :: arg
logical(lp) :: opt
END FUNCTION withopt
END INTERFACE
END MODULE mod
SUBMODULE (mod) submod
implicit none
CONTAINS
MODULE FUNCTION withopt( arg , default ) RESULT( opt )
logical(lp), intent(in), optional :: default
logical(lp), intent(in), optional :: arg
logical(lp) :: opt
opt = .false.
if( present( default ) ) opt = default
if( present( arg ) ) opt = arg
END FUNCTION withopt
END SUBMODULE submod
MODULE func
USE mod, only : ip , rp , lp , withopt
implicit none
INTERFACE
MODULE SUBROUTINE totest( opt )
logical(lp), intent(in), optional :: opt
END SUBROUTINE totest
END INTERFACE
END MODULE func
SUBMODULE (func) subfunc
! USE mod, only : withopt
implicit none
CONTAINS
MODULE SUBROUTINE totest( opt )
logical(lp), intent(in), optional :: opt
if ( withopt( opt ) ) write(6,*) 'true'
if ( .not. withopt( opt ) ) write(6,*) 'false'
END SUBROUTINE totest
END SUBMODULE subfunc
PROGRAM test
USE func, only : totest
call totest( opt=.true. )
call totest( opt=.false. )
END PROGRAM test