This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/27998] New: character arrays: warn if erray constructor values have different lengths
- From: "tobias dot burnus at physik dot fu-berlin dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 12 Jun 2006 13:03:04 -0000
- Subject: [Bug fortran/27998] New: character arrays: warn if erray constructor values have different lengths
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The following constructor seems to be invalid according to the Fortran 2003
standard:
(/ 'Takata', 'Tanaka', 'Hayashi' /)
as first two strings are 6 whereas the last one is 7 character long.
NAG f95 fails with the following error:
Error: string.f90, line 3: Array constructor values have differing CHARACTER
lengths (6 and 7)
[f95 error termination]
Thus a warning would be nice, at least with -Wall, maybe even a default
warning.
In the Fortran 2003 standard, I cannot find the line which forbids the usage of
different length strings. However, in "NOTE 4.70" of implicitly states that it
is not allowed:
"An example of an array constructor that specifies a nonkind type parameter:
(/ CHARACTER(LEN=7) :: ?Takata?, ?Tanaka?, ?Hayashi? /)
In this constructor, without the type specification, it would have been
necessary to specify all of the constants with the same character length."
(This currently does not work in gfortran, see bug 27997.)
Example:
----------------------------
program test
character(15) :: a(3)
! invalid as the constants have different character lengths
a = (/ 'Takata', 'Tanaka', 'Hayashi' /)
! This is valid Fortran 95/2003
!a = (/ 'Takata ', 'Tanaka ', 'Hayashi' /)
! And this is valid Fortran 2003
!a = (/ character(len=7) :: 'Takata ', 'Tanaka ', 'Hayashi' /)
print '(a)',a
end program test
--
Summary: character arrays: warn if erray constructor values have
different lengths
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: tobias dot burnus at physik dot fu-berlin dot de
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27998