From ba95cc22ee771e7c814b2a48d5a7eca7353116bc Mon Sep 17 00:00:00 2001
From: Jonas Maebe <jonas@freepascal.org>
Date: Fri, 15 Jun 2007 17:16:44 +0000
Subject: [PATCH]   * 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 -
---
 .gitattributes         |  1 +
 compiler/defcmp.pas    | 12 ++++++++++--
 tests/webtbs/tw9085.pp | 25 +++++++++++++++++++++++++
 3 files changed, 36 insertions(+), 2 deletions(-)
 create mode 100644 tests/webtbs/tw9085.pp

diff --git a/.gitattributes b/.gitattributes
index fa9c0f9102..334e63362a 100644
--- a/.gitattributes
+++ b/.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
diff --git a/compiler/defcmp.pas b/compiler/defcmp.pas
index d2813183aa..0adff612d1 100644
--- a/compiler/defcmp.pas
+++ b/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;
diff --git a/tests/webtbs/tw9085.pp b/tests/webtbs/tw9085.pp
new file mode 100644
index 0000000000..2af3dcb281
--- /dev/null
+++ b/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.