On WSL2, my gfortran is GNU Fortran (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, and it compiles the code you gave. On Windows I have GNU Fortran (GCC) 12.0.1 20220213 installed from equation.com , and it says
reshape_question.f90:4:12:
4 | x = reshape([real ::],n)
| 1
Error: Without padding, there are not enough elements in the intrinsic RESHAPE source at (1) to match the shape
Adding the suggested PAD argument, the code
implicit none
integer, parameter :: n(3) = [3,2,1]
real, allocatable :: x(:,:,:)
x = reshape([real ::],n,pad=[-1.0,1.0])
print*,shape(x)
print*,x
end
compiles and runs, giving
3 2 1
-1.00000000 1.00000000 -1.00000000 1.00000000 -1.00000000 1.00000000
Metcalf, Reid, and Cohen (2018) say
reshape (source, shape [,pad] [,order] ) returns an array with shape
given by the rank-one integer array shape, and type and type parameters those of the
array source. The size of shape must be constant, and its elements must not be negative.
If pad is present, it must be an array of the same type and type parameters as
source. If pad is absent or of size zero, the size of the result must not exceed the size
of source.