If you do not make the function pure and add a write statement just above the sum it verifies it is a bug; as you can query the bounds …
write(*,*)'f1 x=',x,'lbound=',lbound(x,dim=1),'ubound=',ubound(x,dim=1),'size=',size(x)
shows it at least does not lie about the bug, but that is a bug. You could just do “sum(x)” or
query and use the bounds
i=lbound(x,dim=1)
j=ubound(x,dim=1)
sum(i:j)
but it actually shows the bounds have become 0 and size(x)-1; which is wrong. gfortran compiles and runs without debug switches but of course gets the wrong answer (it of course should be -495).
I had changed the example a bit to use all integers and such, but basically it actually printed bounds of 0 and 9:
inputs: 1 2 3 4 5 6 7 8 9 10
f1 x= 1 2 3 4 5 6 7 8 9 10 lbound= 1 ubound= 10 size= 10
y1= 55 y= 55 T
f1(inputs): 55 PASSED
f1 x= 1 2 3 4 5 6 7 8 9 10 lbound= 1 ubound= 10 size= 10
y1= 55 y= 55 T
f2(inputs): 55 PASSED
f1 x= 1 2 3 4 5 6 7 8 9 10 lbound= 1 ubound= 10 size= 10
y1= 55 y= 55 T
f1 x= -54 -53 -52 -51 -50 -49 -48 -47 -46 -45 lbound= 0 ubound= 9 size= 10
y1= -495 y= 115864 F
f3(inputs): 115864 FAILED