blob: 15a0fb0b32b4e24ddcdf707744cb80b37e31d9b9 [file] [edit]
! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic -Werror
! RUN: %python %S/test_errors.py %s %flang_fc1 -Wdefault-init-null-pointer -Werror
! RUN: %flang_fc1 -fsyntax-only -Werror %s
! A component may be omitted from a structure constructor when its type has
! default initialization. Default initialization leaves a pointer subcomponent
! that has no initialization of its own undefined, and flang makes it NULL()
! instead. That is reported only on request (or with -pedantic).
module m
integer, parameter :: nzero = 0
type t
integer :: y = 3
integer, pointer :: q
end type
type u
type(t) :: c
end type
type v
type(u) :: d
end type
type hasprocptr
integer :: y = 3
procedure(), pointer, nopass :: pp
end type
type w
type(hasprocptr) :: e
end type
type hasinitptr
integer :: y = 3
integer, pointer :: p => null()
integer, allocatable :: a
end type
type x
type(hasinitptr) :: f
end type
type y2
type(t) :: g
type(t) :: h(2)
end type
type hasarray
type(u) :: list(3)
end type
type deeparray
type(y2) :: s
end type
type nestedarray
type(y2) :: arr(2)
end type
type level1
type(t) :: k1(2)
end type
type level2
type(level1) :: k2(2)
end type
type threearrays
type(level2) :: k3(2)
end type
type midscalar
type(y2) :: x
end type
type scalarbetween
type(midscalar) :: arr(2)
end type
type hasallocptr
integer :: y = 1
type(t), allocatable :: al
type(t), pointer :: pt => null()
end type
type wrapallocptr
type(hasallocptr) :: wa
end type
type deepinit
type(x) :: f2
end type
type zerosizes
type(t) :: e0(0)
type(t) :: en(1:nzero)
type(t) :: e20(2,0)
end type
type haszerosize
type(t) :: empty(5:4)
type(u) :: full
end type
type hasnullproc
integer :: y = 3
procedure(), pointer, nopass :: np => null()
end type
type z
type(hasnullproc) :: k
end type
type, extends(t) :: ext
end type
type hasext
type(ext) :: m
end type
contains
subroutine s
type(u) :: ou
type(v) :: ov
type(w) :: ow
type(x) :: ox
type(y2) :: oy
type(hasarray) :: oa
type(deeparray) :: od
type(nestedarray) :: ona
type(threearrays) :: ota
type(scalarbetween) :: osb
type(wrapallocptr) :: owa
type(deepinit) :: odi
type(zerosizes) :: ozs
type(haszerosize) :: oz
type(hasnullproc) :: on
type(z) :: ozz
type(hasext) :: oe
integer, target :: n
!WARNING: Default initialization of omitted component 'c' leaves pointer 'c%q' undefined, NULL() assumed [-Wdefault-init-null-pointer]
ou = u()
!WARNING: Default initialization of omitted component 'd' leaves pointer 'd%c%q' undefined, NULL() assumed [-Wdefault-init-null-pointer]
ov = v()
!WARNING: Default initialization of omitted component 'e' leaves pointer 'e%pp' undefined, NULL() assumed [-Wdefault-init-null-pointer]
ow = w()
ox = x() ! ok; p is initialized and a is unallocated
!WARNING: Default initialization of omitted component 'g' leaves pointer 'g%q' undefined, NULL() assumed [-Wdefault-init-null-pointer]
!WARNING: Default initialization of omitted component 'h' leaves pointer 'q' in each element of 'h' undefined, NULL() assumed [-Wdefault-init-null-pointer]
oy = y2()
!WARNING: Default initialization of omitted component 'list' leaves pointer 'c%q' in each element of 'list' undefined, NULL() assumed [-Wdefault-init-null-pointer]
oa = hasarray()
!WARNING: Default initialization of omitted component 's' leaves pointer 's%g%q' undefined, NULL() assumed [-Wdefault-init-null-pointer]
!WARNING: Default initialization of omitted component 's' leaves pointer 'q' in each element of 's%h' undefined, NULL() assumed [-Wdefault-init-null-pointer]
od = deeparray()
!WARNING: Default initialization of omitted component 'arr' leaves pointer 'g%q' in each element of 'arr' undefined, NULL() assumed [-Wdefault-init-null-pointer]
!WARNING: Default initialization of omitted component 'arr' leaves pointer 'q' in each element of 'h' in each element of 'arr' undefined, NULL() assumed [-Wdefault-init-null-pointer]
ona = nestedarray()
!WARNING: Default initialization of omitted component 'k3' leaves pointer 'q' in each element of 'k1' in each element of 'k2' in each element of 'k3' undefined, NULL() assumed [-Wdefault-init-null-pointer]
ota = threearrays()
!WARNING: Default initialization of omitted component 'arr' leaves pointer 'x%g%q' in each element of 'arr' undefined, NULL() assumed [-Wdefault-init-null-pointer]
!WARNING: Default initialization of omitted component 'arr' leaves pointer 'q' in each element of 'x%h' in each element of 'arr' undefined, NULL() assumed [-Wdefault-init-null-pointer]
osb = scalarbetween()
owa = wrapallocptr() ! ok; al is unallocated, and pt is initialized
odi = deepinit() ! ok; f2%f%p is initialized and f2%f%a is unallocated
ozs = zerosizes() ! ok; all three arrays have zero size
! A zero-size array has no pointers to leave undefined.
!WARNING: Default initialization of omitted component 'full' leaves pointer 'full%c%q' undefined, NULL() assumed [-Wdefault-init-null-pointer]
oz = haszerosize()
on = hasnullproc() ! ok; np is initialized
ozz = z() ! ok; k%np is initialized
!WARNING: Default initialization of omitted component 'm' leaves pointer 'm%q' undefined, NULL() assumed [-Wdefault-init-null-pointer]
oe = hasext()
ou = u(c=t(q=n)) ! ok; nothing is omitted
end
end