Browse Source

* only allow implicit type conversions from dynamic arrays to voidpointer
in Delphi mode, rather than to any pointer type (confused overload
selection in mantis #13639)

git-svn-id: trunk@13079 -

Jonas Maebe 16 years ago
parent
commit
5a09f58526
3 changed files with 58 additions and 1 deletions
  1. 1 0
      .gitattributes
  2. 2 1
      compiler/defcmp.pas
  3. 55 0
      tests/webtbs/tw13639.pp

+ 1 - 0
.gitattributes

@@ -8845,6 +8845,7 @@ tests/webtbs/tw13596a.pp svneol=native#text/plain
 tests/webtbs/tw13622.pp svneol=native#text/plain
 tests/webtbs/tw13622.pp svneol=native#text/plain
 tests/webtbs/tw13628a.pp svneol=native#text/plain
 tests/webtbs/tw13628a.pp svneol=native#text/plain
 tests/webtbs/tw13628b.pp svneol=native#text/plain
 tests/webtbs/tw13628b.pp svneol=native#text/plain
+tests/webtbs/tw13639.pp svneol=native#text/plain
 tests/webtbs/tw1364.pp svneol=native#text/plain
 tests/webtbs/tw1364.pp svneol=native#text/plain
 tests/webtbs/tw1365.pp svneol=native#text/plain
 tests/webtbs/tw1365.pp svneol=native#text/plain
 tests/webtbs/tw1374.pp svneol=native#text/plain
 tests/webtbs/tw1374.pp svneol=native#text/plain

+ 2 - 1
compiler/defcmp.pas

@@ -1013,7 +1013,8 @@ implementation
                      else
                      else
                        { dynamic array to pointer, delphi only }
                        { dynamic array to pointer, delphi only }
                        if (m_delphi in current_settings.modeswitches) and
                        if (m_delphi in current_settings.modeswitches) and
-                          is_dynamic_array(def_from) then
+                          is_dynamic_array(def_from) and
+                          is_voidpointer(def_to) then
                         begin
                         begin
                           eq:=te_equal;
                           eq:=te_equal;
                         end;
                         end;

+ 55 - 0
tests/webtbs/tw13639.pp

@@ -0,0 +1,55 @@
+program t2;
+
+{$IFDEF FPC}
+  {$mode Delphi}
+{$ENDIF}
+
+uses
+  SysUtils;
+
+type
+  Tb = array of byte;
+  int = integer;
+  TMeS = class
+    private
+     FD: Tb;
+     Fp: Integer;
+    public
+     constructor Create(cty: int);
+     procedure Write(const Buffer: TB; Offset: int; Count: int); overload;
+     procedure Write(Buffer: PAnsiChar; Offset: int; Count: int); overload;
+  end;
+
+constructor TMeS.Create(cty: int);
+begin
+  inherited Create;
+  SetLength(FD, cty);
+end;
+
+procedure TMeS.Write(Buffer: PAnsiChar; Offset: int; Count: int);
+begin
+  Move(Buffer[Offset], PAnsiChar(@FD[FP])^, Count);
+  Inc(FP, Count);
+end;
+
+procedure TMeS.Write(const Buffer: TB; Offset: int; Count: int);
+begin
+  Write(PAnsiChar(@Buffer[0]), Offset, Count);
+end;
+
+var vmes:tmes;
+
+const  vac:string='test1 copy string';
+       vtb:string='test2 copy bytes 10';
+
+var
+  s: string;
+begin
+   vmes:=tmes.Create(16);
+   vmes.write(Pansichar(vac),1,10);
+   vmes.Write(tb(vtb),10,5);
+   writeln('"',string(vmes.FD),'"');
+   s:=pchar(vmes.fd);
+   if (s<>'est1 copy  byte') then
+     halt(1);
+end.