Reputation: 300
I have the following code that uses a character variable with allocatable length.
PROGRAM testprog
IMPLICIT NONE
CHARACTER(LEN=5) :: param
CHARACTER(LEN=:), ALLOCATABLE :: val
param = '12455'
val = param
WRITE(*,*) val
END PROGRAM testprog
I compile it using gfortran versions 7.5 or 8.4 with all warnings activated (option -Wall) and I get the following warning:
test.f90:6:0:
val = param
Warning: ‘.val’ may be used uninitialized in this function [-Wmaybe-uninitialized]
The program works. However, I do not understand why this warning message appears.
Upvotes: 1
Views: 217
Reputation: 60008
This is a compiler bug. It is well-known, but not fixed in GCC yet. You can see the report at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91442
You can either ignore it, or disable the "may be used uninitialized" warnings with -Wno-maybe-uninitialized
or compile with optimizations (-O1 and more).
Upvotes: 3