- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello everyone,
the code below shows strange behaviour of an intrinsic derived-type assignment executed in a function call (when compiled with ifort 13.0.1).
Since I am not sure whether or not this code finally violates the Fortran standard, any advice and comments are appreciated!
[fortran]
module m
implicit none
type other_type
integer :: i
end type
! a type with allocatable and scalar data
type :: my_type
class(other_type), allocatable :: allocatable_data
integer :: scalar_data = 1
end type
contains
! returns a copy of a specific original type T
function get_a_copy_fun()
implicit none
type(my_type) :: get_a_copy_fun, original
original%scalar_data = 2 ! change original data
get_a_copy_fun = original ! intrinsic assignment
end function
end module
program main
use m
implicit none
type(my_type) :: t
t = get_a_copy_fun()
print *, t%scalar_data ! prints "1" instead "2"
end program main
[/fortran]
The last print statement should output "2" if the assignment was carried out correctly (at least, to what I expect - but I may be wrong), but instead I get the default initialized value "1".
Remarks:
- Reproduces ONLY if the intrinsic assignment is to the function output argument within a function, not in a subroutine or program statement; and if the "class" keyword is used for allocatable_data ("type" produces correct results). Are there some restrictions that apply to function output arguments that I did violate here?
- Executing the print statement on the result inside the function yields same incorrect result
- It seems that the assignment here has the same effect as a structure constructor, e.g. without copying anything (also, allocatable_data on the lhs of the assignment doens't get allocated, if the rhs was allocated)
- May this be related to the (fixed?) ifort issue at http://software.intel.com/en-us/forums/topic/287152 which now runs fine with ifort version 13.0.1? However, why does this only happen inside a function?
Thanks for having a look,
regards Ferdinand
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I can reproduce the problem - it isn't the same as the other thread. I will escalate this to the developers and let you know of progress. The issue ID is DPD200240809.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The developers told me that they recently fixed this problem and that the fix is expected to appear in Update 3.
![](/skins/images/2E08A100FB92911314A240D1EAFB2828/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page