Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
71 Views

Overloaded operator for derived type undefined when imported from a wrapper module

The following code does not compile with Intel Fortran v16, v17, on x86-64 Linux:

module mymod
implicit none

type :: mytype
  private
  integer :: a
  contains
  procedure,private :: eq
  generic :: operator(==) => eq
endtype mytype

interface mytype
  module procedure :: constructor
endinterface mytype

contains

type(mytype) function constructor(a)
  integer,intent(in),optional :: a
  if(present(a))then
    constructor % a = a
  else
    constructor % a = 0
  endif
endfunction constructor

logical function eq(m0,m1)
  class(mytype),intent(in) :: m0
  class(mytype),intent(in) :: m1
  eq = m0 % a == m1 % a
endfunction eq

endmodule mymod

module wrapper_module
use mymod,only:mytype
endmodule wrapper_module

program test
use wrapper_module
implicit none

write(*,*)mytype() == mytype(0)

endprogram test

The compiler does not seem to resolve the overloaded == operator for mytype:

$ ifort test.f90 
test.f90(44): error #6355: This binary operation is invalid for this data type.
write(*,*)mytype() == mytype(0)
----------^
test.f90(44): error #6355: This binary operation is invalid for this data type.
write(*,*)mytype() == mytype(0)
----------------------^
compilation aborted for test.f90 (code 1)

If the main program accesses mytype directly from mymod, the program compiles and executes as expected.

If the main program accesses mytype from wrapper_module, and wrapper module accesses mytype via "use mymod", the program compiles and executes as expected.

If the main program accesses mytype from wrapper_module, and wrapper module accesses mytype via "use mymod,only:mytype" (the example code above), the compilation fails with the above message. I think this is unexpected behavior.

The code compiles and executes as expected when compiled with gfortran 5.x

Thanks,

milan

 

 

0 Kudos
5 Replies
Highlighted
71 Views

Thanks - this is an issue we're already working on. Issue ID is DPD200374263.

0 Kudos
Highlighted
Beginner
71 Views

Just a follow-up, the issue remains as of Intel Fortran 19.0.1.144 Build 20181018.

 

Cheers,

milan

0 Kudos
Highlighted
New Contributor II
71 Views

This still seems to be present even in the latest compiler. Any updates on the Intel side?

0 Kudos
Highlighted
Valued Contributor I
71 Views

For me this works with ifort v19.0.3 and v19.0.4 as well as with the beta version of 19.1.0. So it seems that this bug has been fixed.

0 Kudos
Highlighted
Beginner
71 Views

Thanks Juergen, it looks like it's time for an update. :)

0 Kudos