[Bug fortran/70233] Missing diagnostic in array constructor, different size strings
anlauf at gmx dot de
gcc-bugzilla@gcc.gnu.org
Fri Mar 18 19:21:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70233
--- Comment #7 from Harald Anlauf <anlauf at gmx dot de> ---
(In reply to Jerry DeLisle from comment #6)
> The failures I looked at were becasue the constructors were using strings of
> different sizes. So my question was going to be what are the rules. Are the
> strings suppose to get padded to the length of the character array element?
Other compiler give error messages (if standard conformance is required)
ifort:
pr70233.f90(9): warning #8208: If type specification is omitted, each ac-value
expression in the array constructor of type CHARACTER must have the same
length type parameters. ['def']
ch_array = [bh, "def", ch, ch, bh]! no error given
--------------------^
pr70233.f90(10): warning #8208: If type specification is omitted, each ac-value
expression in the array constructor of type CHARACTER must have the same
length type parameters. ['def']
ch_array = ["def", bh, ch, ch, ch] ! error given
----------------^
sunf95:
ch_array = [bh, "def", ch, ch, bh]! no error given
^
"pr70233.f90", Line = 9, Column = 21: ERROR: Array constructor values of type
character must all have the same length.
ch_array = ["def", bh, ch, ch, ch] ! error given
^
"pr70233.f90", Line = 10, Column = 24: ERROR: Array constructor values of type
character must all have the same length.
^
"pr70233.f90", Line = 10, Column = 28: ERROR: Array constructor values of type
character must all have the same length.
^
"pr70233.f90", Line = 10, Column = 32: ERROR: Array constructor values of type
character must all have the same length.
^
"pr70233.f90", Line = 10, Column = 36: ERROR: Array constructor values of type
character must all have the same length.
f90comp: 16 SOURCE LINES
f90comp: 5 ERRORS, 0 WARNINGS, 0 OTHER MESSAGES, 0 ANSI
So I'd say it's ok to give an error message here, unless you want
to make silent padding a gnu extension. ;-)
> All elements must be of the same size so I assume if the length is say six,
> you can not use "abc" in a constructor and one must use "abc "
>
> I did not check all the failures, but at least one requires the -fbackslash
> and with the patch passes fine if I pad out the strings in the constructor.
The patch produces misleading error messages for valid code, as in:
character(4), parameter :: chr (4) = (/"abcd", "efgh", "ijkl", "mnop"/)
character(4), parameter :: chr1(2) = (/chr(2)(2:3) , chr(3)(3:4)/) ! OK
character(4), parameter :: chr2(2) = (/chr(2:3)(2:3)/) ! Error?
character(4), parameter :: chr3(2) = (/chr(2:2)(2:3), chr(3)(3:4)/) ! Error?
end
pr70233b.f90:1:48:
character(4), parameter :: chr (4) = (/"abcd", "efgh", "ijkl", "mnop"/)
1
Error: Different CHARACTER lengths (2/4) in array constructor at (1)
Could this be an issue with substrings of array sections?
More information about the Gcc-bugs
mailing list