Skip to content

bits() in bitset_type returned a non-zero value even though no value is set. #746

Closed
@degawa

Description

@degawa

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

b8fbb3c

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions