public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/52393] New: Erroneous parse of read statement with parenthesised expression in format
@ 2012-02-26 23:50 ian_harvey at bigpond dot com
  2012-02-27  8:08 ` [Bug fortran/52393] " burnus at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: ian_harvey at bigpond dot com @ 2012-02-26 23:50 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52393

             Bug #: 52393
           Summary: Erroneous parse of read statement with parenthesised
                    expression in format
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: ian_harvey@bigpond.com


With gfortran built from recent trunk revision 184585 on fedora 15 x86_64, the
following example:

PROGRAM ReadMeTwo
  IMPLICIT NONE
  CHARACTER(10) :: var
  READ ('(') // 'A)', var  
  PRINT *, var
END PROGRAM ReadMeTwo

gives:

$ gfortran -Wall -std=f2003 ReadMeTwo.f90
ReadMeTwo.f90:4.12:

  READ ('(') // 'A)', var
            1
Error: Expected variable in READ statement at (1)

I think the example is valid fortran and should compile without error.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/52393] Erroneous parse of read statement with parenthesised expression in format
  2012-02-26 23:50 [Bug fortran/52393] New: Erroneous parse of read statement with parenthesised expression in format ian_harvey at bigpond dot com
@ 2012-02-27  8:08 ` burnus at gcc dot gnu.org
  2012-02-27  9:32 ` ian_harvey at bigpond dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-02-27  8:08 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52393

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu.org

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-02-27 07:50:05 UTC ---
Looks like an invalid (logical) UNIT number to me. You either need to have an
integer literal/parameter/variable, a character variable or a "*" for UNIT=.

I think you intended to write instead of:
>   READ ('(') // 'A)', var  

  READ (*,'(' // 'A)') var

That is: With unit "*" and with the ")" not after "')'" but after 'A)'.
Additional, the comma before "var" is not allowed (but a common vendor
extension).


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/52393] Erroneous parse of read statement with parenthesised expression in format
  2012-02-26 23:50 [Bug fortran/52393] New: Erroneous parse of read statement with parenthesised expression in format ian_harvey at bigpond dot com
  2012-02-27  8:08 ` [Bug fortran/52393] " burnus at gcc dot gnu.org
@ 2012-02-27  9:32 ` ian_harvey at bigpond dot com
  2012-02-27 10:26 ` [Bug fortran/52393] I/O: "READ format" statement with parenthesed default-char-expr burnus at gcc dot gnu.org
  2012-02-27 10:34 ` ian_harvey at bigpond dot com
  3 siblings, 0 replies; 5+ messages in thread
From: ian_harvey at bigpond dot com @ 2012-02-27  9:32 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52393

--- Comment #2 from Ian Harvey <ian_harvey at bigpond dot com> 2012-02-27 09:28:22 UTC ---
There is no unit number in that /read-stmt/, just a /format/ and one io item. 
This is the "second" form (per the ordering in the syntax rules from F77 on) of
read that is the companion to the /print-stmt/ (as opposed to the more commonly
seen form that is the companion to a /write-stmt/).  This second form always
reads from the "console" (or whatever the unit * means), just like PRINT always
writes to the console.

R910
/read-stmt/ is READ ( /io-control-spec-list/ ) [ /input-item-list/ ]

            or READ /format/ [ , /input-item-list/ ]     ! <-- This one.

R915
/format/    is /default-char-expr/      ! <-- Then this one.

            or /label/

            or *

The /format/ for this /read-stmt/ is then the /default-char-expr/

  (    '('   )    //     'A)'

which has a pointlessly parenthesised character literal '(' concatenated with
'A)'.  The result of evaluating that is '(A)', which is a valid format
specification (9.6.2.2p2).

The comma is simply the comma that is required in the /read-stmt/ to separate
the format expression from the /input-item-list/.  The common vendor extension
for the extra comma for the other form of /read-stmt/ is problematic here with
respect to ambiguity.

I've used F2008 references above, but this is all standard F90 (salient parts
are F77 even?).  See c.l.f for discussion of ambiguity issues with F2008.  

I accept that this is somewhat obscure and that the specific example is rather
contrived.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/52393] I/O: "READ format" statement with parenthesed default-char-expr
  2012-02-26 23:50 [Bug fortran/52393] New: Erroneous parse of read statement with parenthesised expression in format ian_harvey at bigpond dot com
  2012-02-27  8:08 ` [Bug fortran/52393] " burnus at gcc dot gnu.org
  2012-02-27  9:32 ` ian_harvey at bigpond dot com
@ 2012-02-27 10:26 ` burnus at gcc dot gnu.org
  2012-02-27 10:34 ` ian_harvey at bigpond dot com
  3 siblings, 0 replies; 5+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-02-27 10:26 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52393

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-02-27
            Summary|Erroneous parse of read     |I/O: "READ format"
                   |statement with              |statement with parenthesed
                   |parenthesised expression in |default-char-expr
                   |format                      |
     Ever Confirmed|0                           |1

--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-02-27 10:11:47 UTC ---
OK, that's what you want to achieve. That code definitely breaks with all my
compilers, but it seems to be valid.

In gcc/fortran/io.c's match_io, one has:

  m = gfc_match_char ('(');
  if (m == MATCH_NO)
   {
     // Handle "READ /format/" (and PRINT)
   }
  else
   {
     // Handle READ/WRITE with io-list
   }

Which does not work if the format expression starts with a '('.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/52393] I/O: "READ format" statement with parenthesed default-char-expr
  2012-02-26 23:50 [Bug fortran/52393] New: Erroneous parse of read statement with parenthesised expression in format ian_harvey at bigpond dot com
                   ` (2 preceding siblings ...)
  2012-02-27 10:26 ` [Bug fortran/52393] I/O: "READ format" statement with parenthesed default-char-expr burnus at gcc dot gnu.org
@ 2012-02-27 10:34 ` ian_harvey at bigpond dot com
  3 siblings, 0 replies; 5+ messages in thread
From: ian_harvey at bigpond dot com @ 2012-02-27 10:34 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52393

--- Comment #4 from Ian Harvey <ian_harvey at bigpond dot com> 2012-02-27 10:30:32 UTC ---
Maybe there's some additional cleverness going on then, because the following
equally contrived example:

PROGRAM ReadMeOne
  IMPLICIT NONE
  CHARACTER(10) :: var
  READ ('(A)'), var
  PRINT *, var
END PROGRAM ReadMeOne

which is again supposed to be the second form of read, when compiled with:

  gfortran -Wall -std=f2003

appears to work!


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-02-27 10:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-26 23:50 [Bug fortran/52393] New: Erroneous parse of read statement with parenthesised expression in format ian_harvey at bigpond dot com
2012-02-27  8:08 ` [Bug fortran/52393] " burnus at gcc dot gnu.org
2012-02-27  9:32 ` ian_harvey at bigpond dot com
2012-02-27 10:26 ` [Bug fortran/52393] I/O: "READ format" statement with parenthesed default-char-expr burnus at gcc dot gnu.org
2012-02-27 10:34 ` ian_harvey at bigpond dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).