You could consider instead of creating a version with asprintf as in
trans-array.c to call a library function.
That way we could improve the error message output (cf. PR28494):
Currently:
Fortran runtime error: Array reference out of bounds for array 'r',
upper bound of dimension 1 exceeded (in file 'array2.f90', at line 4)
With a library function the following is possible:
Fortran runtime error: Array reference out of bounds. Subscript 1 of
array 'r' (value 5) exceeds upper bound of 4 (in file 'array2.f90', at
line 4)"
When extracting the name of the array for the error message consider
also derived types:
The current trans-array.c prints for 'i' exceeding the bounds: 'V'
rather than 'array' for
V(1)%array(i)
The best output would be of cause something like 'v%array'. (PR29800)