This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [PATCH] Fix FMT= with CHARACTER arrays (PR fortran/39865, take 2
- From: dominiq at lps dot ens dot fr (Dominique Dhumieres)
- To: fortran at gcc dot gnu dot org
- Cc: jakub at redhat dot com
- Date: Wed, 13 May 2009 00:23:48 +0200
- Subject: Re: [PATCH] Fix FMT= with CHARACTER arrays (PR fortran/39865, take 2
With your patch (take 2) the following code:
subroutine foo (a)
integer :: a(:, :)
write (*, fmt=a) 1, 2, 3, 4, 5, 6, 7, 8
end subroutine foo
interface
subroutine foo (a)
integer :: a(:, :)
end subroutine foo
end interface
integer :: a(5, 5), b(1,2)
complex :: za(5,10), zb(5,10)
a = 4HXXXX
a(2,2) = 4H (8I
a(2,3) = 2H4)
b(1,1) = 4H (8I
b(1,2) = 2H4)
call foo (b)
call foo (a(2:2,2:3))
za = 8HXXXXXXXX
zb = 8HXXXXXXXX
za(2,3) = 8H(I1)xxxx
zb(3,2) = 8H(I10)xxx
call bar (za, zb)
write (*, fmt=b(1,1)) 1, 2, 3, 4, 5, 6, 7, 8
contains
subroutine bar (a,b)
complex :: a(1:5,1:10)
complex :: b(:,:)
write (*, fmt=a(2,3)) 1
write (*, fmt=b(3,2)) 1
end subroutine
end
gives
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1
1
At line 24 of file pr39865_7_db.f90 (unit = 6, file = 'stdout')
Fortran runtime error: Nonnegative width required in format
(8I
^
I think the relevant part of the standard (f95/f03) is:
9.4.1.1 Format specifier
R913 format is default-char-expr
or label
or *
Constraint: The label shall be the label of a FORMAT statement that appears in the same scoping unit
as the statement containing the format specifier.
The default-char-expr shall evaluate to a valid format specification (10.1.1 and 10.1.2).
If default-char-expr is an array, it is treated as if all of the elements of the array were specified in array
element order and were concatenated.
and
10.1.2 Character format specification
If the format specifier references a character array, it is treated as if all of the elements of the array were
specified in array element order and were concatenated. However, if a format specifier references a
character array element, the format specification shall be entirely within that array element.
Note that the above code gives errors with -std=f95 or -std=f2003, not only
for the Hollerith extension, but also for
Error: Extension: Non-character in FORMAT tag at (1)
Dominique