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

bug(???) in combination of block construct and allocatable derived type

Hi there,

I found a supprising behaviour in this little program:

Module Test_Type
  Type :: TT
    integer, allocatable :: xx(:)
  End type TT
End Module Test_Type
program test
  use Test_Type
  Type(TT), allocatable :: yy
  integer, allocatable :: i,j(:)
  outer:block
    Allocate(yy,j(5),i)
  end block outer
  write(*,*) allocated(yy), allocated(i), allocated(j)
end program test

I would have expected that all variables are still allocated when leaving the block, but this is not the case for "yy". The output of the program was

 F T T

when compiled with ifort 17.05 on linux 4.14.4. Using gfortran 7.2 the output was, as expected,

  T  T  T

The deallocation call must be somewhat a "real" deallocation call, because if yy is a large object from a class with finalizers (e.g. a hugh linked list), the time difference from leaving the block to the program termination is substantial, because the finalizers are called etc.

I can only imagine that this is a bug (but maybe i am wrong).

Any comments??

Cheers

0 Kudos
3 Replies
Highlighted
Valued Contributor III
3 Views

Submit the case at the Intel

Submit the case at the Intel OSC.

0 Kudos
Highlighted
3 Views

Looks like a bug to me.

Looks like a bug to me.

As an observation (nothing to do with any standards requirements) your block statement happens to occur between the data declarations of the program and the executable statements. Out of curiosity, what happens if you place a

print *, "something"

in front of the block statement (iow place the block inside the executable statements)

FWIW the assumption being the compiler may have falsely determined the type declaration occurred within the block.

Jim Dempsey

0 Kudos
Highlighted
Valued Contributor I
3 Views

gfortran with all versions

gfortran with all versions from 4.8 to 8.0 shows TTT, also NAG. Ifort shows FTT in the latest v15, v16, v17 and v18. Interestingly, PGF cannot compile the code but issues a syntax error "at or near identifier block". But the block construct is F2008, and PGF is known to have still very limited F2003 and F2008 features implemented. Putting a print statement before the block construct does not change the ifort behaviour. To me it looks like that the allocatable component xx of the DT causes this behaviour: when you make xx just an integer (integer :: xx) then ifort shows the expected behaviour. Also explicitly allocating yy%xx does not help, the output is still FTT. I would file a bug report. 

0 Kudos