Code:
! test_char.f90
program test_char
implicit none
character(len=:), allocatable :: str
str = 'hello world'
end program test_char
Test:
$ gfortran --version && gfortran -g -Wall -std=f2018 test_char.f90
GNU Fortran (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
test_char.f90:9:19:
9 | str = 'hello world'
| ^
Warning: ‘.str’ may be used uninitialized [-Wmaybe-uninitialized]
Questions:
- Is the code standard-conforming?
- Why
str
is considered maybe uninitialized? - What is the dot preceding
str
?
Remarks
- I am aware that
-Wall
implies-Wmaybe-uninitialized
. What interests me is not why this option is turned on or whether it should be, but rather why the code triggers this warning. - The following compilation finishes without warning.
ifort -g -warn all -check all -debug extended test_char.f90
ifx -g -warn all -check all -debug extended test_char.f90
nagfor -g -C test_char.f90
flang -g -Wall -Wextra test_char.f90
nvfortran -g -Wall -Wextra test_char.f90
aocc-flang -g -Wall -Wextra test_char.f90
sunf95 -g -w3 -ansi -xcheck=%all -C test_char.f90
Thanks.