https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123900
Bug ID: 123900
Summary: Compiler warnings about an uninitialised pointer
variable show only when there is an unused pointer
variable
Product: gcc
Version: 15.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: arjen.markus895 at gmail dot com
Target Milestone: ---
Created attachment 63541
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=63541&action=edit
Short program exhibiting the reported behaviour
I stumbled on a curious problem with uninitialised pointers. Note that I was
looking for situations that the compiler will diagnose at compile or run time,
so the program is not conforming by design.
If I compile it with -Wall, then the following warnings result:
chk_reduced.f90:8:51:
8 | real, dimension(:), pointer :: p, q
| 1
Warning: Unused variable 'q' declared at (1) [-Wunused-variable]
chk_reduced.f90:13:67:
13 | write(*,*) 'Association uninitialised pointer: ', associated(p)
| ^
Warning: 'p.data' is used uninitialized [-Wuninitialized]
chk_reduced.f90:8:48:
8 | real, dimension(:), pointer :: p, q
| ^
note: 'p' declared here
chk_reduced.f90:15:43:
15 | write(*,*) 'Uninitialised pointer: ', p
| ^
Warning: 'p.data' is used uninitialized [-Wuninitialized]
chk_reduced.f90:8:48:
8 | real, dimension(:), pointer :: p, q
| ^
note: 'p' declared here
chk_reduced.f90:15:43:
15 | write(*,*) 'Uninitialised pointer: ', p
| ^
Warning: 'p.offset' is used uninitialized [-Wuninitialized]
chk_reduced.f90:8:48:
8 | real, dimension(:), pointer :: p, q
| ^
note: 'p' declared here
chk_reduced.f90:15:43:
15 | write(*,*) 'Uninitialised pointer: ', p
| ^
Warning: 'p.dim[0].lbound' is used uninitialized [-Wuninitialized]
chk_reduced.f90:8:48:
8 | real, dimension(:), pointer :: p, q
| ^
note: 'p' declared here
chk_reduced.f90:15:43:
15 | write(*,*) 'Uninitialised pointer: ', p
| ^
Warning: 'p.dim[0].ubound' is used uninitialized [-Wuninitialized]
chk_reduced.f90:8:48:
8 | real, dimension(:), pointer :: p, q
| ^
note: 'p' declared here
chk_reduced.f90:15:43:
15 | write(*,*) 'Uninitialised pointer: ', p
| ^
Warning: 'p.dim[0].stride' is used uninitialized [-Wuninitialized]
chk_reduced.f90:8:48:
8 | real, dimension(:), pointer :: p, q
| ^
note: 'p' declared here
However, uncommenting the lines 20-24 makes all these warnings disappear. As
can be seen, the warnings are about the first part of the program, but the
association of p to q at line 20 and the subsequent use in the write statements
should be independent of these diagnostics.
I have reduced the program to possibly the minimum, dropping the two write
statements did not make the warnings disappear.