This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Doubt w.r.t. to gfortran's interpretation of the Fortran2003 standard
- From: "Alberto F. Martín Huertas" <amartin at cimne dot upc dot edu>
- To: fortran at gcc dot gnu dot org
- Cc: Javier Principe <principe at cimne dot upc dot edu>
- Date: Fri, 31 Oct 2014 09:12:52 +0100
- Subject: Doubt w.r.t. to gfortran's interpretation of the Fortran2003 standard
- Authentication-results: sourceware.org; auth=none
Dear Fortran@gcc.gnu.org members,
I would like to know if the following Fortran2003 code snippet is
compliant or not
with the Fortran2003 standard:
module overwrite
type madre
contains
procedure :: sum => sum_madres
generic :: operator(+) => sum
end type madre
type, extends(madre) :: hijo
contains
procedure :: sum => sum_hijos_compliant
generic :: operator(+) => sum
end type hijo
contains
function sum_madres(op1,op2) result(res)
implicit none
class(madre), intent(in) :: op1, op2
class(madre), pointer :: res
write(*,*) 'sum_madres'
end function sum_madres
function sum_hijos_compliant(op1,op2) result(res)
implicit none
class(hijo) , intent(in) :: op1
class(madre), intent(in) :: op2
class(madre), pointer :: res
write(*,*) 'sum_hijos'
end function
end module overwrite
program drive_ovw
use overwrite
implicit none
type(madre) :: m1, m2
class(madre), pointer :: mres
type(hijo) :: h1, h2
class(madre), pointer :: hres
mres => m1 + m2
hres => h1 + m2
hres => h1%sum(h2)
!h1+h2
!m1+h1
!h1+m1
end program drive_ovw
When I compile it with either gfortran 4.8.1, or 4.9.1, I get the
following compilation error:
gfortran -c -J Objects -g -O0 -fdefault-real-8 -g -fbacktrace
-fbounds-check -std=f2003 -o Objects/overwrite.o overwrite.f90
overwrite.f90:12.29:
generic :: operator(+) => sum
1
Error: 'sum_hijos_compliant' and 'sum_madres' for GENERIC '+' at (1) are
ambiguous
However, I can compile it with both the Intel and IBM fortran compilers,
getting as output (as expected):
sum_madres
sum_hijos
sum_hijos
Thanks for your advice.
Best regards,
Alberto.
--
Alberto F. Martín-Huertas
Centre Internacional de Mètodes Numèrics a l'Enginyeria (CIMNE)
Parc Mediterrani de la Tecnologia, UPC
Esteve Terradas 5, Building C3, Office 215,
08860 Castelldefels (Barcelona, Spain)
Tel.: (+34) 9341 34223
e-mail: amartin@cimne.upc.edu
________________
IMPORTANT NOTICE
All personal data contained on this mail will be processed confidentially and registered in a file property of CIMNE in
order to manage corporate communications. You may exercise the rights of access, rectification, erasure and object by
letter sent to Ed. C1 Campus Norte UPC. Gran Capitán s/n Barcelona.