Bug 77649 - Wrong error reported with bound checking enabled
Summary: Wrong error reported with bound checking enabled
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks: Fortran_bounds_checking
  Show dependency treegraph
 
Reported: 2016-09-19 15:28 UTC by mrestelli
Modified: 2019-01-29 14:55 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-09-20 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mrestelli 2016-09-19 15:28:28 UTC
When compiled with  -fcheck=all  the following code produces an
incorrect error at runtime:


$ gfortran test.f90 -fcheck=all -o test
$ ./test
At line 13 of file test.f90
Fortran runtime error: Index '2' of dimension 1 of array 'text' above upper bound of 1


$ gfortran --version
GNU Fortran (GCC) 7.0.0 20160919 (experimental)


program p
 implicit none
 character(len=10) :: s

 s = fs((/"abc","d  "/))

 write(*,*) s
contains

 function fs(text) result(s)
  character(len=*), intent(in) :: text(:)
  integer :: i
  character(len=sum((/(len_trim(text(i)) , i=1,size(text))/))) :: s

   write(*,*) "len(s) = ", len(s)
   s = "XYZ"
 end function fs

end program p
Comment 1 Martin Liška 2016-09-20 07:38:07 UTC
Confirmed on all releases I have (4.5.0+).