From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20675 invoked by alias); 4 Jan 2013 16:59:04 -0000 Received: (qmail 20277 invoked by uid 48); 4 Jan 2013 16:58:41 -0000 From: "kargl at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/55117] Programs fails to read namelist (contains derived types objects) Date: Fri, 04 Jan 2013 16:59:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: kargl at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: CC 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: 2013-01/txt/msg00335.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55117 kargl at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |kargl at gcc dot gnu.org --- Comment #7 from kargl at gcc dot gnu.org 2013-01-04 16:58:36 UTC --- (In reply to comment #6) > Another manifestation of this problem is with type extension. Here is another > small example which fails. (Tested on v4.6.3 and also a 1/4/2013 snapshot of > the 4.8 trunk.): > > program test_type_extension > > type t1_t > real :: x > end type t1_t > > type, extends(t1_t) :: t1e_t > character(8) :: string > end type t1e_t > > type(t1e_t) :: t1e > > integer :: answer > namelist /test_NML/ t1e, answer > > open(unit=1,file='test1.inp') > read(1,NML=test_NML) > > write(*,*) t1e%x, t1e%string, answer > > end program test_type_extension > > File test1.inp contains: > > &test_NML > t1e%x = 2.,t1e%string='gfortran',answer=42 > / > > wws@w6ws-4:~/fortran/xxx$ gfortran namelist.f90 > wws@w6ws-4:~/fortran/xxx$ a.out > At line 17 of file namelist.f90 (unit = 1, file = 'test1.inp') > Fortran runtime error: Cannot match namelist object name %x If one modifies your code to have gfortran create the file with the namelist, it can then read it back. Here's what I have program test_type_extension type t1_t real :: x end type t1_t type, extends(t1_t) :: t1e_t character(8) :: string end type t1e_t type(t1e_t) :: t1e integer :: answer namelist /test_NML/ t1e, answer t1e%x = 2. t1e%string='gfortran' answer=42 open(unit=2,file='test2.inp') write(2,NML=test_NML) close(2) t1e%x = 0 t1e%string='' answer=0 open(unit=2,file='test2.inp') read(2,NML=test_NML) close(2) write(*,*) t1e%x, t1e%string, answer open(unit=1,file='test1.inp') read(1,NML=test_NML) write(*,*) t1e%x, t1e%string, answer end program test_type_extension % gfc4x -o z foo.f90 && ./z 2.00000000 gfortran 42 At line 36 of file foo.f90 (unit = 1, file = 'test1.inp') Fortran runtime error: Cannot match namelist object name %x % cat test2.inp &TEST_NML T1E%T1_T%X= 2.00000000 , T1E%STRING="gfortran", ANSWER= 42, / It appears that gfortran's handling of an extended derived type in its namelist code is incorrect.