Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2018-06

FPC fails on overload

9 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

David Jenkins

The following code:

{$MODE DELPHI}
program CharOverload;
uses
   SysUtils;
procedure Foo(const aArg: UnicodeString); overload;
begin
   WriteLn('WideString: ', aArg);
end;
procedure Foo(c: WideChar); overload;
begin
   WriteLn('Char: ', c);
end;
begin
   Foo('abc');
end.

Fails with current trunk fpc with the following messages

[odysseus:fpc-trunk$] compiler/ppc386 ~/Desktop/test/CharOverload.pp Free Pascal Compiler version 3.1.1 [2018/06/18] for i386 Copyright (c) 1993-2018 by Florian Klaempfl and others Target OS: Darwin for i386
Compiling /Users/djenkins/Desktop/test/CharOverload.pp CharOverload.pp(19,3) Error: Can't determine which overloaded function to call
CharOverload.pp(19,12) Error: Illegal type conversion: "Constant String" to "WideChar"
CharOverload.pp(20,4) Fatal: There were 2 errors compiling module, stopping Fatal: Compilation aborted

It fails with same messages with {$MODE OBJFPC}.  Is this known. I can enter a Mantis if desired.

Thanks

David Jenkins

Reply by email

Marcos Douglas B. Santos
to David Jenkins
David Jenkins wrote 43 lines
The following code: {$MODE DELPHI} program CharOverload; uses SysUtils; procedure Foo(const aArg: UnicodeString); overload; begin WriteLn('WideString: ', aArg); end; procedure Foo(c: WideChar); overload; begin WriteLn('Char: ', c); end; begin Foo('abc'); end. Fails with current trunk fpc with the following messages [odysseus:fpc-trunk$] compiler/ppc386 ~/Desktop/test/CharOverload.pp Free Pascal Compiler version 3.1.1 [2018/06/18] for i386 Copyright (c) 1993-2018 by Florian Klaempfl and others Target OS: Darwin for i386 Compiling /Users/djenkins/Desktop/test/CharOverload.pp CharOverload.pp(19,3) Error: Can't determine which overloaded function to call CharOverload.pp(19,12) Error: Illegal type conversion: "Constant String" to "WideChar" CharOverload.pp(20,4) Fatal: There were 2 errors compiling module, stopping Fatal: Compilation aborted It fails with same messages with {$MODE OBJFPC}. Is this known. I can enter a Mantis if desired.

Hey David,
The compiler says "Can't determine which overloaded function to call" because both are strings.

Marcos Douglas

Reply by email

David Jenkins
to Marcos Douglas B. Santos

This is something that has just recently stopped working for us(with update to current trunk). We previously were using trunk rev 36812 with no problems.

Placing a second call

foo('a')

calls the expected WideChar version.

David

Marcos Douglas B. Santos wrote 53 lines
On Mon, Jun 18, 2018 at 3:04 PM, David Jenkins wrote: > The following code: > > > {$MODE DELPHI} > > program CharOverload; > > uses > SysUtils; > > procedure Foo(const aArg: UnicodeString); overload; > begin > WriteLn('WideString: ', aArg); > end; > > procedure Foo(c: WideChar); overload; > begin > WriteLn('Char: ', c); > end; > > begin > Foo('abc'); > end. > > > Fails with current trunk fpc with the following messages > > > [odysseus:fpc-trunk$] compiler/ppc386 ~/Desktop/test/CharOverload.pp > Free Pascal Compiler version 3.1.1 [2018/06/18] for i386 > Copyright (c) 1993-2018 by Florian Klaempfl and others > Target OS: Darwin for i386 > Compiling /Users/djenkins/Desktop/test/CharOverload.pp > CharOverload.pp(19,3) Error: Can't determine which overloaded function to > call > CharOverload.pp(19,12) Error: Illegal type conversion: "Constant String" to > "WideChar" > CharOverload.pp(20,4) Fatal: There were 2 errors compiling module, stopping > Fatal: Compilation aborted > > > It fails with same messages with {$MODE OBJFPC}. Is this known. I can enter > a Mantis if desired. Hey David, The compiler says "Can't determine which overloaded function to call" because both are strings. Marcos Douglas _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Florian Klämpfl
to David Jenkins
David Jenkins wrote
This is something that has just recently stopped working for us(with update to current trunk).  We previously were using trunk rev 36812 with no problems.

Please submit a bug report to mantis.

Reply by email

David Jenkins
to Florian Klämpfl

Done.  Mantis 33875.

Florian Klämpfl wrote 10 lines
Am 18.06.2018 um 22:00 schrieb David Jenkins: > This is something that has just recently stopped working for us(with > update > to current trunk).  We previously were using trunk rev 36812 with no > problems. Please submit a bug report to mantis. _______________________________________________ fpc-devel maillist  -  http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

J. Gareth Moreton

Technically it's a regression because it worked fine before and it breaks now.  However, I do agree... how should a string literal be interpreted? Technically either a WideString or UnicodeString is correct, so the compiler cannot decide between them or even know what the best fit is.

Gareth

On Tue 19/06/18 00:38 , "Marcos Douglas B. Santos" sent:

Florian Klämpfl wrote 9 lines
Am 18.06.2018 um 22:00 schrieb David Jenkins: > > This is something that has just recently stopped working for us(with > update > to current trunk). We previously were using trunk rev 36812 with no > problems. Please submit a bug report to mantis.

Sorry, but how the compiler will know the correct string type of 'a'?

Reply by email

Sven Barth
to J. Gareth Moreton
J. Gareth Moreton wrote 5 lines
Technically it's a regression because it worked fine before and it breaks now.  However, I do agree... how should a string literal be interpreted? Technically either a WideString or UnicodeString is correct, so the compiler cannot decide between them or even know what the best fit is.

It's an overload between UnicodeString and WideCHAR, not WideString, so there is a definitive difference.

Regards,
Sven

Reply by email

J. Gareth Moreton

Oh whoops. My mistake.

On Tue 19/06/18 06:18 , Sven Barth via
fpc-devel
sent:

Am 19.06.2018 um 02:47 schrieb J. Gareth

Moreton:

Technically it's a regression because it

worked fine before and it

breaks now.  However, I do agree... how

should a string literal be

interpreted? Technically either a

WideString or UnicodeString is correct,

so the compiler cannot decide between

them or even know what the best fit

is. It's an overload between

UnicodeString and WideCHAR, not
WideString, so

Show quoted text 5 lines
there is a definitive difference. Regards, Sven

Reply by email