[fpc-devel] Overloading problem in generic class.

Bart bartjunk64 at gmail.com
Sun Sep 18 14:29:49 CEST 2022

On Sun, Sep 18, 2022 at 1:34 PM Martin Frb via fpc-devel
<fpc-devel at lists.freepascal.org> wrote:

> Just enable fpc_math_samevalue_bug
> {$if FPC_FullVersion=30202}{$ifdef Win64}
>    {$define fpc_math_samevalue_bug}
> {$endif}{$endif}

This suggest that the bug is in Windows 3.2.2

> Make it
> {$if FPC_FullVersion<=30202}
>    {$define fpc_math_samevalue_bug}
> {$endif}
This suggest that the bug is in all versions up until 3.2.2 (so fixed
in 3.1.1 and merged to 3.2 fixes branch)
That is incorrect, since it will compile on Windows with 3.2.2 for
both 32 and 64 bit.

So, back to original question:
Should it (the example with the cast to the generic type: T(_Def))
compile on all platforms, or should it not compile on Windows?
If it should compile it can be fixed for the correct compiler+platform
versions, if not, it should be fixed in a different way.

> I wonder anyway
>    TCustomSpinEditEx = class(specialize TSpinEditExBase<Int64>)
> But "SameValue" does not exist for int64 (or any int)?
> So I assume the compiler converts the int to a float

Yes it does, and then calls the Single overload of SameValue.
Given the current values of DefMaxValue and DefMinValue, this is safe.
Unwanted maybe, but only called in OI when setting Max/MinValue, so
performance penalty is not realy an issue here.
If OTOH we decide to make DefMaxValue = High(Int64, which is not very
likely), then the Single overload of SameValue seems to return TRUE if
it compares High(Int64) and High(Int64)-1.

The base class can have a virtual abstract InternalSameValue function
thet then needs to be implemented in all descendant classes.
This will break all derived classes that are not part of the Lazarus
distribution, e.g. the ExCtrls package
This may be the cleaner solution though.


More information about the fpc-devel mailing list