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

            Bug ID: 117819
           Summary: Formatted READ with BZ in format fails
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libfortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jvdelisle at gcc dot gnu.org
  Target Milestone: ---

The following test case courtesy Malcolm Cohen:

Program xe1
  Implicit None
  Character(6) string
  Integer x
  Logical :: ok = .True.
  string = '111111'
  print *, "String we read from is: ", string
  Read(string,2) x
2 Format(BZ,B8)
  If (x/=Int(b'11111100')) Then
    Print *,'FAIL B8 BZ wrong result'
    Print *,'Expected',Int(b'11111100')
    Print *,'Received',x
    ok = .False.
  End If
  string = '123456'
  Read(string,1) x
1 Format(BZ,I8)
  If (x/=12345600) Then
    Print *,'FAIL I8 BZ wrong result'
    Print *,'Expected',12345600
    Print *,'Received',x
    ok = .False.
  End If
  Read(string,3) x
3 Format(BZ,O8)
  If (x/=Int(o'12345600')) Then
    Print *,'FAIL O8 BZ wrong result'
    Print *,'Expected',Int(o'12345600')
    Print *,'Received',x
    ok = .False.
  End If
  Read(string,4) x
4 Format(BZ,Z8)
  If (x/=Int(z'12345600')) Then
    Print *,'FAIL OZ BZ wrong result'
    Print *,'Expected',Int(z'12345600')
    Print *,'Received',x
    ok = .False.
  End If
  If (ok) Print *,'ok IBOZ with BZ and PAD'
End Program

$ gfc malcolm1.f90 
$ ./a.out 
 String we read from is: 111111
 FAIL B8 BZ wrong result
 Expected         252
 Received          63
 FAIL I8 BZ wrong result
 Expected    12345600
 Received      123456
 FAIL O8 BZ wrong result
 Expected     2739072
 Received       42798
 FAIL OZ BZ wrong result
 Expected   305419776
 Received     1193046

Reply via email to