Bug 23151 - print (buf, format), expression should be invalid
Summary: print (buf, format), expression should be invalid
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: unknown
: P2 normal
Target Milestone: ---
Assignee: Thomas Koenig
URL:
Keywords: accepts-invalid, diagnostic
Depends on:
Blocks: 19292
  Show dependency treegraph
 
Reported: 2005-07-30 20:37 UTC by Thomas Koenig
Modified: 2006-05-31 20:51 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-05-25 21:36:29


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Koenig 2005-07-30 20:37:17 UTC
The following is illegal:

$ cat print.f90
program main
  character*80 line
  print (line,'(A)'), 'hello'
end program main
$ cat print.f90
program main
  character*80 line
  print (line,'(A)'), 'hello'
end program main
$ gfortran print.f90
$ gfortran -std=f95 print.f90
$ gfortran -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.1/configure --prefix=/home/ig25
--enable-languages=c,f95 : (reconfigured) ../gcc-4.1/configure
--prefix=/home/ig25 --enable-languages=c,f95
Thread model: posix
gcc version 4.1.0 20050726 (experimental)
Comment 1 Thomas Koenig 2005-11-02 21:59:16 UTC
g77 groks this:

$ cat prt.f
      program main
      character*80 line
      print (line,'(A)'), 'hello'
      end
$ g77 prt.f
prt.f: In program `main':
prt.f:3:
         print (line,'(A)'), 'hello'
                ^
Real part of complex constant at (^) must be a real or integer constant -- otherwise use CMPLX() or COMPLEX() in place of ()
prt.f:3:
         print (line,'(A)'), 'hello'
                     ^
Imaginary part of complex constant at (^) must be a real or integer constant -- otherwise use CMPLX() or COMPLEX() in place of ()
Comment 2 Thomas Koenig 2006-05-23 20:48:54 UTC
This patch looks as if it could do the job:

Index: io.c
===================================================================
--- io.c        (revision 113958)
+++ io.c        (working copy)
@@ -2424,6 +2424,12 @@
       dt->io_unit = default_unit (k);
       goto get_io_list;
     }
+  else
+    {
+      /* print (*,*) is invalid.  */
+      if (gfc_match_char ('('))
+       goto syntax;
+    }

   /* Match a control list */
   if (match_dt_element (k, dt) == MATCH_YES)
Comment 3 Thomas Koenig 2006-05-23 21:17:16 UTC
The previous patch was bogus.  This one actually works:

Index: io.c
===================================================================
--- io.c        (revision 113958)
+++ io.c        (working copy)
@@ -2424,6 +2424,12 @@
       dt->io_unit = default_unit (k);
       goto get_io_list;
     }
+  else
+    {
+      /* print (*,*) is invalid.  */
+      if (k == M_PRINT)
+       goto syntax;
+    }

   /* Match a control list */
   if (match_dt_element (k, dt) == MATCH_YES)
Comment 4 patchapp@dberlin.org 2006-05-25 18:55:13 UTC
Subject: Bug number PR23151

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-05/msg01323.html
Comment 5 Thomas Koenig 2006-05-26 19:53:28 UTC
Subject: Bug 23151

Author: tkoenig
Date: Fri May 26 19:53:18 2006
New Revision: 114138

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114138
Log:
2006-05-26  Thomas Koenig  <Thomas.Koenig@online.de>

	PR fortran/23151
	* io.c (match_io):  print (1,*) is an error.

2006-05-26  Thomas Koenig  <Thomas.Koenig@online.de>

	PR fortran/23151
	* gfortran.dg/inquire_9.f90:  Fix illegal print syntax.
	* gfortran.dg/print_parentheses_1.f:  New test.
	* gfortran.dg/print_parentheses_2.f90:  New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/print_parentheses_1.f
    trunk/gcc/testsuite/gfortran.dg/print_parentheses_2.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/io.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/inquire_9.f90

Comment 6 Thomas Koenig 2006-05-31 20:51:00 UTC
Subject: Bug 23151

Author: tkoenig
Date: Wed May 31 20:50:34 2006
New Revision: 114281

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114281
Log:
2006-05-31  Thomas Koenig  <Thomas.Koenig@online.de>

	PR fortran/23151
	Backport from mainline.
	* io.c (match_io):  print (1,*) is an error.

2006-05-31  Thomas Koenig  <Thomas.Koenig@online.de>

	PR fortran/23151
	Backport from mainline.
	* gfortran.dg/inquire_9.f90:  Fix illegal print syntax.
	* gfortran.dg/print_parentheses_1.f:  New test.
	* gfortran.dg/print_parentheses_2.f90:  New test.


Added:
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/print_parentheses_1.f
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/print_parentheses_2.f90
Modified:
    branches/gcc-4_1-branch/gcc/fortran/ChangeLog
    branches/gcc-4_1-branch/gcc/fortran/io.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/inquire_9.f90

Comment 7 Thomas Koenig 2006-05-31 20:51:37 UTC
Fixed on trunk and 4.1.  Closing.