Thank you very much for looking this up.
I found what I was looking for in the Fortran Standard (paragraph 7 of section 184.108.40.206; pg. 315 of the linked document):
- Except in references to intrinsic inquiry functions, if the dummy argument is nonoptional and the actual argument is allocatable, the corresponding actual argument shall be allocated.
I guess that, if the desired behavior of the
-Mchkptr flag is to be for debugging purposes, perhaps it should not issue a runtime error in this case, else it will hit users who wish to exploit a valid (and at times quite useful) feature of the language, and want to still use this flag to check for actual bugs.
For completeness I checked what other compilers do. See this modified code below:
real, allocatable :: a(:),b(:),c(:)
real, intent(in) :: var(:),var_not_optional(:)
real, intent(in), optional :: var_optional(:)
crayftn I could not get any runtime error (not good, in my view). With
ifort, the program only errors out when the allocated array is passed as a non-optional argument:
$ ifort -g -check all test.f90 && ./a.out
forrtl: severe (408): fort: (8): Attempt to fetch from allocatable variable B when it is not allocated
Edit: So perhaps a sub-option for
-Mchkptr, or a change in its behavior would be useful.