http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47845
Summary: Polymorphic deferred function: Not matched class
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: fortran
AssignedTo: unassig...@gcc.gnu.org
ReportedBy: kdx1...@gmail.com
I'm trying to work out an Exercise in Stephen Chapman's book Fortran 95/2003
for Scientists & Engineers. Create a abstract class vec and subclass vec2d and
vec3d, override some deferred functions, then test the classes.
Here is my construction of vec:
MODULE class_vec
!
! Brief Description:
! 1. Superclass of vec2d and vec3d
! 2. Perform vector addition and subtraction
! 3. Perform vector dot product
!
! 4. Common fields:
! a.x
! b.y
!
! Record of revisions:
! Date Programmer Description of change
! 02/21/2011KePuOriginal code
!
IMPLICIT NONE
TYPE,ABSTRACT::vec
! Common fields
REAL::x
REAL::y
! Declare methods
CONTAINS
GENERIC::OPERATOR(+)=>add
GENERIC::OPERATOR(-)=>subtract
GENERIC::OPERATOR(*)=>dot
PROCEDURE,PASS::set_vec=>set_vec_sub
PROCEDURE(addx),PASS,DEFERRED::add
PROCEDURE(subtractx),PASS,DEFERRED::subtract
PROCEDURE(dotx),PASS,DEFERRED::dot
END TYPE vec
!!
!!
! Interfaces to deferred procedures
ABSTRACT INTERFACE
FUNCTION addx(this,other) RESULT(add_vec)
!
! Purpose:
! Add two vector
!
! Record of revisions:
! Date Programmer Description of change
! 02/21/2011KePuOriginal code
!
IMPORT vec
IMPLICIT NONE
CLASS(vec),INTENT(in)::this! This object
CLASS(vec),INTENT(in)::other ! The other object
CLASS(vec),POINTER::add_vec! Return value
END FUNCTION addx
!!
FUNCTION subtractx(this,other) RESULT(subtract_vec)
!
! Purpose:
! Subtract two vector
!
! Reord of revisions:
! Date Programmer Description of change
! 02/21/2011KePuOriginal code
!
IMPORT vec
IMPLICIT NONE
CLASS(vec),INTENT(in)::this! This object
CLASS(vec),INTENT(in)::other ! The other object
CLASS(vec),Pointer::subtract_vec ! Return value
END FUNCTION subtractx
!!
FUNCTION dotx(this,other)
!
! Purpose:
! Dot product of two vectors
!
! Record of revisions:
! Date Programmer Description of change
! 02/21/2011KePuOriginal code
!
IMPORT vec
IMPLICIT NONE
CLASS(vec),INTENT(in)::this! This object
CLASS(vec),INTENT(in)::other ! The other object
REAL::dotx ! Return value
END FUNCTION dotx
END INTERFACE
!!
!!
! Define methods
CONTAINS
SUBROUTINE set_vec_sub(this,x,y)
!
! Purpose:
! Set coordinate of vector
!
! Record of revisions:
! Date Programmer Description of change
! 02/21/2011KePuOriginal code
!
IMPLICIT NONE
! Data dictionary:
CLASS(vec),INTENT(inout)::this ! Input object
REAL,INTENT(in)::x,y ! Coordinate
this%x=x
this%y=y
END SUBROUTINE set_vec_sub
END MODULE class_vec
--
--
Subclass vec3d will override all the functions and subroutines defined above
MODULE class_vec3d
!
! Brief description:
! 1. Subclass of vec
! 2. Fields
! a. Inherited: real::x real::y
! b. Extends: real::z
! 3. Method
! a. set_vec
! b. Addition
! c. Subtraction
! d. Dot product
!
! Record of revisions:
! Date Programmer Description of change
! 02/22/2011KePuOriginal code
!
USE class_vec ! Use parent class
IMPLICIT NONE
! Type definition
TYPE,EXTENDS(vec),PUBLIC::vec3d
! Fields
REAL::z
! Declare methods
CONTAINS
PROCEDURE,PUBLIC,PASS::set_vec=>set_vec_3d
PROCEDURE,PUBLIC,PASS::add=>add_fn
PROCED