Skip to content

Commit

Permalink
Fixes #235 missing TARGET on map::erase()
Browse files Browse the repository at this point in the history
  • Loading branch information
tclune committed Aug 23, 2024
1 parent 45b4d4a commit b685047
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
6 changes: 6 additions & 0 deletions ChangeLog.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## Unreleased

### Fixed

- Added missing TARGET attribute in map::erase() procedures. When
used with NAG compiler, would result in temporary objects with
dangling pointers. Added new test to cover this case.

## [1.14.0] - 2024-07-09

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions include/v2/map/procedures.inc
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@
! =======================
function __MANGLE(erase_iter)(this, iter) result(new_iter)
type(__map_iterator) :: new_iter
class(__map), intent(inout) :: this
class(__map), target, intent(inout) :: this
type(__map_iterator), intent(in) :: iter

new_iter%reference => iter%reference
Expand All @@ -261,7 +261,7 @@
! =======================
function __MANGLE(erase_key)(this, k) result(n)
integer(kind=GFTL_SIZE_KIND) :: n
class(__map), intent(inout) :: this
class(__map), target, intent(inout) :: this
__Key_declare_dummy__, intent(in) :: k

type(__map_iterator) :: iter
Expand Down
19 changes: 19 additions & 0 deletions tests/map/Test_Map.m4
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,25 @@ contains

end subroutine test_erase

@test
subroutine test_erase_key()
type (Map), target :: m
integer :: n

call m%insert(key_one, one)
call m%insert(key_two, two)
call m%insert(key_three, three)

n = m%erase(key_two)
@assert_that(n, is(equal_to(1)))
@assert_that(int(m%size()), is(equal_to(2)))

n = m%erase(key_zero)
@assert_that(n, is(equal_to(0)))
@assert_that(int(m%size()), is(equal_to(2)))

end subroutine test_erase_key

@test
subroutine test_next()
type (Map), target :: m
Expand Down

0 comments on commit b685047

Please sign in to comment.