This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

[Patch, fortran] PR30081 - Failure to overload non-generic intrinsics


:ADDPATCH fortran:

This problem seemed very mysterious, at first, but turns out to be rather simple. If resolve_generic_f/s fail to find a module procedure whos interface matches the actual, they turn to intrinsics to see if a match can be found. This was done by searching amongst the generic intrinsics. However, this is unnecessarily restrictive since the standard permits non-generic intrinsics to be overloaded. The fix was implemented by substituting gfc_generic intrinsic by gfc_intrinsic_name. The testcase is the contributors.

Regtested on Cygwin_NT/amd64 - OK for trunk and 4.2?

Paul

2006-12-16  Paul Thomas <pault@gcc.gnu.org>

	PR fortran/30081
	* resolve.c (resolve_generic_f, resolve_generic_s): Use
	gfc_intrinsic_name to find out if the function is intrinsic
	because it does not have to be a generic intrinsic to be
	overloaded.

2006-12-16  Paul Thomas <pault@gcc.gnu.org>

	PR fortran/30081
	* gfortran.dg/generic_10.f90: New test.


Index: gcc/fortran/resolve.c
===================================================================
*** gcc/fortran/resolve.c	(revision 119697)
--- gcc/fortran/resolve.c	(working copy)
*************** generic:
*** 1215,1223 ****
  	goto generic;
      }
  
!   /* Last ditch attempt.  */
! 
!   if (!gfc_generic_intrinsic (expr->symtree->n.sym->name))
      {
        gfc_error ("There is no specific function for the generic '%s' at %L",
  		 expr->symtree->n.sym->name, &expr->where);
--- 1215,1223 ----
  	goto generic;
      }
  
!   /* Last ditch attempt.  See if the reference is to an intrinsic
!      that possesses a matching interface.  14.1.2.4  */
!   if (!gfc_intrinsic_name (sym->name, 0))
      {
        gfc_error ("There is no specific function for the generic '%s' at %L",
  		 expr->symtree->n.sym->name, &expr->where);
*************** generic:
*** 1675,1683 ****
  	goto generic;
      }
  
!   /* Last ditch attempt.  */
    sym = c->symtree->n.sym;
!   if (!gfc_generic_intrinsic (sym->name))
      {
        gfc_error
  	("There is no specific subroutine for the generic '%s' at %L",
--- 1675,1685 ----
  	goto generic;
      }
  
!   /* Last ditch attempt.  See if the reference is to an intrinsic
!      that possesses a matching interface.  14.1.2.4  */
    sym = c->symtree->n.sym;
! 
!   if (!gfc_intrinsic_name (sym->name, 1))
      {
        gfc_error
  	("There is no specific subroutine for the generic '%s' at %L",
Index: gcc/testsuite/gfortran.dg/generic_10.f90
===================================================================
*** gcc/testsuite/gfortran.dg/generic_10.f90	(revision 0)
--- gcc/testsuite/gfortran.dg/generic_10.f90	(revision 0)
***************
*** 0 ****
--- 1,36 ----
+ ! { dg-do compile }
+ ! Test the patch for PR30081 in which non-generic intrinsic
+ ! procedures could not be overloaded by generic interfaces.
+ !
+ ! Contributed by Harald Anlauf  <anlauf@gmx.de>
+ !
+ module gfcbug46
+   interface random_seed
+      module procedure put_seed
+   end interface
+   interface random_number
+      module procedure random_vector
+   end interface
+   type t_t
+      real :: x(2)
+   end type t_t
+ contains
+   subroutine put_seed (n, seed)
+     integer, intent(inout) :: n
+     integer, intent(in)    :: seed
+     call random_seed (size=n)
+   end subroutine put_seed
+   subroutine random_vector (t)
+     type(t_t) :: t
+     call random_number (t% x)
+   end subroutine random_vector
+ end module gfcbug46
+ 
+   use gfcbug46
+   type(t_t) :: z
+   integer :: n = 2, seed = 1
+   call put_seed (n, seed)
+   call random_number (z)
+   print *, z
+ end
+ ! { dg-final { cleanup-modules "gfcbug46" } }


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