Bug on gfortran 15.1 on Mac

Hello,

I face a problem with gfortran 15.1 on my :

when I enter :

buffer(80:80) = C_NEW_LINE

the C_NEW_LINE is inserted at buffer(1:1). If I want it to work I need to enter:

buffer(1:80) = buffer(1:79) // C_NEW_LINE

I don’t know where to report this so I drop it here

I am guessing you did not initialize buffer(), and it is probably filled with nulls and so if you print it it looks like there are no spaces. Try adding

   buffer=' '
before you set character 80.

If that is not the problem, if you can provide a simple working example program that produces the problem that would be useful.

This works as expected with gfortran 15.1:

use iso_c_binding
implicit none

character(11) :: str

str = "0123456789x"
print "(*(A))", str, str
str(11:11) = c_new_line
print "(*(A))", str, str

end

Output:

0123456789x0123456789x
0123456789
0123456789

I have problems

As already mentioned, please post a Minimum Reproducible Example. Without that it will be difficult to help you.

1 Like

This example replace str(1:1) with c_new_line despite we entered str(11:11) = c_new_line

program main

use iso_c_binding
implicit none

character(len=:), pointer :: str =>null()

allocate( character(len=11) :: str )

print ‘(/“First Test”/)’
str = “0123456789x”
print “((A))", str, str
str(11:11) = c_new_line
print "(
(A))”, str, str

print ‘(/“Second Test”/)’
str = “0123456789x”
print “((A))", str, str
str(1:11) = str(1:10) // c_new_line
print "(
(A))”, str, str

deallocate(str)

end

First Test

0123456789x0123456789x

123456789x
123456789x

Second Test

0123456789x0123456789x
0123456789
0123456789

If I remove the => null() initialization, then the output is normal again.

Note that this initialization is not needed here. Nonetheless, yes it’s a bug.

Bugs of gfortran should be reported here: https://gcc.gnu.org/bugzilla

1 Like