This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Fortran, Patch] Disallow assigning to external functions (PR31559)


Why does one always realize that something is missing *after* one has
hit send?

a) Bootstrapped on x86_64-unknown-linux-gnu and regression tested
(check-gfortran) with -m64 and -m32 with no failures.
Ok for the trunk? (Does anyone want to see this backported to 4.2?)

b) And of cause Thunderbird does not re-read attached patches either.
(Interdiff: Changed one string in "dg-error" as it did not match the
error string.)

Sorry for my mistakes.

Tobias


Tobias Burnus wrote:
> 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
+   sub = 'a'  ! { dg-error "Expected VARIABLE" }
+   fun = 4.4  ! { dg-error "Expected VARIABLE" }
+   funget = 4 ! { dg-error "is not a VALUE" }
+   bar = 5    ! { dg-error "is not a VALUE" }
+  end subroutine a
+end module mod
+
+end

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]