Currency overloading issue with Math.SameValue on Windows 64-bit, complicated by generics
Original Reporter info from Mantis: Bart @flyingsheep
-
Reporter name: Bart Broersma
Original Reporter info from Mantis: Bart @flyingsheep
- Reporter name: Bart Broersma
Description:
This issue popped up in Lazarus where the compilation of TSpinEditExBase, a generic class, did not compile anymore with fpc trunk for 64-bit windows if the class was specialized with type Currency.
It seems that overloading Math.SameValue() with currency as one of it's parameters works different than in 3.2.0.
Also if SameValue() is called in a specialisation of a generic method, it will fail to compile always in this scenario.
Steps to reproduce:
Try to compile the following program with fpc 3.2.0 and fpc trunk for both win-32 and win-64 bit and observe the diffrences between bitness and fpc version.
program c;
{$mode objfpc}
uses
Math;
type
generic TBase<T> = class
private const
AConst = 1;
private
GenVarA: T;
GenVarB: T;
function Foo: Boolean;
end;
function TBase.Foo: Boolean;
begin
//Fails with trunk win-64 if TCur type is defined (e.g. not commented out) (*)
Result := SameValue(AConst, GenVarB);
//Fails with trunk win-64, EVEN if TCur definition is commented out
//Fails with 3.2.0 win-32, EVEN if TCur definition is commented out
//Fails with 3.2.0 win-64, EVEN if TCur definition is commented out, if it is defined it gives the errormesage twice for this line
Result := SameValue(GenVarA, GenVarB);
//Fails with trunk win-64 if TCur type is defined (e.g. not commented out)
Result := SameValue(GenVarA, AConst);
end;
type
TCur = specialize TBase<Currency>;
const
CurConst = 1;
var
CurVarA: Currency = 1;
CurVarB: Currency = 2;
begin
//Fails with trunk win-64
SameValue(CurConst, CurVarA);
//Fails with 3.2.0 win-64
SameValue(Currency(CurConst), CurVarA);
//Fails with 3.2.0 win-64
SameValue(CurVarA, CurVarB);
//Fails with trunk win-64
SameValue(CurVarA, CurConst);
//Fails with 3.2.0 win-64
SameValue(CurVarA, Currency(CurConst));
end.
//(*) Fails in this context means: compilation failed with the following message: Can't determine which overloaded function to call
// Win-64 means compiled for Windows with -PX86_64
// Tested with fpc trunk r47193 and r48083
Additional information:
While specific typecasting to currency works in a plain call to SameValue() for fpc trunk, this will not work for the case where SameValue is called with in a specialization with type currency of a generic method.
In Lazarus we had to move the offensive method from the base class to all derived classes, which rather sucks.
Mantis conversion info:
- Mantis ID: 38309
- OS: Windows
- OS Build: 10
- Build: r47193 ,r48083
- Platform: i386
- Version: 3.3.1
- Fixed in revision: 48089 (#aec18c24)