Bug 17941 - gfortran: parser chokes on complex literal constant
gfortran: parser chokes on complex literal constant
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: fortran
4.0.0
: P2 normal
: 4.0.0
Assigned To: Not yet assigned to anyone
: monitored, patch
Depends on:
Blocks: 19292
  Show dependency treegraph
 
Reported: 2004-10-11 20:33 UTC by Harald Anlauf
Modified: 2005-01-23 22:39 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-10-11 20:51:07


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Harald Anlauf 2004-10-11 20:33:08 UTC
Hi,

here's another problem, this time with "legacy f90" code:

program gfcbug17
  ! gfortran cannot parse this complex constant:
  complex, parameter :: c0 = (- 0.5, -0.5)
  print *, c0
end program gfcbug17

I get:


 In file gfcbug17.f90:3

  complex, parameter :: c0 = (- 0.5, -0.5)
                                  1
Error: Expected a right parenthesis in expression at (1)


Apparently the space between the "-" and 0.5 lets the parser choke.
Can the parsing rules be relaxed to accept the above form?

Cheers,
-ha
Comment 1 Andrew Pinski 2004-10-11 20:51:07 UTC
Confirmed, IFC accepts the code.
Comment 2 Tobias Schlüter 2004-10-11 22:48:43 UTC
I'm not sure if this suffices, will try tomorrow:

Index: primary.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/primary.c,v
retrieving revision 1.13
diff -u -p -r1.13 primary.c
--- primary.c   7 Oct 2004 15:12:01 -0000       1.13
+++ primary.c   11 Oct 2004 22:46:36 -0000
@@ -1028,6 +1028,13 @@ match_const_complex_part (gfc_expr ** re

   for (;; c = gfc_next_char (), count++)
     {
+      if (c == ' ')
+       {
+         if (seen_dp || seen_digits)
+           break;
+         continue;
+       }
+
       if (c == '.')
        {
          if (seen_dp)
Comment 3 Tobias Schlüter 2004-10-12 21:37:23 UTC
No, that's not sufficient. mpfr_set_str apparently doesn't like spaces in constants.
Comment 4 Steve Kargl 2004-12-31 06:06:04 UTC
The patch here

http://gcc.gnu.org/ml/fortran/2004-12/msg00265.html

fiexes the problem.
Comment 5 Andrew Pinski 2004-12-31 06:08:33 UTC
(In reply to comment #4)
> fiexes the problem.
s/fiexes/fixes/
Comment 6 Paul Brook 2005-01-15 11:09:39 UTC
Technically illagal, so removing rejects-valid keyword.
IFC is not a particularly good judge of whether code is legal ;-)
Comment 7 Steve Kargl 2005-01-15 20:34:08 UTC
Paul, the code is legal!  Both NAG and Lahey compile the code
without warning or error.  Apparently, IFC also compiles the
code.  I just sent you a new patch to fix the bug.
Comment 8 Steve Kargl 2005-01-15 22:27:25 UTC
I started a thread on c.l.f.  The title is "whitespace in signed real literal
constants.  So far, it appears that the code is indeed standard conforming.
Comment 9 Steve Kargl 2005-01-22 01:32:56 UTC
A new path is available.

http://gcc.gnu.org/ml/fortran/2005-01/msg00243.html
Comment 10 CVS Commits 2005-01-23 22:29:49 UTC
Subject: Bug 17941

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	pbrook@gcc.gnu.org	2005-01-23 22:29:41

Modified files:
	gcc/fortran    : ChangeLog arith.c primary.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gfortran.dg: complex_int_1.f90 real_const_1.f 
	                           real_const_2.f90 

Log message:
	2004-01-23  Paul Brook  <paul@codesourcery.com>
	Steven G. Kargl  <kargls@comcast.net>
	
	PR fortran/17941
	* arith.c (gfc_convert_real): Remove sign handling.
	* primary.c (match_digits): Allow whitespace after initial sign.
	(match_real_const): Handle signs here.  Allow whitespace after
	initial sign.  Remove dead code.
	(match_const_complex_part): Remove.
	(match_complex_part): Use match_{real,integer}_const.
	(match_complex_constant): Cross-promote integer types.
	testsuite/
	* gfortran.dg/real_const_1.f: New test.
	* gfortran.dg/real_const_2.f90: New test.
	* gfortran.dg/complex_int_1.f90: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/ChangeLog.diff?cvsroot=gcc&r1=1.312&r2=1.313
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/arith.c.diff?cvsroot=gcc&r1=1.20&r2=1.21
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/primary.c.diff?cvsroot=gcc&r1=1.17&r2=1.18
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4927&r2=1.4928
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/complex_int_1.f90.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/real_const_1.f.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/real_const_2.f90.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 11 Paul Brook 2005-01-23 22:38:51 UTC
Fixed.