Consider the function
integer function add(x,y)
integer, intent(in) :: x
integer, intent(in), optional :: y
if (present(y)) then
add = x+y
else
add = x
endif
endfunction add
I looked at this in Compiler Explorer and it shows that present() is evaluated at runtime with a CMP instruction.
Why is this not resolved at compile time?
The compiler certainly knows whether the function is called with one or two arguments.