Browse Source

* only allow automatic type conversions of array constructors of
char to pchar/array of char, rather than of arbitrary array
constructors (mantis #9085)

git-svn-id: trunk@7670 -

Jonas Maebe 18 years ago
parent
commit
ba95cc22ee
3 changed files with 36 additions and 2 deletions
  1. 1 0
      .gitattributes
  2. 10 2
      compiler/defcmp.pas
  3. 25 0
      tests/webtbs/tw9085.pp

+ 1 - 0
.gitattributes

@@ -8295,6 +8295,7 @@ tests/webtbs/tw8950.pp svneol=native#text/plain
 tests/webtbs/tw8975.pp svneol=native#text/plain
 tests/webtbs/tw8975a.pp svneol=native#text/plain
 tests/webtbs/tw9054.pp svneol=native#text/plain
+tests/webtbs/tw9085.pp svneol=native#text/plain
 tests/webtbs/ub1873.pp svneol=native#text/plain
 tests/webtbs/ub1883.pp svneol=native#text/plain
 tests/webtbs/uw0555.pp svneol=native#text/plain

+ 10 - 2
compiler/defcmp.pas

@@ -848,7 +848,11 @@ implementation
                    begin
                      { string constant (which can be part of array constructor)
                        to zero terminated string constant }
-                     if (fromtreetype in [arrayconstructorn,stringconstn]) and
+                     if (((fromtreetype = arrayconstructorn) and
+                          { can't use is_chararray, because returns false for }
+                          { array constructors                                }
+                          is_char(tarraydef(def_from).elementdef)) or
+                         (fromtreetype = stringconstn)) and
                         (is_pchar(def_to) or is_pwidechar(def_to)) then
                       begin
                         doconv:=tc_cstring_2_pchar;
@@ -937,7 +941,11 @@ implementation
                    begin
                      { string constant (which can be part of array constructor)
                        to zero terminated string constant }
-                     if (fromtreetype in [arrayconstructorn,stringconstn]) and
+                     if (((fromtreetype = arrayconstructorn) and
+                          { can't use is_chararray, because returns false for }
+                          { array constructors                                }
+                          is_char(tarraydef(def_from).elementdef)) or
+                         (fromtreetype = stringconstn)) and
                         (is_pchar(def_to) or is_pwidechar(def_to)) then
                       begin
                         doconv:=tc_cstring_2_pchar;

+ 25 - 0
tests/webtbs/tw9085.pp

@@ -0,0 +1,25 @@
+program chatserver;
+
+{$mode objfpc}
+
+procedure Sendln(MsgType: Longint; Str: PChar);
+begin
+  halt(1);
+end;
+
+procedure Sendln(MsgType: Longint; Str: array of PChar);
+begin
+  halt(0);
+end;
+
+
+procedure Sendln(MsgType: Longint; Str: array of char);
+begin
+  halt(1);
+end;
+
+
+
+begin
+  Sendln(1, ['str1', 'str2'])
+end.