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

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

 

 

Thread Topic: 

Bug Report
6 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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

Retired 12/31/2016

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

 

Cheers,

milan

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

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.

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

Leave a Comment

Please sign in to add a comment. Not a member? Join today