Typecasting float constant to Single/Double does not work
Original Reporter info from Mantis: FPCCore
-
Reporter name: FPC core team
Original Reporter info from Mantis: FPCCore
- Reporter name: FPC core team
Description:
Attached code fails to compile with error 'Illegal type conversion' with latest 1.9.1 compiler (downloaded from CVS at 19.12.2003).
This is not something related to Writeln, e.g. the following code fails too:
var F:Single;
begin F:=Single(1.0) end.
This occurs only if you cast to Single or Double (casting to Extended compiles and works OK). Also this occurs only if value casted is a float constant, i.e. things like
begin Writeln(Single(1)) { int constant } end.
or
var f1,f2:Single;
begin f2:=Single(f1) end.
work OK.
One may ask "Where is such explicit cast to Single needed ?". Well it's needed when we have a couple of overloaded procedures, e.g.
procedure p(const a,b:Single); overload;
begin Writeln('single') end;
procedure p(const a,b:Extended); overload;
begin Writeln('extended') end;
var F1:Single = 1.0;
begin p(F1, 1.0) end.
then FPC will say "Can't determine which overloaded function to call". And this is where we have to use
p(F1, Single(1.0))
to explicitly point which overloaded version should be used. This already worked with some earlier FPC 1.1 version.
(this is different from 1.0.x versions behaviour that was somehow weird:
p(F1, 1.0);
calls Executed version and
p(1.0, F1);
calls Single version. So I do like the way new FPC is working at this point. All I want is that Single(1.0) works.)
Oh, I almost forgot : as you can guess from looking at the attached source, this bug occurs only in DELPHI mode. Changing mode to OBJFPC, FPC and probably all other modes will make this code compile and work OK.
Additional information:
Reporter: Michalis Kamburelis
EMail: michalis at camelot dot homedns dot org
Mantis conversion info:
- Mantis ID: 4870
- OS: Linux
- Version: 1.9.1