[Bug fortran/41556] New: Errors in applying operator/assignment to an abstract type

damian at rouson dot net gcc-bugzilla@gcc.gnu.org
Sat Oct 3 17:10:00 GMT 2009


When defining an abstract type with generic operators that map to deferred
bindings and using these operators in an expression, the development branch of
gfortran 4.5.0 (20090925) gives the errors shown below the program below.  In
case it helps to know, IBM XL Fortran 12.1 compiles the program without errors
or warnings. 

Damian


$ cat abstract_algebra.f03
module abstract_algebra
  implicit none 
  private      
  public :: rescale
  public :: object

  type ,abstract :: object
  contains
    procedure(assign_interface) ,deferred :: assign   
    procedure(product_interface) ,deferred :: product
    generic  :: assignment(=) => assign
    generic  :: operator(*) => product
  end type 

  abstract interface
    function product_interface(lhs,rhs) result(product)
      import :: object
      class(object) ,intent(in)  :: lhs
      class(object) ,allocatable :: product
      real          ,intent(in)  :: rhs
    end function 
    subroutine assign_interface(lhs,rhs) 
      import :: object 
      class(object) ,intent(inout) :: lhs
      class(object) ,intent(in)    :: rhs
    end subroutine 
  end interface

contains

  subroutine rescale(operand,scale)    
    class(object)    :: operand
    real ,intent(in) :: scale
    operand = operand*scale           ! preferred implementation 
    operand = operand%product(scale)  ! alternate implementation
  end subroutine 
end module

$ /usr/local/gfortran/bin/gfortran-4.5 -c abstract_algebra.f03 
abstract_algebra.f03:9.54:

    procedure(assign_interface) ,deferred :: assign   
                                                      1
Error: Assignment operator interface at (1) must not redefine an INTRINSIC type
assignment
abstract_algebra.f03:34.14:

    operand = operand*scale           ! preferred implementation 
              1
Error: Operands of binary numeric operator '*' at (1) are CLASS(object)/REAL(4)
abstract_algebra.f03:35.14:

    operand = operand%product(scale)  
              1
Error: ABSTRACT INTERFACE 'product_interface' must not be referenced at (1)

$ /usr/local/gfortran/bin/gfortran-4.5 --version
GNU Fortran (GCC) 4.5.0 20090925 (experimental)


-- 
           Summary: Errors in applying operator/assignment to an abstract
                    type
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: damian at rouson dot net
 GCC build triplet: Mac OS X 10.5.8
  GCC host triplet: Mac OS X 10.5.8
GCC target triplet: Mac OS X 10.5.8


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41556



More information about the Gcc-bugs mailing list