Bug 42481 - generic interface not recognized
Summary: generic interface not recognized
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: ---
Assignee: Paul Thomas
URL:
Keywords: rejects-valid
Depends on:
Blocks: 32834
  Show dependency treegraph
 
Reported: 2009-12-23 15:22 UTC by william.mitchell
Modified: 2010-07-06 18:30 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-01-13 22:16:32


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description william.mitchell 2009-12-23 15:22:35 UTC
! 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
Comment 1 Harald Anlauf 2009-12-23 22:31:58 UTC
(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]

Comment 2 Harald Anlauf 2009-12-23 22:39:31 UTC
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.
Comment 3 Tobias Burnus 2010-01-05 09:20:12 UTC
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.
Comment 4 Paul Thomas 2010-01-13 22:16:31 UTC
I am just about to post a fix.

Paul
Comment 5 Paul Thomas 2010-01-14 06:13:47 UTC
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

Comment 6 Paul Thomas 2010-01-14 06:19:01 UTC
Fixed on trunk.

Thanks for the report

Paul