How to learn new Fortran features

This syntax is elegant but I’ve found it to have caveats with some compilers having troubles with it in certain cases. So far I consider it unstable.

The most robust approach so far is to customize a reallocate using move_alloc, say:

subroutine reallocate( x , newsze )
    real, intent(inout), allocatable :: x(:)
    real, allocatable :: temp(:)
    integer, intent(in) :: newsze
    if(.not.allocated(x)) then
        allocate( x( newsze ) )
    else if( newsze > size( x ) ) then
        allocate( temp( newsze ) )
        temp(1:size(x)) = x(1:size(x)) 
        call move_alloc( from=temp , to=x )
    end if
end subroutine

You can then make it as fancy as you want for handling several use cases.

A read that might be interesting is this feature enhancement proposal: REALLOCATABLE attribute