http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60500
Bug ID: 60500 Summary: Spurious warning on derived type initialization Product: gcc Version: 4.8.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: jonathan.hogg at stfc dot ac.uk The following code: module spurious_warning implicit none type :: ntype integer :: level = 1 end type ntype contains subroutine sub1(n1, n2, st) integer, intent(in) :: n1, n2 integer, intent(out) :: st type(ntype), dimension(:), allocatable :: work1 integer, dimension(:), allocatable :: work2 allocate(work1(n1), stat=st) if(st.ne.0) return allocate(work2(n2), stat=st) if(st.ne.0) return end subroutine sub1 end module spurious_warning Produces the following spurious warning: [user@host]$ gfortran-4.8 -O2 -Wall -c bug.f90 bug.f90: In function ‘sub1’: bug.f90:12:0: warning: ‘work1.dim[0].ubound’ may be used uninitialized in this function [-Wmaybe-uninitialized] type(ntype), dimension(:), allocatable :: work1 ^ With the following compiler version: GNU Fortran (Ubuntu 4.8.1-2ubuntu1~12.04) 4.8.1 Notes: Removal of -O2 removes the sprurious warning. Removal of the second allocation removes spurious warning. Removal of default value in type definition removes spurious warning. Working theory: The automatic initialization accesses array size as part of implementation?