浏览代码

* 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 -

Jonas Maebe 12 年之前
父节点
当前提交
1244cdff70
共有 5 个文件被更改,包括 58 次插入7 次删除
  1. 3 0
      .gitattributes
  2. 22 7
      compiler/defcmp.pas
  3. 9 0
      tests/webtbf/tw24013.pp
  4. 11 0
      tests/webtbf/tw24013a.pp
  5. 13 0
      tests/webtbf/tw24013b.pp

+ 3 - 0
.gitattributes

@@ -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

+ 22 - 7
compiler/defcmp.pas

@@ -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 - 0
tests/webtbf/tw24013.pp

@@ -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 - 0
tests/webtbf/tw24013a.pp

@@ -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 - 0
tests/webtbf/tw24013b.pp

@@ -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.