# Gfortran bug or am I missing something?

**URL:** <https://fortran-lang.discourse.group/t/gfortran-bug-or-am-i-missing-something/5476>\
**Category:** Help\
**Created:** [April 1, 2023, 5:08pm UTC](https://fortran-lang.discourse.group/t/gfortran-bug-or-am-i-missing-something/5476 "2023-04-01T17:08:27Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [April 2, 2023, 11:04pm UTC](https://fortran-lang.discourse.group/t/gfortran-bug-or-am-i-missing-something/5476/14 "2023-04-02T23:04:06Z")

</div>

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 …

```plaintext
  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

```plaintext
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:

```plaintext
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

```

---

_[View the full topic](https://fortran-lang.discourse.group/t/gfortran-bug-or-am-i-missing-something/5476)._
