! In this program, gfortran fails to identify the generic interface sub for ! sub_int. The compiler gives this error message: ! ! > gfortran prog.f90 ! prog.f90:40.9: ! ! call sub(1) ! 1 ! Error: Type mismatch in argument 'x' at (1); passed INTEGER(4) to REAL(4) ! ! However, if the use statements in program prog are switched so that ! use mod2 comes before use mod1, it correctly identifies the generic ! interface and compiles. ! ! This is with the following version of gfortran: ! > gfortran --version ! GNU Fortran (GCC) 4.5.0 20091205 (experimental) [trunk revision 155016] module mod1 contains subroutine sub(x) real x end subroutine sub end module mod1 module mod2 use mod1 interface sub module procedure sub, sub_int end interface sub contains subroutine sub_int(i) integer i end subroutine sub_int end module mod2 program prog use mod1 use mod2 call sub(1) end program prog
(In reply to comment #0) Funny, ifort 11.1, xlf 12.1.0.5 and Sunstudio 12.1 accept the code, but nagfor 5.2 rejects it with: NAG Fortran Compiler Release 5.2(686) Warning: prog.f90, line 23: Unused dummy variable X detected at SUB@<end-of-statement> Warning: prog.f90, line 34: Unused dummy variable I detected at SUB_INT@<end-of-statement> Error: prog.f90, line 40: Symbol SUB found both in module MOD1 and in MOD2 detected at CALL@SUB [NAG Fortran Compiler pass 1 error termination, 1 error, 2 warnings]
Note that I personally would declare sub as generic in mod1, e.g. module mod1 interface sub module procedure sub end interface contains subroutine sub(x) real x end subroutine sub end module mod1 and remove the corresponding module procedure in mod2, as this resolves the compilation errors with gfortran and nagfor.
See also http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/b128e5ed244a2516 Richard Maine thinks it is valid - and I also do not see (ad hoc) any reason why it should be invalid.
I am just about to post a fix. Paul
Subject: Bug 42481 Author: pault Date: Thu Jan 14 06:13:19 2010 New Revision: 155876 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=155876 Log: 2010-01-14 Paul Thomas <pault@gcc.gnu.org> PR fortran/42481 * module.c (load_generic_interfaces): If a procedure that is use associated but not generic is given an interface that includes itself, then make it generic. 2010-01-14 Paul Thomas <pault@gcc.gnu.org> PR fortran/42481 * gfortran.dg/generic_19.f90 : New test. Added: trunk/gcc/testsuite/gfortran.dg/generic_19.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/module.c trunk/gcc/testsuite/ChangeLog
Fixed on trunk. Thanks for the report Paul