Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
degawa opened this issue Nov 13, 2023 · 1 comment · Fixed by #753
Closed

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

degawa opened this issue Nov 13, 2023 · 1 comment · Fixed by #753
Labels
bug Something isn't working

Comments

@degawa
Copy link
Contributor

degawa commented Nov 13, 2023

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.

@degawa degawa added the bug Something isn't working label Nov 13, 2023
@jvdp1
Copy link
Member

jvdp1 commented Nov 19, 2023

Thank you for reporting this issue. It seems that your proposition would solve the it. Could you open a PR with your solution please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants