+++ This bug was initially created as a clone of Bug #31059 +++ Gfortran does not report an error if an allocatable array is set to a function of larger size, for example in the code below. program p integer, allocatable :: ivec(:) ivec = [1, 2] ! ivec(:) = func() ! case 1 (already diagnosed) ! ivec(:) = ivec + func() ! case 2 ! ivec(:) = func() + ivec ! case 3 contains function func() integer :: func(3) func = [7, 8, 9] end function func end Uncomment either case 1, case 2 or case 3, and see if the program leads to a runtime error with -fcheck=bounds. Case 1 is diagnosed, but not case 2 and neither case 3.
The use of the intrinsic TRANSFER produces the equivalent of a function but with non-constant size, derived from pr34740, also not detected: program p real, allocatable :: ivec(:) real :: jvec(3) = [1,2,3] ivec = [1.,2.] ivec(:) = transfer (jvec, [1.]) end Detected by NAG, but not by Intel.