https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117842

            Bug ID: 117842
           Summary: Function wrongly returning empty character string if
                    allocated on the heap
           Product: gcc
           Version: 14.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: alexandre.poux at coria dot fr
  Target Milestone: ---

The following code is working as expected, unless I'm using
-fmax-stack-var-size=0 with gfortran 12.3, 13.3 or 14.2.1. In which case, the
function returns an empty string.

program test_clean_str
    implicit none
    character(len=100) :: input_str
    character(len=:), allocatable :: result_str

    input_str = '  Test String  '

    result_str = clean_str(input_str)

    print *, 'Result:-', result_str,"-"

contains

    function clean_str(str_in) result(str_out)
        implicit none
        character(len=*), intent(in) :: str_in
        character(len=:), allocatable :: str_out

        str_out = trim(str_in)
        print*,"-",str_out,"-"

    end function clean_str

end program test_clean_str

This change of behavior does not occur if the function is rewritten as a
subroutine or if I'm working with integer arrays instead of character string.

I've tested gfortran 12.3 13.3 and 14.2.1 on an up to date Arch Linux.
  • [Bug fortran/117842] New: Func... alexandre.poux at coria dot fr via Gcc-bugs

Reply via email to