Assumed-rank arrays

It’s a bug in Intel Fortran.

In the meantime, a workaround can be a subroutine option and which may be advantageous in certain circumstances:

module m
contains
   pure subroutine flatten(x, y)
       real, intent(in) :: x(..)
       real, intent(inout) :: y(size(x))
       select rank(x)
         rank(1) ; y = reshape(x,shape=[size(x)])
         rank(2) ; y = reshape(x,shape=[size(x)])
       end select
   end subroutine
   pure subroutine flatten2(x, y)
       real, intent(in) :: x(..)
       real, intent(out), allocatable :: y(:)
       select rank(x)
         rank(1) ; y = reshape(x+1.0,shape=[size(x)])
         rank(2) ; y = reshape(x+1.0,shape=[size(x)])
       end select
     end subroutine
end module
   use m
   real :: a(2,3)
   real, allocatable :: b(:)
   a = 1.0
   call flatten2(a, b)
   print *, "size(b): ", size(b), "; expected is ", size(a)
   print *, "b(2*3): ", b(2*3), "; expected is ", a(2,3)+1.0
   call flatten(a, b)
   print *, "b(2*3): ", b(2*3), "; expected in ", a(2,3)
 end

C:\temp>ifort /standard-semantics r.f90
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.2.0 Build 20210228_000000
Copyright (C) 1985-2021 Intel Corporation. All rights reserved.

Microsoft (R) Incremental Linker Version 14.27.29112.0
Copyright (C) Microsoft Corporation. All rights reserved.

-out:r.exe
-subsystem:console
r.obj

C:\temp>r.exe
size(b): 6 ; expected in 6
b(23): 2.000000 ; expected is 2.000000
b(2
3): 1.000000 ; expected is 1.000000

C:\temp>