https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78187
Bug ID: 78187 Summary: -fno-automatic does not work with allocatable scalar character result result Product: gcc Version: 6.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: nuclearlee at gmail dot com Target Milestone: --- Created attachment 39945 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=39945&action=edit test.f90 contains a module and a test program to demonstrate described bug. Summary: The attached code should returns an allocatable scalar character as a "result". If I compile without -fno-automtic I get the correct result, if I compile with -fno-automatic, I get an empty string that is allocated (for gfortran 6.2.0, 5.4.1, and 4.9.4. 4.8.5 gives close to the correct result with some garbage appended to it). If I instead use the function name to return the result (instead of using the keyword "result"), the function works with -fno-automatic). More details below. Thanks, Lee Detail: If I compile in Ubuntu using gcc-6.2 (gcc version 6.2.0 20160901 (Ubuntu 6.2.0-3ubuntu11~14.04) using the following command $ gfortran-6 -o test.exe test.f90 I get the correct result: $ ./test.exe c|abcdef| T If I compile using -fno-automatic, however, I get the folowing $ gfortran-6 -fno-automatic -o test.exe test.f90 I get the correct result: $ ./test.exe c|| T Also, If I change the function scalar in test_module so that I'm not using "result", and instead declaring scalar and setting it, it returns the *correct* result using -fno-automatic, i.e., function scalar(a, b) result(c) character(len=*), intent(in) :: a, b character(len=:), allocatable :: scalar scalar = trim(a)//trim(b) end function scalar I used a few different versions and -fno-automatic has the same result in all of them (4.9.4, 5.4.1 and 4.8.5). gfortran 4.8.5 returns the closest to a correct result (though still incorrect): $ gfortran-4.8 -fno-automatic -o test.exe test.f90 $ ./test.exe c|abcdef�q�abcdef��| T