https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109453

            Bug ID: 109453
           Summary: UBOUND incorrect when used in declartion of another
                    array
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jvdelisle at gcc dot gnu.org
  Target Milestone: ---

The following program illustrates:

integer, parameter :: a(0:19)=(/(i,i=0,19)/)
integer :: b(-1:ubound(a,dim=1)) ! <<<< This gives wrong result
! integer, parameter  :: c = ubound(a,dim=1) ! Using an intermediate works
! integer :: b(-1:c) ! Using the intermediate
b(-1:ubound(a,dim=1))=(/0,a(0:19)/)
write(*,'(1000i3)') a
write(*,'(1000i3)') b
print *, rank(b), size(b), ubound(b), lbound(b)
print *, rank(a), size(a), ubound(a), lbound(a)
end

Giving:

$ ./a.out 
  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19
  0  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19  0
           1          22          20          -1
           1          20          19           0

Commenting out the wrong result line and uncommenting the alternate lines:

$ ./a.out 
  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19
  0  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19
           1          21          19          -1
           1          20          19           0

Looks like an off by one somewhere.

Reply via email to