This is the mail archive of the gcc-bugs@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]

[Bug fortran/29926] New: interface overloading assignment does not handle input types correctly


Using an interface to overload the assignment operator of a user-defined type
does   choose the proper specific subroutine based on the input type.  The code
below shows this problem: 

! uword.f90
!
module uword_type

  type uword
    integer(kind=2) :: value
  end type uword

  interface assignment(=)
    module procedure uword_assign_2
    module procedure uword_assign_4
  end interface

  interface dummy
    module procedure dummy_2
    module procedure dummy_4
  end interface

contains

  subroutine uword_assign_2(out_value,in_value)
  implicit none

  type(uword), intent(out)::out_value
  integer(kind=2), intent(in)::in_value

    out_value%value = in_value

  end subroutine uword_assign_2

  subroutine uword_assign_4(out_value,in_value)
  implicit none

  type(uword), intent(out)::out_value
  integer(kind=4), intent(in)::in_value
  integer::i
  integer(kind=1)::holdbit

    do i=0,15
      out_value%value = ibclr(out_value%value,i)

      if(ibits(in_value,i,1) == 1) then
        out_value%value = ibset(out_value%value,i)
      end if
    end do    

  end subroutine uword_assign_4

  subroutine dummy_2(value)
  implicit none  
    integer(kind=2), intent(in)::value
    integer::nothing
      nothing = value*2
  end subroutine dummy_2

  subroutine dummy_4(value)
  implicit none    
    integer(kind=4), intent(in)::value
    integer::nothing    
      nothing = value*2    
  end subroutine dummy_4

end module uword_type

! test.f90
!
program test
use uword_type
implicit none

type(uword)::a,b

  a = uword(int(1024,kind=2))
  b = uword(int(65535,kind=4))

  call dummy(int(1024,kind=2))
  call dummy(int(65535,kind=4))

end program test

gfortran (version 4.3.0 20061120 i686-pc-cygwin) reports the following at
compile time:

test.f90:10.12:

  b = uword(int(65535,kind=4))
           1
Error: Arithmetic overflow converting INTEGER(4) to INTEGER(2) at (1)

Note that the overloading of dummy does not return an error, but the assignment
interface chooses the the wrong module procedure.


-- 
           Summary: interface overloading assignment does not handle input
                    types correctly
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jeffrey dot armstrong at analexcleveland dot com


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


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