[fpc-devel] Implicit function specialization precedence

Sven Barth pascaldragon at googlemail.com
Wed Apr 7 07:39:04 CEST 2021

Am 06.04.2021 um 23:11 schrieb Ryan Joseph via fpc-devel:
>> On Apr 6, 2021, at 12:57 PM, Sven Barth <pascaldragon at googlemail.com> wrote:
>> In the example you posted below, I agree with you, but that is not what I said. Look at my example again:
> Also could you please verify that $H+ isn't causing problems? The string literal 'Hello World' is a short string but "String" is an AnsiString so that may influence the results you're expecting.  However  even without the operator I don't know how to delineate between the explicit cast vs the non-explicit cast.
> 	Writeln(Test('Hello World'));
> 	Writeln(Test(String('Hello World')));
> These both appear to be equal as far as is_better_candidate is concerned.

First of *you* need to make sure that the type you pick for the generic 
parameter for a string constant is the correct one matching the $H+ 
directive as well as the UnicodeString modeswitch (and if the string 
constant contains WideChar elements it needs to be a UnicodeString 
anyway). That's where you currently search for the SHORTSTRING type.

Then you only need to make sure that the check for generic vs. 
non-generic is in place as I said in the other mail and the compiler 
will do the rest for you. You don't need to do *anything*. Your task is 
merely to provide the compiler with the suitable overload candidates and 
a way to check their order and it will already do all the rest.


More information about the fpc-devel mailing list