$ cat a.f90 character(10) string string = 'ABCDEEDCBA' write(*,*) index(string,'A',kind=1) end $ gfortran a.f90 && ./a.out 10 I suspect we're passing 1 as a logical BACK argument to the library function. Well, I do more than suspect, I checked and that's indeed what we do :) Work needed in trans-intrinsic.c, probably an easy one. Will need auditing other intrinsics that were added a KIND argument in F2003.
Note: Initially found by James Van Buskirk: http://groups.google.com/group/comp.lang.fortran/msg/e90575a5a6a50e35
Fixed for INDEX and SCAN, but leaving open as reminder for the following: > Will need auditing other intrinsics that were added a KIND argument in F2003.
Subject: Bug 36462 Author: burnus Date: Thu Jun 12 16:16:39 2008 New Revision: 136712 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=136712 Log: 2008-06-12 Tobias Burnus <burnus@net-b.de> PR fortran/36462 * trans-intrinsic.c (gfc_conv_intrinsic_index_scan_verify): Fix passing of the BACK= argument. 2008-06-12 Tobias Burnus <burnus@net-b.de> PR fortran/36462 * gfortran.dg/index_2.f90: New. Added: trunk/gcc/testsuite/gfortran.dg/index_2.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/trans-intrinsic.c trunk/gcc/testsuite/ChangeLog
See also: PR29600.
Adjusting Subject, removing wrong-code.
After a long and tedious look through the F2003 and F2008 standards, it appears we've got this covered.