From ae4a38f89b984de07ade91794e0769aefa7e5c21 Mon Sep 17 00:00:00 2001 From: Jeremie Vandenplas Date: Sun, 3 Sep 2023 11:38:24 +0200 Subject: [PATCH] Fix bug related to string_type move #731 #735 --- src/stdlib_string_type.fypp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/stdlib_string_type.fypp b/src/stdlib_string_type.fypp index 0bb5ff8a2..b7a634246 100644 --- a/src/stdlib_string_type.fypp +++ b/src/stdlib_string_type.fypp @@ -680,9 +680,18 @@ contains !> No output elemental subroutine move_string_string(from, to) type(string_type), intent(inout) :: from - type(string_type), intent(out) :: to + type(string_type), intent(inout) :: to + + if(.not.allocated(from%raw))then + if(allocated(to%raw))deallocate(to%raw) + return + endif - call move_alloc(from%raw, to%raw) + if(from%raw .eq. to%raw)then + deallocate(from%raw) + else + call move_alloc(from%raw, to%raw) + endif end subroutine move_string_string