http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61069
Bug ID: 61069
Summary: Gfortran allows functions to be called as subroutines
when defined in a separate source file
Product: gcc
Version: 4.8.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: tristanmoody at gmail dot com
This might not be the easiest thing to fix, as (1) it appears that verifying
the semantics of a function call happen on a per-source-file basis, and (2)
there is no apparent way of marking a procedure as either a subroutine or a
function once it has been translated to assembly or object code.
Nevertheless, the problem is fairly straightforward. Suppose there exists a
program "foo", as follows:
program foo
implicit none
integer :: i
external bar, baz
i = 0
call bar(i)
call baz(i)
end program
function bar(i)
implicit none
integer :: i
integer :: bar
bar = i + 10
i = i + 5
return
end function
subroutine baz(i)
implicit none
integer :: i
write(*,*) i
return
end subroutine
When the main program and the two subprograms are all in the same file, the
error is correctly caught by gfortran:
foobad.f90:8.13:
call bar(i)
1
foobad.f90:12.15:
function bar(i)
2
Error: Global name 'bar' at (1) is already being used as a FUNCTION at (2)
However, when the main program is a separate file from the two subprograms,
(i.e. program foo in foo.f90, bar and baz in bar.f90, then compiled with
"gfortran foo.f90 bar.f90" ), then compilation proceeds without issue and the
resulting executable behaves as though bar() was called and its result
discarded. Filing this bug report as this non-standard behavior does not
appear in any of the documentation I have seen.