I've found that if I have overloaded the intrinsic MAX function with any arbitrary function, I am no longer able to use the intrinsic MAX function with 10 or more arguments, but it still works for 2 to 9 arguments.
For a simple example consider a program that simply attempts to call the intrinsic MAX function twice, once with 9 arguments and once with 10 arguments. Now, assume we have a module max_mod that overloads the intrinsic MAX function with a dummy function that accepts a single integer input and returns it. If I modify the original program to add a USE max_mod statement it will no longer compile. Code for this example is below:
program prog1 implicit none real :: a a = max(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0) write (*, *) 'max of 9 numbers, expecting 9: ', a a = max(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0) write (*, *) 'max of 10 numbers, expecting 10: ', a end program
This program compiles and works as expected. Next the module and the program using it:
module max_mod implicit none interface max module procedure max_dummy end interface max contains function max_dummy (i) integer, intent(in) :: i integer :: max_dummy max_dummy = i end function max_dummy end module max_mod program prog2 use max_mod implicit none real :: a a = max(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0) write (*, *) 'max of 9 numbers, expecting 9: ', a a = max(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0) write (*, *) 'max of 10 numbers, expecting 10: ', a end program
This program will not compile, giving the error message
prog2.f90(20): error #6284: There is no matching specific function for this generic function reference. [MAX] a = max(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0) --------^ compilation aborted for prog2.f90 (code 1)
I found it odd that there is no error when only 9 arguments are specified, but for 10 or more I see this compilation error. I had expected this to compile. Am I misunderstanding something or is this a bug?
I'm using Intel Fortran ifort (IFORT) 15.0.2 20150121. I have also tested with 14.0.0 20130728 and 12.0.0 20101006.