From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 379 invoked by alias); 5 Feb 2012 23:01:45 -0000 Received: (qmail 365 invoked by uid 22791); 5 Feb 2012 23:01:43 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 05 Feb 2012 23:01:30 +0000 From: "burnus at gcc dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libfortran X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: burnus at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P4 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.4.7 X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-02/txt/msg00548.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49791 --- Comment #19 from Tobias Burnus 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)