Empty array of derived type

Viewed 109

How do I properly write an empty array literal of user derived type?

The following works in GFortran, but not in IFort up to version 19.1.1.217

 type(SpinOrbIdx_t), allocatable :: det_I(:)
det_I = [SpinOrbIdx_t::]

Is this a bug in ifort, or non standard conforming behaviour of GFortran?

1 Answers

That is indeed the correct syntax to declare the type of a constructed (zero-size) array. Intel Fortran is wrong to reject this as Fortran 2003+ syntax: you should report this to Intel support.

In Fortran 2018 this is syntax rule R770 (with R769 and other context).

As a work-around you can allocate det_I to be of size zero or use an array constructor of structure constructors with no elements:

allocate(det_I(0))
det_I = [(SpinOrbIdx(...),i=1,0)]  ! For appropriate structure constructor, etc.
Related