diff --git a/.gitattributes b/.gitattributes index 497adec751..1850fae4ef 100644 --- a/.gitattributes +++ b/.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 diff --git a/compiler/ninl.pas b/compiler/ninl.pas index cd8e181eb5..5142ed8614 100644 --- a/compiler/ninl.pas +++ b/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'; diff --git a/tests/webtbs/tw8148.pp b/tests/webtbs/tw8148.pp new file mode 100644 index 0000000000..444f6843bb --- /dev/null +++ b/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.