This is not a bug (I don't think the code is legal), but surely we could do better than this: $ cat zero_spread_2.f90 real,allocatable :: bar(:,:),foo(:) allocate(foo(0)) bar = spread(foo,dim=1,ncopies=1) print *, allocated(bar) end $ gfortran zero_spread_2.f90 && ./a.out T Same goes for most of the transformational intrinsics. libgfortran/intrinsic/spread_generic.c says: /* The front end has signalled that we need to populate the return array descriptor. */ We should really find another way of signaling this to the library (additional argument?) so that we can perform some checking.
I don't think that the original bug report here is quite right. See here: real,allocatable :: bar(:,:),foo(:) allocate(foo(0)) bar = spread(foo,dim=1,ncopies=1) print *, shape(bar) end This prints: 1 0 That's perfectly correct; bar is "allocated" according to Fortran semantics, but of size 0. However, there's this related case where foo is never allocated, which seems to be what the OP was talking about: real,allocatable :: bar(:,:),foo(:) bar = spread(foo,dim=1,ncopies=1) print *, shape(bar) end This is not a legal use of a non-allocated variable, but "-fcheck=all" misses it. If you run, you get: 1 1 Which is nonsense.
Related to/Duplicate of pr36683?