[Bug fortran/78662] New: Incorrect parsing of quotes in the char-literal-constant of the DT data descriptor
ian_harvey at bigpond dot com
gcc-bugzilla@gcc.gnu.org
Sat Dec 3 10:36:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78662
Bug ID: 78662
Summary: Incorrect parsing of quotes in the
char-literal-constant of the DT data descriptor
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: ian_harvey at bigpond dot com
Target Milestone: ---
The following, when compiled with gfortran recent trunk, generates an error
that indicates that parsing of the optional character literal constant of a DT
edit descriptor is not correctly handling embedded quotes.
MODULE m
IMPLICIT NONE
TYPE :: t
CHARACTER :: c
CONTAINS
PROCEDURE :: write_formatted
GENERIC :: WRITE(FORMATTED) => write_formatted
END TYPE t
CONTAINS
SUBROUTINE write_formatted(dtv, unit, iotype, v_list, iostat, iomsg)
CLASS(t), INTENT(IN) :: dtv
INTEGER, INTENT(IN) :: unit
CHARACTER(*), INTENT(IN) :: iotype
INTEGER, INTENT(IN) :: v_list(:)
INTEGER, INTENT(OUT) :: iostat
CHARACTER(*), INTENT(INOUT) :: iomsg
WRITE (unit, "(A)", IOSTAT=iostat, IOMSG=iomsg) iotype
END SUBROUTINE write_formatted
END MODULE m
PROGRAM p
USE m
IMPLICIT NONE
TYPE(t) :: x
WRITE (*, "(DT'a''b')") x
END PROGRAM p
$ gfortran 2016-12-03\ dt.f90 && ./a.out
2016-12-03 dt.f90:28:21:
WRITE (*, "(DT'a''b')") x
1
Error: Unexpected element ‘'’ in format string at (1)
The delimiter of the inner character literal constant (embedded in the
character literal constant that makes up the entire format specification) is a
single quote - the two single quotes in sequence therefore represent a single
single quote in the value that the inner character literal represents.
A more complicated variant is:
WRITE (*, '(DT''a''''b'')') x
The problem also arises with FORMAT statements, which don't have the complexity
associated with having to consider "nested" literals.
WRITE (*, 100) x
100 FORMAT(DT'a''b')
More information about the Gcc-bugs
mailing list