[Bug fortran/106108] New: gfortran gives warning about unitilialized variable for string with both allocatable length and size
kaiserkarl31 at yahoo dot com
gcc-bugzilla@gcc.gnu.org
Mon Jun 27 17:36:10 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106108
Bug ID: 106108
Summary: gfortran gives warning about unitilialized variable
for string with both allocatable length and size
Product: gcc
Version: 11.3.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: kaiserkarl31 at yahoo dot com
Target Milestone: ---
gfortran using "-Wuninitialized" spits out an erroneous warning message for the
declaration of a string that has both allocatable length and allocatable
dimension. Making it a fixed-length string works: gfortran handles the
fixed-length string with allocatable dimension.
The following program is a minimal working example:
program test
implicit none
character (len=:), dimension(:), allocatable :: args
allocate( character(len=6) :: args(2) )
args(1) = 'hello,'
args(2) = 'world!'
print '(2(A,1X))', args
end program test
The compiler seems to handle the above code just fine, but it should not warn
the user. Instead, if compiled with "-Wall" or "-Wuninitialized", it says this:
test.f90:3:55:
3 | character (len=:), dimension(:), allocatable :: args
| ^
Warning: ‘.args’ is used uninitialized [-Wuninitialized]
As I said before, making the length fixed seems to work:
program test
implicit none
character (len=6), dimension(:), allocatable :: args
allocate( args(2) )
args(1) = 'hello,'
args(2) = 'world!'
print '(2(A,1X))', args
end program test
This version produces no warnings.
More information about the Gcc-bugs
mailing list