public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "burnus at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libfortran/49791] [4.4/4.5/4.6/4.7 Regression] Formatted namelist reads fails with: Cannot match namelist object
Date: Sun, 05 Feb 2012 23:01:00 -0000	[thread overview]
Message-ID: <bug-49791-4-KvHPctraOM@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-49791-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #19 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-02-05 23:00:16 UTC ---
I think the patch suggested in
http://gcc.gnu.org/ml/fortran/2011-07/msg00252.html is actually correct - which
then fixes the issue of comment 18. 

--- ../../libgfortran/io/list_read.c    (Revision 183913)
+++ ../../libgfortran/io/list_read.c    (Arbeitskopie)
@@ -2206,3 +2211,4 @@ nml_parse_qualifier (st_parameter_dt *dt
                      || !(compile_options.allow_std & GFC_STD_GNU)
-                     || dtp->u.p.ionml->type == BT_DERIVED)
+                     || (dtp->u.p.ionml->type == BT_DERIVED
+                         && !dtp->u.p.ionml->touched))
                    ls[dim].end = ls[dim].start;


However, one then runs into a failure for fortran.dg/namelist_66.f90, but it
fails in the same way for the program below. Contrary to comment 18 (which is
about a vendor extension), I believe the following program *is* valid. At least
one combines an incomplete read of the whole array "(:)" with some explicit
reads.


One should recall that in namelist, all character constants have to start with
a quotation mark. Thus, if one reads [a-z], one is always matching a namelist
object name! Thus, before reading the next array element, one should check
whether one has as next item something starting with "a-zA-z"; if so, one does
an early return from nml_read_obj



Expected (as with NAG):
 &NAML1 TRACER = aa T bb T XX F/

Result with gfortran:
 Fortran runtime error: Cannot match namelist object name 'bb'


Example:

type ptracer
   character(len = 2)  :: sname
   logical              :: lini
end type ptracer
type(ptracer) , dimension(3) :: tracer
namelist/naml1/  tracer

tracer(:) = ptracer('XXX', .false.)
open (99, file='nml.dat', status="replace")
write(99,*) "&naml1"
write(99,*) "   tracer(:)   = 'aa' , .true."
write(99,*) "   tracer(2)   = 'bb' , .true. /"
rewind(99)
read (99, nml=naml1)
write (*, nml=naml1)
close (99, status="delete")
end



Using the following early draft patch, the example above works. However, if one
changes one tracer(2) line to:
  write(99,*) "   tracer(2)   = 'bb' , .true. "
(i.e. removes the "/") one gets:
  Fortran runtime error: End of file
which looks reasonable.

However, if one adds after that line:
  write(99,*) "   tracer(3)   = 'cc' , .true. "
one now gets:
  Fortran runtime error: Internal namelist read error

It works correctly if a "/" is added in the last write above.


Hence, I think the patch is in the correct direction, but not yet ready.

--- ../../libgfortran/io/list_read.c    (Revision 183913)
+++ ../../libgfortran/io/list_read.c    (Arbeitskopie)
@@ -2517,2 +2518,19 @@ nml_read_obj (st_parameter_dt *dtp, name

+/*       if (dtp->u.p.expanded_read)*/
+           {
+             char c;
+
+             /* Skip whitespace.  */
+             do
+               c = next_char (dtp);
+             while (c != EOF && (c == ' ' || c == '\t' || c == '\r' || c ==
'\n'));
+             unget_char (dtp, c);
+
+             /* Stop early - next namelist object found. */
+             if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
+             {
+               return SUCCESS;
+             }
+           }
+
           switch (nl->type)


  parent reply	other threads:[~2012-02-05 23:01 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-20  8:05 [Bug libfortran/49791] New: [4.6 Regression] Formatted namelist reads of arrays don't work quantum.analyst at gmail dot com
2011-07-20  9:31 ` [Bug libfortran/49791] [4.4/4.5/4.6/4.7 Regression] Formatted namelist reads fails with: Cannot match namelist object burnus at gcc dot gnu.org
2011-07-20 15:43 ` kargl at gcc dot gnu.org
2011-07-20 16:20 ` burnus at gcc dot gnu.org
2011-07-20 17:16 ` sgk at troutmask dot apl.washington.edu
2011-07-20 17:25 ` burnus at gcc dot gnu.org
2011-07-20 21:09 ` quantum.analyst at gmail dot com
2011-07-20 21:23 ` sgk at troutmask dot apl.washington.edu
2011-07-20 21:55 ` burnus at gcc dot gnu.org
2011-07-21 18:33 ` jvdelisle at gcc dot gnu.org
2011-07-22  1:28 ` jvdelisle at gcc dot gnu.org
2011-07-22 13:51 ` jvdelisle at gcc dot gnu.org
2011-07-22 22:45 ` burnus at gcc dot gnu.org
2011-07-23 10:27 ` burnus at gcc dot gnu.org
2011-07-23 15:26 ` jvdelisle at gcc dot gnu.org
2011-07-27 17:46 ` burnus at gcc dot gnu.org
2011-07-27 21:35 ` burnus at gcc dot gnu.org
2011-07-28  5:40 ` burnus at gcc dot gnu.org
2011-07-28  5:48 ` burnus at gcc dot gnu.org
2011-08-01 14:08 ` rguenth at gcc dot gnu.org
2012-02-05 23:01 ` burnus at gcc dot gnu.org [this message]
2012-02-06 22:19 ` burnus at gcc dot gnu.org
2012-03-13 14:24 ` [Bug libfortran/49791] [4.5/4.6/4.7/4.8 " jakub at gcc dot gnu.org
2012-07-02 14:04 ` [Bug libfortran/49791] [4.6/4.7/4.8 " rguenth at gcc dot gnu.org
2012-07-02 14:05 ` orion at cora dot nwra.com
2013-01-02 17:18 ` jvdelisle at gcc dot gnu.org
2013-03-30  3:18 ` [Bug libfortran/49791] [4.6/4.7/4.8/4.9 " jvdelisle at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-49791-4-KvHPctraOM@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).