[Bug fortran/77504] [9/10/11/12 Regression] "is used uninitialized" with allocatable string and array constructors
mailling-lists-bd at posteo dot de
gcc-bugzilla@gcc.gnu.org
Mon Jan 17 14:24:44 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77504
Baptiste Demoulin <mailling-lists-bd at posteo dot de> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mailling-lists-bd at posteo dot de
--- Comment #27 from Baptiste Demoulin <mailling-lists-bd at posteo dot de> ---
I don't know if it is related to this bug, but I found that this program:
program test_allocatable
implicit none
integer, allocatable :: array(:)
character(len=:), allocatable :: string
integer :: i
character(len=64) :: buf
allocate(array(4))
array = [1, 2, 3, 4]
do i=1, size(array) - 1
write(buf, '(I0)') array(i)
string = string//trim(buf)//','
end do
write(buf, '(I0)') array(size(array))
string = string//trim(buf)
write(*, '(A)') string
end program test_allocatable
yields:
gfortran -Wuninitialized allocatable_string.f90
allocatable_string.f90:20:28:
20 | string = string//trim(buf)
| ^
Warning: ‘.__var_2_realloc_string’ may be used uninitialized
[-Wmaybe-uninitialized]
If the line "string = string//trim(buf)" after the loop is commented, then the
warning disppears.
The test was run on Fedora, where "gfortran --version" yields:
GNU Fortran (GCC) 11.2.1 20211203 (Red Hat 11.2.1-7)
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
More information about the Gcc-bugs
mailing list