- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Allocating an array of a derived-type which contains an allocatable component within a block statement fails for both ifort as well as ifx (recent 2024 release, linux). No compile options required.
program alloc_block
implicit none
type :: int_scalar
integer :: i = 0
end type int_scalar
type :: int_alloc
integer, allocatable :: i
end type int_alloc
type :: string
character(len=:), allocatable :: c
end type string
type(int_scalar), dimension(:), allocatable :: a
type(int_alloc), dimension(:), allocatable :: b
type(string), dimension(:), allocatable :: c
integer, dimension(:), allocatable :: d
block
allocate(a(1:1))
allocate(b(1:1))
allocate(c(1:1))
allocate(d(1:1))
end block
print *, allocated(a), allocated(b), allocated(c), allocated(d)
end program alloc_block
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you please be more specific about the failure? compile time? runtime?
What message do you get?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, I forgot that. Allocation fails for "b" and "c" and I get the output "T F F T" instead of "T T T T". All four variables should be allocated at the final print statement.
I just checked the stat, which is zero (i.e. allocation succeeded). Below is the same code but with additional diagnostic output, and it seems that within the block, all four variables are indeed allocated, but "b" and "c" get deallocated at end of block statement. I also thought that "dimension(:)" for b and c is necessary, but it also fails if b and c are declared without that, i.e. as scalar values.
program alloc_block
implicit none
type :: int_scalar
integer :: i = 0
end type int_scalar
type :: int_alloc
integer, allocatable :: i
end type int_alloc
type :: string
character(len=:), allocatable :: c
end type string
type(int_scalar), dimension(:), allocatable :: a
type(int_alloc), dimension(:), allocatable :: b
type(string), dimension(:), allocatable :: c
integer, dimension(:), allocatable :: d
integer :: stat
block
allocate(a(1:1), stat=stat)
print *, allocated(a), stat
allocate(b(1:1), stat=stat)
print *, allocated(b), stat
allocate(c(1:1), stat=stat)
print *, allocated(c), stat
allocate(d(1:1), stat=stat)
print *, allocated(d), stat
end block
print *, allocated(a), allocated(b), allocated(c), allocated(d)
end program alloc_block
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Now that you have explained it better, yes I see the error in Windows.
Interesting really, clearly a bug in Intel Fortran.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Good news! This issue is fixed in the next minor compiler release due about the end of Q1 2024. The issue is fixed for both ifx and ifort.
ifx mm.f90
a.out
T T T T
ifx mm2.f90
a.out
T 0
T 0
T 0
T 0
T T T T
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I confirmed that ifx 2024.1.0 prints the correct output. It was released last week. Please try it out!
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page