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