* prevent warning for val with second parameter not being a longint

git-svn-id: trunk@1463 -
This commit is contained in:
peter 2005-10-18 08:26:29 +00:00
parent a357bef5e5
commit 5abb9d68f6
3 changed files with 68 additions and 4 deletions

1
.gitattributes vendored
View File

@ -6273,6 +6273,7 @@ tests/webtbs/tw3971.pp svneol=native#text/plain
tests/webtbs/tw3973.pp svneol=native#text/plain
tests/webtbs/tw3977.pp svneol=native#text/plain
tests/webtbs/tw3977.txt svneol=native#text/plain
tests/webtbs/tw4006.pp svneol=native#text/plain
tests/webtbs/tw4007.pp svneol=native#text/plain
tests/webtbs/tw4009.pp svneol=native#text/plain
tests/webtbs/tw4010.pp svneol=native#text/plain

View File

@ -1037,11 +1037,13 @@ implementation
{ its right field is nil }
sourcepara.right := sizepara;
{ create the call and assign the result to dest }
{ (val helpers are functions) }
{ the assignment will take care of rangechecking }
{ create the call and assign the result to dest (val helpers are functions).
Use a trick to prevent a type size mismatch warning to be generated by the
assignment node. First convert implicitly to the resulttype. This will insert
the range check. The Second conversion is done explicitly to hide the implicit conversion
for the assignment node and therefor preventing the warning (PFV) }
addstatement(newstatement,cassignmentnode.create(
destpara.left,ccallnode.createintern(procname,newparas)));
destpara.left,ctypeconvnode.create_internal(ctypeconvnode.create(ccallnode.createintern(procname,newparas),destpara.left.resulttype),destpara.left.resulttype)));
{ dispose of the enclosing paranode of the destination }
destpara.left := nil;

61
tests/webtbs/tw4006.pp Executable file
View File

@ -0,0 +1,61 @@
{ %opt=-Sew }
{ Source provided for Free Pascal Bug Report 4006 }
{ Submitted by "Torsten Kildal" on 2005-05-23 }
{ e-mail: kildal@mx }
program Val_Test;
{$IFDEF FPC}
{$MODE TP} {BP/TP compatible}
{$H-} {short strings!}
{$ENDIF}
{$R+}
VAR
s : string;
iVar : smallint;
lVar : longint; { BP7 = Borland Pascal }
rVar : real; { 1010 = FPC 1.0.10 }
iCode : integer; { 196 = FPC 1.9.6 }
wCode : word; { 200 = FPC 2.0.0 }
begin
s:='3.14'; {content plays no roll}
VAL(s,iVar,iCode);
{BP7 : ok}
{1010: ok}
{196 : Warning: Type size mismatch, possible loss of data / range check error}
{200 : Warning: Type size mismatch, possible loss of data / range check error}
VAL(s,lVar,iCode);
{BP7 : ok}
{1010: ok}
{196 : ok}
{200 : ok}
VAL(s,rVar,iCode);
{BP7 : ok}
{1010: ok}
{196 : Warning: Type size mismatch, possible loss of data / range check error}
{200 : Warning: Type size mismatch, possible loss of data / range check error}
(*
VAL(s,iVar,wCode);
{BP7 : ok}
{1010: ok}
{196 : Warning: Type size mismatch, possible loss of data / range check error}
{200 : Warning: Type size mismatch, possible loss of data / range check error}
VAL(s,lVar,wCode);
{BP7 : ok}
{1010: ok}
{196 : ok}
{200 : ok}
VAL(s,rVar,wCode);
{BP7 : ok}
{1010: ok}
{196 : Warning: Type size mismatch, possible loss of data / range check error}
{200 : Warning: Type size mismatch, possible loss of data / range check error}
*)
end.