This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] PR fortran/67987 -- character lengths cannot be negative
- From: FX <fxcoudert at gmail dot com>
- To: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- Cc: fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Fri, 16 Oct 2015 22:17:34 +0200
- Subject: Re: [PATCH] PR fortran/67987 -- character lengths cannot be negative
- Authentication-results: sourceware.org; auth=none
- References: <20151016190831 dot GA81904 at troutmask dot apl dot washington dot edu>
> The attach patch enforces the Fortran Standard's requirement
> that character length must be great than or equal to zero.
We've got to be careful about this. The standard (F2008) has this to say about character lengths:
4.4.3.1. "The number of characters in the string is called the length of the string. The length is a type parameter; its kind is processor dependent and its value is greater than or equal to zero.â
but
4.4.3.2. "If the character length parameter value evaluates to a negative value, the length of character entities declared is zero."
So while strings cannot have negative length, they can be declared with a length parameter value which is itself negative, leading to the string having zero length. Or, said otherwise:
character(len=-2) :: s
is legal and declares a string of zero length, being thus equivalent to:
character(len=0) :: s
Thus: not OK to commit.
FX