[Patch, fortran] PR51976 - [F2003] Support deferred-length character components of derived types (allocatable string length)
W Spector
w6ws@earthlink.net
Sun Mar 9 16:36:00 GMT 2014
Janus,
The 'No initializer for component...' error, when the derived type
definition is in a module, is really a problem. It seriously restricts
the usefulness of the feature for obvious reasons.
Also two more issues:
4.) Array assignment doesn't work. This is mentioned in the revised web
page, but the compiler accepts the code without indicating an
unsupported case and then does nothing:
wws@w6ws-4:~/fortran/strings$ cat deflen_test6.F90
program deflen_test6
implicit none
type def_strings
#if !defined (FIXED_LENGTH)
character(:), allocatable :: strings(:)
#else
character(16), allocatable :: strings(:)
#endif
end type
type(def_strings) :: my_strings
my_strings%strings = [ &
"first string ", &
"second string", &
"third string " &
]
print *, my_strings%strings
end program
wws@w6ws-4:~/fortran/strings$ /usr/local/gcc-trunk/bin/gfortran
deflen_test6.F90
wws@w6ws-4:~/fortran/strings$ a.out
wws@w6ws-4:~/fortran/strings$
wws@w6ws-4:~/fortran/strings$ /usr/local/gcc-trunk/bin/gfortran
-DFIXED_LENGTH deflen_test6.F90
wws@w6ws-4:~/fortran/strings$ a.out
first string second string third string
wws@w6ws-4:~/fortran/strings$
5.) This is a problem with the existing non-derived type capability.
(It is also a problem in my 4.7.2 compiler.) Probably should be the
subject of a different PR:
wws@w6ws-4:~/fortran/strings$ cat deflen_test7.f90
program deflen_test7
implicit none
character(:), allocatable :: localstrings(:)
localstrings = [ &
"first string ", &
"second string", &
"third string " &
]
print *, localstrings
end program
wws@w6ws-4:~/fortran/strings$ /usr/local/gcc-trunk/bin/gfortran
deflen_test7.f90
wws@w6ws-4:~/fortran/strings$ a.out
third string third string third string
wws@w6ws-4:~/fortran/strings$
Walter
On 03/09/2014 08:38 AM, W Spector wrote:
>> I have just committed the patch as r208386, thereby implementing
>> deferred-length character components on 4.9 trunk. One big plea to the
>> users: Please test this as soon as possible!
>
> Janus - I have updated my test compiler to the current trunk. A couple
> of things:
>
> 1.) I can reproduce the 'gimplification' ICE in comment #8 with the
> ALLOCATE statement,
>
> 2.) I can reproduce the 'No initializer for component...' error also
> mentioned in comment #8,
>
> 3.) My example in comment #12 appears to work fine. However when
> running the example under valgrind, memory leaks are indicated. I cut
> the example down quite a bit, and it seems that there are leaks
> regardless of whether derived types are used or not. So this isn't a
> regression due to this patch, but something that has been around for a
> while:
>
> wws@w6ws-4:~/fortran/strings$ cat deflen_test5.f90
> program strings
> implicit none
>
> character(:), allocatable :: string
>
> string = "first string"
> print *, string
> string = "second string"
> print *, string
> string = "3rd string"
> print *, string
>
> end program
> wws@w6ws-4:~/fortran/strings$ /usr/local/gcc-trunk/bin/gfortran
> --version deflen_test5.f90
> GNU Fortran (GCC) 4.9.0 20140306 (experimental)
> Copyright (C) 2014 Free Software Foundation, Inc.
>
> GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
> You may redistribute copies of GNU Fortran
> under the terms of the GNU General Public License.
> For more information about these matters, see the file named COPYING
>
> wws@w6ws-4:~/fortran/strings$ valgrind --leak-check=full a.out
> ==3153== Memcheck, a memory error detector
> ==3153== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
> ==3153== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
> ==3153== Command: a.out
> ==3153==
> first string
> second string
> 3rd string
> ==3153==
> ==3153== HEAP SUMMARY:
> ==3153== in use at exit: 10 bytes in 1 blocks
> ==3153== total heap usage: 24 allocs, 23 frees, 11,851 bytes allocated
> ==3153==
> ==3153== 10 bytes in 1 blocks are definitely lost in loss record 1 of 1
> ==3153== at 0x4C2B4F0: realloc (in
> /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==3153== by 0x400B0E: MAIN__ (in /home/wws/fortran/strings/a.out)
> ==3153== by 0x400C12: main (in /home/wws/fortran/strings/a.out)
> ==3153==
> ==3153== LEAK SUMMARY:
> ==3153== definitely lost: 10 bytes in 1 blocks
> ==3153== indirectly lost: 0 bytes in 0 blocks
> ==3153== possibly lost: 0 bytes in 0 blocks
> ==3153== still reachable: 0 bytes in 0 blocks
> ==3153== suppressed: 0 bytes in 0 blocks
> ==3153==
> ==3153== For counts of detected and suppressed errors, rerun with: -v
> ==3153== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 2 from 2)
> wws@w6ws-4:~/fortran/strings$
>
>
> Walter
>
More information about the Fortran
mailing list