Quantcast
Channel: Intel® Fortran Compiler
Viewing all articles
Browse latest Browse all 3270

Wrong result with defined assignment operator and/or parenthesized expressions and allocatable components

$
0
0

As discussed also in this thread:

https://groups.google.com/d/msg/comp.lang.fortran/8q2nYfHnZfU/M9FmGgx7AQAJ

ifort produces wrong results with the attached code: the expected output is

 Case A: v1%x =   1.5000000E+00
 Case B: v1%x =   1.5000000E+00
 Case C: v1%x =   1.5000000E+00

while it gives

 Case A: v1%x =   0.0000000E+00
 Case B: v1%x =   0.0000000E+00
 Case C: v1%x =   0.0000000E+00

ifort -V
Intel(R) Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 16.0.0.109 Build 20150815

module m
 implicit none

 type :: t_a
  real, allocatable :: x
 end type t_a

 interface assignment(=)
  module procedure copy_t_a
 end interface

contains

 subroutine copy_t_a(y,x)
  type(t_a), intent(in)  :: x
  type(t_a), intent(out) :: y
   allocate( y%x , source=x%x)
 end subroutine copy_t_a

end module m


program p
 use m
 implicit none

 type(t_a) :: v1

 ! Define v1
 allocate( v1%x )
 v1%x = 1.5


 ! This produces segfault
 v1 = v1
 write(*,*) "Case A: v1%x = ",v1%x ! should print 1.5

 ! This produces segfault
 v1 = (v1)
 write(*,*) "Case B: v1%x = ",v1%x ! should print 1.5

 ! This prints 0
 call copy_t_a( v1 , (v1) )
 write(*,*) "Case C: v1%x = ",v1%x ! should print 1.5

end program p

 


Viewing all articles
Browse latest Browse all 3270

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>