* don't treat bitpacked arrays of subranges of char that can be represented

using less than 8 bits per element the same as regular char arrays as far
    as automatic type conversions are concerned (they have to be explicitly
    packed/unpacked) (mantis #24013)

git-svn-id: trunk@23739 -
This commit is contained in:
Jonas Maebe 2013-03-09 10:37:30 +00:00
parent 76e6fff302
commit 1244cdff70
5 changed files with 58 additions and 7 deletions

3
.gitattributes vendored
View File

@ -12179,6 +12179,9 @@ tests/webtbf/tw2359.pp svneol=native#text/plain
tests/webtbf/tw2362.pp svneol=native#text/plain
tests/webtbf/tw2383.pp svneol=native#text/plain
tests/webtbf/tw2400.pp svneol=native#text/plain
tests/webtbf/tw24013.pp svneol=native#text/plain
tests/webtbf/tw24013a.pp svneol=native#text/plain
tests/webtbf/tw24013b.pp svneol=native#text/plain
tests/webtbf/tw2403.pp svneol=native#text/plain
tests/webtbf/tw2414.pp svneol=native#text/plain
tests/webtbf/tw2478.pp svneol=native#text/plain

View File

@ -547,7 +547,12 @@ implementation
arraydef :
begin
{ array of char to string, the length check is done by the firstpass of this node }
if is_chararray(def_from) or is_open_chararray(def_from) then
if (is_chararray(def_from) or
is_open_chararray(def_from)) and
{ bitpacked arrays of char whose element bitsize is not
8 cannot be auto-converted to strings }
(not is_packed_array(def_from) or
(tarraydef(def_from).elementdef.packedbitsize=8)) then
begin
{ "Untyped" stringconstn is an array of char }
if fromtreetype=stringconstn then
@ -857,12 +862,14 @@ implementation
{ strings in ISO Pascal (at least if the lower bound }
{ is 1, but GPC makes all equal-length chararrays }
{ compatible), so treat those the same as regular }
{ char arrays }
{ char arrays -- except if they use subrange types }
if (is_packed_array(def_from) and
not is_chararray(def_from) and
(not is_chararray(def_from) or
(tarraydef(def_from).elementdef.packedbitsize<>8)) and
not is_widechararray(def_from)) xor
(is_packed_array(def_to) and
not is_chararray(def_to) and
(not is_chararray(def_to) or
(tarraydef(def_to).elementdef.packedbitsize<>8)) and
not is_widechararray(def_to)) then
{ both must be packed }
begin
@ -965,7 +972,11 @@ implementation
else
{ to array of char, from "Untyped" stringconstn (array of char) }
if (fromtreetype=stringconstn) and
(is_chararray(def_to) or
((is_chararray(def_to) and
{ bitpacked arrays of char whose element bitsize is not
8 cannot be auto-converted from strings }
(not is_packed_array(def_to) or
(tarraydef(def_to).elementdef.packedbitsize=8))) or
is_widechararray(def_to)) then
begin
eq:=te_convert_l1;
@ -1015,8 +1026,12 @@ implementation
stringdef :
begin
{ string to char array }
if (not is_special_array(def_to)) and
(is_char(tarraydef(def_to).elementdef)or
if not is_special_array(def_to) and
((is_char(tarraydef(def_to).elementdef) and
{ bitpacked arrays of char whose element bitsize is not
8 cannot be auto-converted from strings }
(not is_packed_array(def_to) or
(tarraydef(def_to).elementdef.packedbitsize=8))) or
is_widechar(tarraydef(def_to).elementdef)) then
begin
doconv:=tc_string_2_chararray;

9
tests/webtbf/tw24013.pp Normal file
View File

@ -0,0 +1,9 @@
{ %fail }
var
astr: bitpacked array[1..5] of #0..#127;
begin
writeln('Assigning a literal string to astr:');
astr := 'aaaaa';
end.

11
tests/webtbf/tw24013a.pp Normal file
View File

@ -0,0 +1,11 @@
{ %fail }
var
astr: bitpacked array[1..5] of #0..#127;
str: string;
begin
writeln('Assigning a variable string to astr:');
str := 'aaaaa';
astr := str;
end.

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

@ -0,0 +1,13 @@
{ %fail }
var
astr: bitpacked array[1..5] of #0..#127;
str: string;
i: integer;
begin
writeln('Assigning a bitpacked array to a string variable:');
for i := 1 to 5 do
astr[i] := 'a';
str := astr;
end.