1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
program class_29
type :: toml_val
integer :: x
character(len=:), allocatable :: y
end type
type :: toml_table
integer :: x
character(len=:), allocatable :: y
class(toml_val), allocatable :: val
end type
class(toml_table), pointer :: temp
class(toml_table), pointer :: temp2
class(toml_table), allocatable :: temp3
type(toml_table), allocatable :: temp4
type(toml_table), target :: temp_table
temp_table%x = 42
temp => temp_table
nullify(temp2)
if (associated(temp2) .or. .not. associated(temp)) error stop
if (allocated(temp3)) error stop
allocate(temp3)
allocate(temp4)
if (.not. allocated(temp3)) error stop
temp3%y = "Hello, World!"
if (allocated(temp3%val)) error stop
call destroy(temp3)
if (allocated(temp3%y)) error stop
temp3%y = "Hello, World!"
temp4%y = "Hello, World!"
if (allocated(temp3%y)) then
deallocate(temp3%y)
end if
if (allocated(temp3%y)) error stop
if (allocated(temp4%y)) then
deallocate(temp4%y)
end if
if (allocated(temp4%y)) error stop
allocate(temp4%val)
temp4%val%y = "Hello"
if (allocated(temp4%val%y)) then
deallocate(temp4%val%y)
end if
if (allocated(temp4%val%y)) error stop
contains
subroutine destroy(shlex)
class(toml_table), intent(inout) :: shlex
deallocate(shlex%y)
end subroutine destroy
end program
|