This is the mail archive of the
mailing list for the GCC project.
Re: [PATCH] Fix FMT= with CHARACTER arrays (PR fortran/39865, take 2)
On Tue, May 12, 2009 at 07:29:29PM -0700, Jerry DeLisle wrote:
> I very much appreciate your effort on this.
> F2003 standard says that FMT=format
> R914 format is default-char-expr
> or label
> or *
> It seems clear to me that anything other then the three cases in R914 is
> invalid Fortran and we should throw a diagnostic.
> I see the exact same requirement in F95, and F2008
> The F77 standard uses different language but it is equivalent, so this
> suggests it is not a legacy behaviour.
> Also, it is clear that if a character array is specified, the format
> specifiers begin with the left most character in the element. Elements
> are concatenated in array element order, forming one string.
> If a single element is specified it is treated as a single string and the
> formatting does not extend past that element. In other words, the length
> of the single element string is the size of the character element of the
I wasn't talking about character elements and character arrays, those
are certainly covered by the standard and aren't questionable.
Character elements don't even hit this routine, see set_string doing:
if (e->ts.type == BT_CHARACTER && e->rank == 0)
gfc_conv_expr (&se, e);
/* Array assigned Hollerith constant or character array. */
else if (e->symtree && (e->symtree->n.sym->as->rank > 0))
gfc_convert_array_to_string (&se, e);
Character arrays are e->rank > 0 and the patch I've posted fixes the
behavior for them (when the array is not packed or when e->expr_type
isn't a variable or when the array isn't referenced as whole).
The user testcase that lead me to posting the patch was just
using array section of a character array.
The issue I'm discussing are legacy non-character arrays containing
Hollerith constants where a single element is passed. As gfortran
made an extra effort to use size of the remaining array and as ifort
according to Tobias apparently does the same in that case, I'd assume
it is intentional.