This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Fortran, Patch] Disallow assigning to external functions (PR31559)
- From: Tobias Burnus <burnus at net-b dot de>
- To: gcc-patches <gcc-patches at gcc dot gnu dot org>, "'fortran at gcc dot gnu dot org'" <fortran at gcc dot gnu dot org>
- Date: Fri, 13 Apr 2007 09:55:44 +0200
- Subject: [Fortran, Patch] Disallow assigning to external functions (PR31559)
:ADDPATCH fortran:
As found by Steve: gfortran currently allows to assign values to
external function names:
real :: bar
external bar
bar = 4.4
Tobias
2007-04-13 Tobias Burnus <burnus@net-b.de>
PR fortran/31559
* primary.c (match_variable): External functions
are no variables.
2007-04-13 Tobias Burnus <burnus@net-b.de>
PR fortran/31559
* func_assign.f90: New test.
Index: gcc/fortran/primary.c
===================================================================
--- gcc/fortran/primary.c (revision 123774)
+++ gcc/fortran/primary.c (working copy)
@@ -2420,7 +2421,8 @@
case FL_PROCEDURE:
/* Check for a nonrecursive function result */
- if (sym->attr.function && (sym->result == sym || sym->attr.entry))
+ if (sym->attr.function && (sym->result == sym || sym->attr.entry)
+ && !sym->attr.external)
{
/* If a function result is a derived type, then the derived
type may still have to be resolved. */
Index: gcc/testsuite/gfortran.dg/func_assign.f90
===================================================================
--- gcc/testsuite/gfortran.dg/func_assign.f90 (revision 0)
+++ gcc/testsuite/gfortran.dg/func_assign.f90 (revision 0)
@@ -0,0 +1,33 @@
+! { dg-do compile }
+!
+! PR fortran/31559
+! Do not allow assigning to external functions
+!
+! Contributed by Steve Kargl <sgk@troutmask.apl.washington.edu>
+!
+module mod
+ implicit none
+contains
+ integer function bar()
+ bar = 4
+ end function bar
+
+ subroutine a()
+ implicit none
+ real :: fun
+ external fun
+ interface
+ function funget(a)
+ integer :: a
+ end function
+ subroutine sub()
+ end subroutine sub
+ end interface
+ funget = 4 ! { dg-error "Expected VARIABLE" }
+ fun = 4.4 ! { dg-error "Expected VARIABLE" }
+ bar = 5 ! { dg-error "not a VALUE" }
+ sub = 'a' ! { dg-error "Expected VARIABLE" }
+ end subroutine a
+end module mod
+
+end