Skip to content

Commit b251ced

Browse files
committed
optinal value should check before use
Optional argument value has been passed for the first argument of merge routine. some compiler can't allow such situation.
1 parent 4daf7da commit b251ced

File tree

1 file changed

+47
-20
lines changed

1 file changed

+47
-20
lines changed

src/stdlib_string_type.fypp

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ contains
421421
type(string_type), intent(in) :: string
422422
integer :: ich
423423

424-
ich = merge(ichar(string%raw), 0, allocated(string%raw))
424+
ich = merge(ichar(string%raw(1:1)), 0, allocated(string%raw))
425425

426426
end function ichar_string
427427

@@ -431,7 +431,7 @@ contains
431431
type(string_type), intent(in) :: string
432432
integer :: ich
433433

434-
ich = merge(iachar(string%raw), 0, allocated(string%raw))
434+
ich = merge(iachar(string%raw(1:1)), 0, allocated(string%raw))
435435

436436
end function iachar_string
437437

@@ -571,8 +571,11 @@ contains
571571
logical, intent(in), optional :: back
572572
integer :: pos
573573

574-
pos = index(maybe(string), maybe(substring), &
575-
merge(back, .false., present(back)))
574+
if(present(back))then
575+
pos = index(maybe(string), maybe(substring),back)
576+
else
577+
pos = index(maybe(string), maybe(substring),.false.)
578+
endif
576579

577580
end function index_string_string
578581

@@ -584,8 +587,11 @@ contains
584587
logical, intent(in), optional :: back
585588
integer :: pos
586589

587-
pos = index(maybe(string), substring, &
588-
merge(back, .false., present(back)))
590+
if(present(back))then
591+
pos = index(maybe(string), substring,back)
592+
else
593+
pos = index(maybe(string), substring,.false.)
594+
endif
589595

590596
end function index_string_char
591597

@@ -597,8 +603,11 @@ contains
597603
logical, intent(in), optional :: back
598604
integer :: pos
599605

600-
pos = index(string, maybe(substring), &
601-
merge(back, .false., present(back)))
606+
if(present(back))then
607+
pos = index(string, maybe(substring),back)
608+
else
609+
pos = index(string, maybe(substring),.false.)
610+
endif
602611

603612
end function index_char_string
604613

@@ -612,8 +621,11 @@ contains
612621
logical, intent(in), optional :: back
613622
integer :: pos
614623

615-
pos = scan(maybe(string), maybe(set), &
616-
merge(back, .false., present(back)))
624+
if(present(back))then
625+
pos = scan(maybe(string), maybe(set),back)
626+
else
627+
pos = scan(maybe(string), maybe(set),.false.)
628+
endif
617629

618630
end function scan_string_string
619631

@@ -625,8 +637,11 @@ contains
625637
logical, intent(in), optional :: back
626638
integer :: pos
627639

628-
pos = scan(maybe(string), set, &
629-
merge(back, .false., present(back)))
640+
if(present(back))then
641+
pos = scan(maybe(string), set,back)
642+
else
643+
pos = scan(maybe(string), set,.false.)
644+
endif
630645

631646
end function scan_string_char
632647

@@ -638,8 +653,11 @@ contains
638653
logical, intent(in), optional :: back
639654
integer :: pos
640655

641-
pos = scan(string, maybe(set), &
642-
merge(back, .false., present(back)))
656+
if(present(back))then
657+
pos = scan(string, maybe(set),back)
658+
else
659+
pos = scan(string, maybe(set),.false.)
660+
endif
643661

644662
end function scan_char_string
645663

@@ -653,8 +671,11 @@ contains
653671
logical, intent(in), optional :: back
654672
integer :: pos
655673

656-
pos = verify(maybe(string), maybe(set), &
657-
merge(back, .false., present(back)))
674+
if(present(back))then
675+
pos = verify(maybe(string), maybe(set),back)
676+
else
677+
pos = verify(maybe(string), maybe(set),.false.)
678+
endif
658679

659680
end function verify_string_string
660681

@@ -667,8 +688,11 @@ contains
667688
logical, intent(in), optional :: back
668689
integer :: pos
669690

670-
pos = verify(maybe(string), set, &
671-
merge(back, .false., present(back)))
691+
if(present(back))then
692+
pos = verify(maybe(string), set,back)
693+
else
694+
pos = verify(maybe(string), set,.false.)
695+
endif
672696

673697
end function verify_string_char
674698

@@ -681,8 +705,11 @@ contains
681705
logical, intent(in), optional :: back
682706
integer :: pos
683707

684-
pos = verify(string, maybe(set), &
685-
merge(back, .false., present(back)))
708+
if(present(back))then
709+
pos = verify(string, maybe(set),back)
710+
else
711+
pos = verify(string, maybe(set),.false.)
712+
endif
686713

687714
end function verify_char_string
688715

0 commit comments

Comments
 (0)