Taken from http://www.polyhedron.com/pb05/linux/diagnose.html ------<CBND1.F>------- ! character bound error - local variable program cbnd1 character*10 zz i = 2 j = i+9 zz(i:j) = 'abcdef' print * , zz end ---------------------- gfortran-4.2 -Wall -pedantic -fbounds-check CBND1.F ./a.out ^Aabcdef
Expected: Issue a run-time error message. Examples of other compilers: ifort64-9.1 -C -check all -warn all,nodec,interfaces -gen_interfaces -traceback -fpe0 -fpstkchk CBND1.F ./a.out forrtl: severe (408): fort: (4): Variable ZZ has substring ending point 11 which is greater than the variable length of 10 g95 -Wall -pedantic -fbounds-check -ftrace=full CBND1.F ./a.out At line 6 of file CBND1.F Traceback: (Innermost first) Fortran runtime error: Substring reference out of bounds: (2:11) in string of length 10 NAG: f95 -C=all -C=undefined -info -g -gline CBND1.F Out of range: substring ending position 11 is greater than length 10 Program terminated by fatal error In CBND1, line 6 of CBND1.F The following is even detected at compile time by the intel and NAGf95 compilers (gfortran does not detect it at compile or runtime): --------<CBND3.F>-------------- ! Check character bound error - assign to dummy argument which is larger than actual arg program cbnd3 character*10 zz,zzz common /aaa/zz,zzz zz = '0000000000' zzz = '1111111111' call sub(zz) print * , zzz end subroutine sub(zz) character*11 zz zz = 'abcdef' print * , zz end --------------------------- -- Summary: -fbounds-check should catch substring out of range accesses Product: gcc Version: 4.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: tobias dot burnus at physik dot fu-berlin dot de http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27588