Selaa lähdekoodia

* call the ansistring version of val for zero-based array-of-char
parameters (because they can be auto-converted to ansistring, but not
to shortstring) (mantis #8148)

git-svn-id: trunk@6076 -

Jonas Maebe 18 vuotta sitten
vanhempi
commit
a3f059bc29
3 muutettua tiedostoa jossa 29 lisäystä ja 0 poistoa
  1. 1 0
      .gitattributes
  2. 3 0
      compiler/ninl.pas
  3. 25 0
      tests/webtbs/tw8148.pp

+ 1 - 0
.gitattributes

@@ -7975,6 +7975,7 @@ tests/webtbs/tw8140g.pp svneol=native#text/plain
 tests/webtbs/tw8140h.pp svneol=native#text/plain
 tests/webtbs/tw8141.pp svneol=native#text/plain
 tests/webtbs/tw8145.pp svneol=native#text/plain
+tests/webtbs/tw8148.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

+ 3 - 0
compiler/ninl.pas

@@ -1050,6 +1050,9 @@ implementation
         { the shortstring-longint val routine by default                   }
         if (sourcepara.resultdef.typ = stringdef) then
           procname := procname + tstringdef(sourcepara.resultdef).stringtypname
+        { zero-based arrays (of char) can be implicitely converted to ansistring }
+        else if is_zero_based_array(sourcepara.resultdef) then
+          procname := procname + 'ansistr'
         else
           procname := procname + 'shortstr';
 

+ 25 - 0
tests/webtbs/tw8148.pp

@@ -0,0 +1,25 @@
+program ValVsArrayOfChar;
+
+{$IFDEF FPC}
+  {$mode delphi}
+{$ENDIF}
+
+procedure test(a: ansistring);
+begin
+end;
+
+
+var
+  Code : Integer;
+  D : Double;
+  s : Array[byte] of Char;
+begin
+  s := '123';
+  test(s);
+  Val(s, D, Code); // compiles only in delphi
+  if (abs(d-123.0) > 0.00001) then
+    halt(1);
+  Val(PChar(@s), D, Code); // compiles in both delphi and FPC
+  if (abs(d-123.0) > 0.00001) then
+    halt(1);
+end.