Closed
Description
Description
The following code, built with gfortran, caught an error because a type-bound procedure bits()
returns a non-zero value.
use testdrive, only : error_type, check
use stdlib_bitsets, only: bitset_large
type(error_type), allocatable :: error
block
type(bitset_large) :: set6
call check(error,set6%bits(),0, &
'set6 % bits() returned non-zero value '//&
'even though set6 was not initialized.')
if (allocated(error)) return
end block
Expected Behaviour
I expected bits()
to return 0 since no value is set for set6
.
Version of stdlib
Platform and Architecture
Windows 10 22H2 64bit, gfortran 11.2 bundled with quickstart Fortran on Windows
Additional Information
This error occurs when child types of bitset_type
, bitset_large
and bitset_64
, are declared in a block
construct, and the error is caused by the fact that the component num_bits
of bitset_type
is not initialized to 0
as the default value.
type, abstract :: bitset_type
!! version: experimental
!!
!! Parent type for bitset_64 and bitset_large ([Specification](../page/specs/stdlib_bitsets.html#the-stdlib_bitsets-derived-types))
private
integer(bits_kind) :: num_bits
contains
The error can be fixed by setting the default value of num_bits
to 0
.