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

            Bug ID: 118571
           Summary: UTF-8 output and the A edit descriptor
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kargls at comcast dot net
  Target Milestone: ---

It seems that the A edit descriptor is not counting UTF-8
characters when a field is given.  Consider the following
program

   program test

   use iso_fortran_env

   implicit none

   integer, parameter :: ucs4 = selected_char_kind('ISO_10646')

   character(kind=ucs4, len=1), parameter :: alpha = char(int(z'03B1'), ucs4)
   character(kind=ucs4, len=1), parameter :: beta  = char(int(z'03B2'), ucs4)
   character(kind=ucs4, len=1), parameter :: space = ucs4_' '

   integer fd
   character(kind=ucs4,len=:), allocatable :: str

   fd = output_unit

   open (fd, encoding='UTF-8')
   str = repeat(space,6)//alpha//beta//alpha//beta

   write(fd,'(2(I4,1X),">",A,"<")') len_trim(str), storage_size(str), str

   str = alpha // beta // alpha // beta

   write(fd,'(2(I4,1X),">",A,"<")')  len_trim(str(1:1)),
storage_size(str(1:1)), str(1:1)
   write(fd,*) len_trim(str(1:1)), storage_size(str(1:1)), str(1:1)

   write(fd,'(2(I4,1X),">",A1,"<")')  len_trim(str(1:1)),
storage_size(str(1:1)), str(1:1)
   write(fd,'(2(I4,1X),">",A1,"<")')  len_trim(str), storage_size(str), str

  end program

and the following output (hopefully alpha and beta show correctly
as I did a copy-n-paste).

% gfcx -o z jj.f90 && ./z
  10  320 >      αβαβ<
   1   32 >α<
           1          32 α
   1   32 >α<
   4  128 >αβαβ<

The last line of output appears to be wrong for A1 formatting.

F2023, 13.7.4

    If the specified field width w for an A edit descriptor corresponding to
    an effective item on output is greater than len, the output field will
    consist of w-len blanks followed by the len characters from the internal
    value. If the specified field width w is less than or equal to len, the
    output field will consist of the leftmost w characters from the internal
    value.

Reply via email to