Constant function pointers to overloaded functions - incorrect version called
Original Reporter info from Mantis: ahydra
-
Reporter name: Colin Haywood
Original Reporter info from Mantis: ahydra
- Reporter name: Colin Haywood
Description:
If I declare a function pointer as a const
const
fp: TFunctionType = @MyFunction
and MyFunction has two or more overloaded versions, when executing the statement
fp(...)
the incorrect version can be called.
My test case attached shows that for two overloaded versions of a function, it specifically seems to always call the first one in order of the prototypes, but only if the number of parameters passed to the correct version (that is, the one declared by TFunctionType) is less than or equal to the number of parameters passed to the other overloaded version.
Steps to reproduce:
See code below.
On clicking the button the second Add23 should be called, i.e. the one with two parameters that returns A - B, since this is the type of function declared by FNType. But instead it calls the first one with three parameters, and returns some nonsense number because C isn't initialised.
Correct behaviour is observed after swapping the order of the Add23 prototypes, or modifying FNType to take three parameters and then changing the calling statement accordingly.
Additional information:
Sorry that this is 2.2.2 - have always encountered problems when upgrading the compiler :(
Mantis conversion info:
- Mantis ID: 16820
- OS: Windows
- OS Build: XP
- Version: 2.2.2
- Fixed in version: 2.6.0
- Fixed in revision: 15508 (#58362db9)
- Monitored by: » ahydra (Colin Haywood)