Skip to content

Commit 4aa4f75

Browse files
committed
fix aliased string move
1 parent 8476d65 commit 4aa4f75

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/stdlib_string_type.fypp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module stdlib_string_type
1717
& to_title_ => to_title, to_sentence_ => to_sentence, reverse_ => reverse
1818
use stdlib_kinds, only : int8, int16, int32, int64, lk, c_bool
1919
use stdlib_optval, only: optval
20+
use iso_c_binding, only: c_loc,c_associated
2021
implicit none
2122
private
2223

@@ -679,10 +680,12 @@ contains
679680
!> Moves the allocated character scalar from 'from' to 'to'
680681
!> No output
681682
elemental subroutine move_string_string(from, to)
682-
type(string_type), intent(inout) :: from
683-
type(string_type), intent(inout) :: to
684-
character(:), allocatable :: tmp
683+
type(string_type), intent(inout), target :: from
684+
type(string_type), intent(inout), target :: to
685+
character(:), allocatable :: tmp
685686

687+
if (c_associated(c_loc(from),c_loc(to))) return
688+
686689
call move_alloc(from%raw, tmp)
687690
call move_alloc(tmp, to%raw)
688691

0 commit comments

Comments
 (0)