This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [PATCH,gfortran] Fix for PR 17941
- From: Paul Brook <paul at codesourcery dot com>
- To: fortran at gcc dot gnu dot org
- Cc: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>,gcc-patches at gcc dot gnu dot org
- Date: Sat, 15 Jan 2005 11:07:44 +0000
- Subject: Re: [PATCH,gfortran] Fix for PR 17941
- Organization: CodeSourcery
- References: <20041231055701.GA8937@troutmask.apl.washington.edu>
On Friday 31 December 2004 05:57, Steve Kargl wrote:
> The attached patch fixes PR 17941. The attached program
> is a test program suitable for inclusion in the gfortran
> testsuite.
>
> Briefly, gfortran could not deal with spaces between an
> uniary plus/minus sign in a complex constant. That is,
> "complex, parameter :: c = (- 1.0, + 2)" would invoke
> an error.
This is supposed to be an error. Your code is illegal in free-form source, and
already accepted in fixed-form.
Section 4.3.1.3 "Complex type" defines a complex literal constant as a pair of
signed real literal constants (plus "(,)" separators).
Section 3.2 "Low-level syntax" says that a real literal constant is a single
lexical token.
Section 3.3.1 "Free source form" says that whitespace may not occur within a
lexical token.
We may wish to allow whitespace between the sign character and
digits in signed literal constants as an extension. If so you should also
modify the other places where this can occur.
DATA a /- 1.0/
I'm not sure why we don't just use signed_real_constant here. That's what the
standard says.
A few comments on the patch itself:
> +#include <stdlib.h> /* Needed for alloca. */
> +#include <string.h> /* Needed for strlen. */
This is wrong.
These are already included under the proper conditionals by
system.h.
> @@ -1936,7 +1940,21 @@
> t = buffer + 1;
> else
> t = buffer;
> - mpfr_set_str (e->value.real, t, 10, GFC_RND_MODE);
> +
> + /* Spaces are not allowed in the string passed to mpfr_set_str. The
> + parsing of complex constants may have spaces, so copy the t to u
> + where we remove spaces. */
> + u = alloca (strlen (t) + 1);
"buffer" is already a temporary copy of the string. Fix that instead of making
another copy. I'd suggest copying just the unsigned part of the value (passed
fo gfc_convert_real), then negate the result as necessary.
> + /* Account for whitespace between the uniary minus/plus and the number.
*/
> + while (c == ' ' || c == '\t')
> + {
> + c = gfc_next_char ();
> + count++;
Use gfc_gobble_whitespace().
Paul