Follow up to PR 37746 / PR 40383. I believe the following program is valid due to the storage association/argument association. However, with -fcheck=bounds one gets:
At line 5 of file aa.f90 Fortran runtime error: Actual string length is shorter than the declared one for dummy argument 'a' (2/4) Note: If one changes the actual argument to ["ab"] or ["a","b"] both NAG f95 and gfortran are able to diagnose the problem at compile time. For the program below, neither compilers gives a compile-time error/warning. (Nor does NAG with -C=all give a run-time error.) program test implicit none call sub(["ab", "cd"]) contains subroutine sub(a) character(len=4) :: a(1) print *, a(1) end subroutine sub end program test >From the standard (F2003, cf. 16.4.3 Storage association): "In a storage association context [...] (3) A nonpointer scalar object of type default character and character length len occupies len contiguous character storage units; [...] (7) A nonpointer array occupies a sequence of contiguous storage sequences, one for each array element, in array element order (6.2.2.2); [...] A sequence of storage sequences forms a storage sequence." (And a bit further down one finds a bit more to "argument association".) The challenge is diagnose this properly. The problem is that the array size is _not_ passed. One solution would be to enable the check only with -std=f95. I believe the argument association is only allowed since Fortran 2003. Or one does a proper argument checking by checking whether the argument is an array. For this one needs -fcheck=call and save the arguments in some external variable, then one checks whether the current procedure matches the procedure where the global variable stores the argument information - and then uses this information for the array check. Sorry, I don't have any better idea at the moment. Note: The primary use of the argument association is: call c_func("abc") with subroutine c_func(str) bind(C) character(len=1,kind=c_char) :: str(*) as otherwise one had to use 'call c_func(["a","b","c"])' which is awkward! -- Summary: -fbounds-check: False positive due to ignoring storage association Product: gcc Version: 4.5.0 Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: burnus at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40452