+ throw a warning in ISO mode if a constant string is assigned to a char and the sizes do not match, resolves #38439

git-svn-id: trunk@48563 -
This commit is contained in:
florian 2021-02-09 20:48:27 +00:00
parent 3a0eb110ec
commit ecce39a3b2
6 changed files with 585 additions and 556 deletions

1
.gitattributes vendored
View File

@ -16713,6 +16713,7 @@ tests/webtbf/tw3812.pp svneol=native#text/plain
tests/webtbf/tw38287.pp svneol=native#text/pascal
tests/webtbf/tw38289a.pp svneol=native#text/pascal
tests/webtbf/tw38289b.pp svneol=native#text/pascal
tests/webtbf/tw38439.pp svneol=native#text/pascal
tests/webtbf/tw3930a.pp svneol=native#text/plain
tests/webtbf/tw3931b.pp svneol=native#text/plain
tests/webtbf/tw3969.pp svneol=native#text/plain

View File

@ -2079,6 +2079,9 @@ type_e_generic_const_type_not_allowed=04128_E_Type not allowed for generic const
type_e_cant_read_write_type_in_iso_mode=04129_E_Can't read or write variables of this type in iso mode
% You are trying to \var{read} or \var{write} a variable from or to a
% file of type text, which doesn't support that variable's type in the selected language mode (iso mode).
type_w_array_size_does_not_match_size_of_constant_string=04130_W_The length of the constant string (length is $1) must be equal to the number of array elements ($2 elements)
% ISO Pascal requires that string constants have the same length as the array to which them they are assigned.
%
% \end{description}
#
# Symtable

View File

@ -592,6 +592,7 @@ const
type_e_forward_interface_type_does_not_match=04127;
type_e_generic_const_type_not_allowed=04128;
type_e_cant_read_write_type_in_iso_mode=04129;
type_w_array_size_does_not_match_size_of_constant_string=04130;
sym_e_id_not_found=05000;
sym_f_internal_error_in_symtablestack=05001;
sym_e_duplicate_id=05002;
@ -1136,9 +1137,9 @@ const
option_info=11024;
option_help_pages=11025;
MsgTxtSize = 86977;
MsgTxtSize = 87094;
MsgIdxMax : array[1..20] of longint=(
28,107,361,130,99,63,145,36,223,68,
28,107,361,131,99,63,145,36,223,68,
63,20,30,1,1,1,1,1,1,1
);

File diff suppressed because it is too large Load Diff

View File

@ -1190,6 +1190,9 @@ implementation
if (left.nodetype = stringconstn) and
(tstringconstnode(left).cst_type=cst_conststring) then
begin
if (m_iso in current_settings.modeswitches) and (arrsize<>tstringconstnode(left).len) and
is_char(tarraydef(resultdef).elementdef) then
Message2(type_w_array_size_does_not_match_size_of_constant_string,tostr(tstringconstnode(left).len),tostr(arrsize));
{ if the array of char is large enough we can use the string
constant directly. This is handled in ncgcnv }
if (arrsize>=tstringconstnode(left).len) and

13
tests/webtbf/tw38439.pp Normal file
View File

@ -0,0 +1,13 @@
{ %fail }
{ %opt=-Sew }
{$mode iso}
program string1(input, output);
var
c: packed array [1..5] of char;
inline: packed array [1..10] of char;
begin
c := '1234567890';
writeln(c);
inline := '12345';
writeln(inline);
end.