[Bug fortran/49436] Modifying actual arguments in subroutine not detected

burnus at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Jun 16 12:04:00 GMT 2011


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49436

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-06-16 12:04:35 UTC ---
(In reply to comment #0)
> There's an aspect of the f95 standard that seems to not be enforced by
> gfortran.

The Fortran standard only requires that constraints ("C<number>" in the
standard) are checked by the compiler. Some other things might be checkable
(and compilers do diagnose some of those) - either at compile time or at run
time, but for a lot of code, it is practically impossible to diagnose the
invalidity.

Your program belongs to the latter:

call c(a)
[...]
subroutine c(n)
integer,intent(in)::n
a=15

This cannot be detected in general - and in specific cases only with
difficulty. I doubt that any Fortran compiler can detect this at compile time -
and I am not sure whether there is any which can do so at run time.

Assume, the variable "a" is in one file, the caller in another and the callee
in the third. In that case it should be clear that a compile-time diagnostic is
unfortunately not possible.

By the way, the result of your program depends on the compiler. Some might do a
copy-in of the argument, in that case "n" and "a" are disjunct. Or the compiler
might not do so - which gives the known result that modifying "a" also modifies
"n".


Thus, I think it is (unfortunately) a WONTFIX bug.



More information about the Gcc-bugs mailing list