Skip to content

Commit c086185

Browse files
authored
Merge pull request #753 from jvdp1/fix_bits_bitset
Fix `bits()` in `bitset_type` before initialization
2 parents 42a547b + 091201d commit c086185

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

src/stdlib_bitsets.fypp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ module stdlib_bitsets
100100
!! Parent type for bitset_64 and bitset_large ([Specification](../page/specs/stdlib_bitsets.html#the-stdlib_bitsets-derived-types))
101101

102102
private
103-
integer(bits_kind) :: num_bits
103+
integer(bits_kind) :: num_bits = 0_bits_kind
104104

105105
contains
106106

src/stdlib_bitsets_large.fypp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ contains
10511051
pure module subroutine set_range_large(self, start_pos, stop_pos)
10521052
!
10531053
! Sets all valid bits to 1 from the START_POS to the STOP_POS positions
1054-
! in SELF. If STOP_POA < START_POS no bits are changed. Positions outside
1054+
! in SELF. If STOP_POS < START_POS no bits are changed. Positions outside
10551055
! the range 0 to BITS(SELF)-1 are ignored.
10561056
!
10571057
class(bitset_large), intent(inout) :: self

test/bitsets/test_stdlib_bitset_64.f90

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,15 @@ subroutine test_initialization(error)
231231

232232
type(bitset_64) :: set4, set5
233233

234+
!The following block triggers an issue in gfortran 11 and 12
235+
block
236+
type(bitset_64) :: set6
237+
call check(error, set6 % bits(), 0, &
238+
'set6 % bits() returned non-zero value '//&
239+
'even though set6 was not initialized.')
240+
if (allocated(error)) return
241+
end block
242+
234243
set5 = log1
235244
call check(error, set5%bits(), 64, &
236245
'initialization with logical(int8) failed to set the right size.')

test/bitsets/test_stdlib_bitset_large.f90

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,15 @@ subroutine test_initialization(error)
345345
logical(int64), allocatable :: log8(:)
346346
type(bitset_large) :: set4, set5
347347

348+
!The following triggers an issue in gfortran 11 and 12
349+
block
350+
type(bitset_large) :: set6
351+
call check(error, set6 % bits(), 0, &
352+
'set6 % bits() returned non-zero value '//&
353+
'even though set6 was not initialized.')
354+
if (allocated(error)) return
355+
end block
356+
348357
set5 = log1
349358
call check(error, set5 % bits(), 64, &
350359
' initialization with logical(int8) failed to set' // &

0 commit comments

Comments
 (0)