Re: [fpc-devel] Why: "Can't take the address of constant expressions" here?

2023-01-14 Thread wkitty42--- via fpc-devel

On 1/13/23 5:35 AM, Bart via fpc-devel wrote:

On Fri, Jan 13, 2023 at 11:13 AM wkitty42--- via fpc-devel
 wrote:





First of all, adding a 'end;" for the "with" compiles under Linux.
That's because widestring=unicodestring on Linux.


i'm a little surprised there is no "mismatched begin/end" error with the caret
pointing to the 2nd begin...

--


That's a copy/paste error.by me.
The original code had about 10 more function calls and then a closing
end for the "with WideStringManager do begin "



oh! that would explain it :lol:


--
 NOTE: No off-list assistance is given without prior approval.
   *Please keep mailing list traffic on the list where it belongs!*
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Why: "Can't take the address of constant expressions" here?

2023-01-13 Thread Bart via fpc-devel
On Fri, Jan 13, 2023 at 11:13 AM wkitty42--- via fpc-devel
 wrote:
>

> > First of all, adding a 'end;" for the "with" compiles under Linux.
> > That's because widestring=unicodestring on Linux.
>
> i'm a little surprised there is no "mismatched begin/end" error with the caret
> pointing to the 2nd begin...
>
> --

That's a copy/paste error.by me.
The original code had about 10 more function calls and then a closing
end for the "with WideStringManager do begin "

-- 
Bart
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Why: "Can't take the address of constant expressions" here?

2023-01-13 Thread wkitty42--- via fpc-devel

On 1/12/23 10:29 AM, Mattias Gaertner via fpc-devel wrote:

On Wed, 11 Jan 2023 23:58:34 +0100
Bart via fpc-devel  wrote:

[...]

begin
   with WideStringManager do
   begin
 writeln(1);
 Wide2AnsiMoveProc(pwidechar(WSource),RawByteString(ADest),
CP_UTF8, Length(WSource));
 writeln(2);
 Ansi2WideMoveProc(PChar(ASource), CP_UTF8, UDest,
Length(ASource));   //<< test.lpr(24,53) Error: Can't take the address
of constant expressions (caret behind UDest)
end.


First of all, adding a 'end;" for the "with" compiles under Linux.
That's because widestring=unicodestring on Linux.


i'm a little surprised there is no "mismatched begin/end" error with the caret 
pointing to the 2nd begin...


--
 NOTE: No off-list assistance is given without prior approval.
   *Please keep mailing list traffic on the list where it belongs!*
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Why: "Can't take the address of constant expressions" here?

2023-01-12 Thread Sven Barth via fpc-devel

Am 13.01.2023 um 01:05 schrieb Bart via fpc-devel:

The issue is indeed the conversion from UnicodeString to WideString
which is not allowed for a var/out parameter. That the compiler doesn't
use the error “Call by var for arg no. 3 has to match exactly: Got
"UnicodeString" expected "WideString"” is due to Ansi2WideMoveProc()
being a function pointer. The code that determines that error is not
called in that case, instead the other is caused essentially as a last
resort.

Thanks for explaining.


You can report a bug with the following sample to hopefully improve this:


Reported as issue #40106


Thank you.

Regards,
Sven
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Why: "Can't take the address of constant expressions" here?

2023-01-12 Thread Bart via fpc-devel
> The issue is indeed the conversion from UnicodeString to WideString
> which is not allowed for a var/out parameter. That the compiler doesn't
> use the error “Call by var for arg no. 3 has to match exactly: Got
> "UnicodeString" expected "WideString"” is due to Ansi2WideMoveProc()
> being a function pointer. The code that determines that error is not
> called in that case, instead the other is caused essentially as a last
> resort.

Thanks for explaining.

>
> You can report a bug with the following sample to hopefully improve this:
>
Reported as issue #40106

On Thu, Jan 12, 2023 at 9:39 PM Sven Barth  wrote:
>
> Am 11.01.2023 um 23:58 schrieb Bart via fpc-devel:
> > Given the following program (an excerpt form a test program for a
> > bugreport about the fpwidestring unit):
> >
> > ===
> > program test;
> > {$codepage utf8}
> > {$mode objfpc}
> > {$h+}
> >
> > uses
> >FpWideString;
> >
> > var
> >WSource: WideString = 'source';
> >USource: UnicodeString = 'source';
> >WDest: WideString = '' ;
> >UDest: UnicodeString = '';
> >ASource: AnsiString = 'source';
> >ADest: AnsiString = '';
> >P: array[0..99] of AnsiChar;
> >
> > begin
> >with WideStringManager do
> >begin
> >  writeln(1);
> >  Wide2AnsiMoveProc(pwidechar(WSource),RawByteString(ADest),
> > CP_UTF8, Length(WSource));
> >  writeln(2);
> >  Ansi2WideMoveProc(PChar(ASource), CP_UTF8, UDest,
> > Length(ASource));   //<< test.lpr(24,53) Error: Can't take the address
> > of constant expressions (caret behind UDest)
> > end.
> > 
> > C:\Users\Bart\LazarusProjecten\bugs\Console\fpwidestring>fpc test.lpr
> > Free Pascal Compiler version 3.3.1 [2022/10/11] for i386
> > Copyright (c) 1993-2022 by Florian Klaempfl and others
> > Target OS: Win32 for i386
> > Compiling test.lpr
> > test.lpr(24,53) Error: Can't take the address of constant expressions
> > ...
> > UDest is of the wrong type here, it compiles fine with WDest (WideString).
> > I just don't understand the "Can't take the address of constant expressions"
> > I would have expected something like "Call by var for arg no. 3 has to
> > match exactly: Got "UnicodeString" expected "WideString""
>
> The issue is indeed the conversion from UnicodeString to WideString
> which is not allowed for a var/out parameter. That the compiler doesn't
> use the error “Call by var for arg no. 3 has to match exactly: Got
> "UnicodeString" expected "WideString"” is due to Ansi2WideMoveProc()
> being a function pointer. The code that determines that error is not
> called in that case, instead the other is caused essentially as a last
> resort.
>
> You can report a bug with the following sample to hopefully improve this:
>
> === code begin ===
>
> program tunicode;
>
> var
>Str: UnicodeString = 'Foobar';
>
> procedure Test(var aArg: WideString);
> begin
>
> end;
>
> var
>Func: procedure(var aArg: WideString) = Nil;
> begin
>Test(Str);
>Func(Str);
> end.
>
> === code end ===
>
> Regards,
> Sven



-- 
Bart
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Why: "Can't take the address of constant expressions" here?

2023-01-12 Thread Sven Barth via fpc-devel

Am 11.01.2023 um 23:58 schrieb Bart via fpc-devel:

Given the following program (an excerpt form a test program for a
bugreport about the fpwidestring unit):

===
program test;
{$codepage utf8}
{$mode objfpc}
{$h+}

uses
   FpWideString;

var
   WSource: WideString = 'source';
   USource: UnicodeString = 'source';
   WDest: WideString = '' ;
   UDest: UnicodeString = '';
   ASource: AnsiString = 'source';
   ADest: AnsiString = '';
   P: array[0..99] of AnsiChar;

begin
   with WideStringManager do
   begin
 writeln(1);
 Wide2AnsiMoveProc(pwidechar(WSource),RawByteString(ADest),
CP_UTF8, Length(WSource));
 writeln(2);
 Ansi2WideMoveProc(PChar(ASource), CP_UTF8, UDest,
Length(ASource));   //<< test.lpr(24,53) Error: Can't take the address
of constant expressions (caret behind UDest)
end.

C:\Users\Bart\LazarusProjecten\bugs\Console\fpwidestring>fpc test.lpr
Free Pascal Compiler version 3.3.1 [2022/10/11] for i386
Copyright (c) 1993-2022 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling test.lpr
test.lpr(24,53) Error: Can't take the address of constant expressions
...
UDest is of the wrong type here, it compiles fine with WDest (WideString).
I just don't understand the "Can't take the address of constant expressions"
I would have expected something like "Call by var for arg no. 3 has to
match exactly: Got "UnicodeString" expected "WideString""


The issue is indeed the conversion from UnicodeString to WideString 
which is not allowed for a var/out parameter. That the compiler doesn't 
use the error “Call by var for arg no. 3 has to match exactly: Got 
"UnicodeString" expected "WideString"” is due to Ansi2WideMoveProc() 
being a function pointer. The code that determines that error is not 
called in that case, instead the other is caused essentially as a last 
resort.


You can report a bug with the following sample to hopefully improve this:

=== code begin ===

program tunicode;

var
  Str: UnicodeString = 'Foobar';

procedure Test(var aArg: WideString);
begin

end;

var
  Func: procedure(var aArg: WideString) = Nil;
begin
  Test(Str);
  Func(Str);
end.

=== code end ===

Regards,
Sven
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Why: "Can't take the address of constant expressions" here?

2023-01-12 Thread Mattias Gaertner via fpc-devel
On Wed, 11 Jan 2023 23:58:34 +0100
Bart via fpc-devel  wrote:

> Given the following program (an excerpt form a test program for a
> bugreport about the fpwidestring unit):
> 
> ===
> program test;
> {$codepage utf8}
> {$mode objfpc}
> {$h+}
> 
> uses
>   FpWideString;
> 
> var
>   WSource: WideString = 'source';
>   USource: UnicodeString = 'source';
>   WDest: WideString = '' ;
>   UDest: UnicodeString = '';
>   ASource: AnsiString = 'source';
>   ADest: AnsiString = '';
>   P: array[0..99] of AnsiChar;
> 
> begin
>   with WideStringManager do
>   begin
> writeln(1);
> Wide2AnsiMoveProc(pwidechar(WSource),RawByteString(ADest),
> CP_UTF8, Length(WSource));
> writeln(2);
> Ansi2WideMoveProc(PChar(ASource), CP_UTF8, UDest,
> Length(ASource));   //<< test.lpr(24,53) Error: Can't take the address
> of constant expressions (caret behind UDest)
> end.

First of all, adding a 'end;" for the "with" compiles under Linux.
That's because widestring=unicodestring on Linux.

On Windows widestring is not a unicodestring and thus it can't be
passed to a var parameter. 

https://wiki.freepascal.org/Widestrings

Mattias
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Why: "Can't take the address of constant expressions" here?

2023-01-12 Thread Michael Van Canneyt via fpc-devel




On Wed, 11 Jan 2023, Bart via fpc-devel wrote:


Given the following program (an excerpt form a test program for a
bugreport about the fpwidestring unit):

===
program test;
{$codepage utf8}
{$mode objfpc}
{$h+}

uses
 FpWideString;

var
 WSource: WideString = 'source';
 USource: UnicodeString = 'source';
 WDest: WideString = '' ;
 UDest: UnicodeString = '';
 ASource: AnsiString = 'source';
 ADest: AnsiString = '';
 P: array[0..99] of AnsiChar;

begin
 with WideStringManager do
 begin
   writeln(1);
   Wide2AnsiMoveProc(pwidechar(WSource),RawByteString(ADest),
CP_UTF8, Length(WSource));
   writeln(2);
   Ansi2WideMoveProc(PChar(ASource), CP_UTF8, UDest,
Length(ASource));   //<< test.lpr(24,53) Error: Can't take the address
of constant expressions (caret behind UDest)
end.

C:\Users\Bart\LazarusProjecten\bugs\Console\fpwidestring>fpc test.lpr
Free Pascal Compiler version 3.3.1 [2022/10/11] for i386
Copyright (c) 1993-2022 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling test.lpr
test.lpr(24,53) Error: Can't take the address of constant expressions
...
UDest is of the wrong type here, it compiles fine with WDest (WideString).
I just don't understand the "Can't take the address of constant expressions"
I would have expected something like "Call by var for arg no. 3 has to
match exactly: Got "UnicodeString" expected "WideString""


I think that what happens is that the compiler sees that it can convert
widestring to unicodestring and allows a conversion, so it inserts a 
conversion node, but the result of the conversion is a constant expresson 
so it generates an error in a later stage of compilation.


But my knowledge is limited, someone else will need to confirm this.

Michael.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Why: "Can't take the address of constant expressions" here?

2023-01-11 Thread Bart via fpc-devel
Given the following program (an excerpt form a test program for a
bugreport about the fpwidestring unit):

===
program test;
{$codepage utf8}
{$mode objfpc}
{$h+}

uses
  FpWideString;

var
  WSource: WideString = 'source';
  USource: UnicodeString = 'source';
  WDest: WideString = '' ;
  UDest: UnicodeString = '';
  ASource: AnsiString = 'source';
  ADest: AnsiString = '';
  P: array[0..99] of AnsiChar;

begin
  with WideStringManager do
  begin
writeln(1);
Wide2AnsiMoveProc(pwidechar(WSource),RawByteString(ADest),
CP_UTF8, Length(WSource));
writeln(2);
Ansi2WideMoveProc(PChar(ASource), CP_UTF8, UDest,
Length(ASource));   //<< test.lpr(24,53) Error: Can't take the address
of constant expressions (caret behind UDest)
end.

C:\Users\Bart\LazarusProjecten\bugs\Console\fpwidestring>fpc test.lpr
Free Pascal Compiler version 3.3.1 [2022/10/11] for i386
Copyright (c) 1993-2022 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling test.lpr
test.lpr(24,53) Error: Can't take the address of constant expressions
...
UDest is of the wrong type here, it compiles fine with WDest (WideString).
I just don't understand the "Can't take the address of constant expressions"
I would have expected something like "Call by var for arg no. 3 has to
match exactly: Got "UnicodeString" expected "WideString""

-- 
Bart
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel