mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-28 07:19:23 +02:00
* correctly convert a single WideChar to a PChar constant with the correct code page
+ added test
This commit is contained in:
parent
889c164f78
commit
a93942cd27
@ -149,7 +149,7 @@ uses
|
||||
symtable,
|
||||
defutil,defcmp,
|
||||
{ pass 1 }
|
||||
htypechk,procinfo,
|
||||
htypechk,procinfo,pass_1,
|
||||
nmem,ncnv,ninl,ncon,nld,nadd,
|
||||
{ parser specific stuff }
|
||||
pbase,pexpr,
|
||||
@ -844,10 +844,20 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
|
||||
{ maybe pchar ? }
|
||||
else
|
||||
if is_char(def.pointeddef) and
|
||||
((node.nodetype=stringconstn) or is_constcharnode(node)) then
|
||||
((node.nodetype=stringconstn) or is_constcharnode(node) or is_constwidecharnode(node)) then
|
||||
begin
|
||||
{ ensure that a widestring is converted to the current codepage }
|
||||
if is_wide_or_unicode_string(node.resultdef) then
|
||||
if is_constwidecharnode(node) then
|
||||
begin
|
||||
initwidestring(pw);
|
||||
concatwidestringchar(pw,tcompilerwidechar(word(tordconstnode(node).value.svalue)));
|
||||
hp:=cstringconstnode.createunistr(pw);
|
||||
donewidestring(pw);
|
||||
node.free;
|
||||
do_typecheckpass(hp);
|
||||
node:=hp;
|
||||
end;
|
||||
if (node.nodetype=stringconstn) and is_wide_or_unicode_string(node.resultdef) then
|
||||
tstringconstnode(node).changestringtype(getansistringdef);
|
||||
{ create a tcb for the string data (it's placed in a separate
|
||||
asmlist) }
|
||||
|
21
tests/tbs/tb0696.pp
Normal file
21
tests/tbs/tb0696.pp
Normal file
@ -0,0 +1,21 @@
|
||||
{$codepage utf8}
|
||||
program tb0696;
|
||||
var
|
||||
ar: PChar = 'Ё';
|
||||
ar2: PChar;
|
||||
l, i: SizeInt;
|
||||
begin
|
||||
Writeln(strlen(ar)); //Error
|
||||
Writeln(Length(Ar)); //Error
|
||||
l := Length(ar);
|
||||
ar2 := 'Ё';
|
||||
Writeln(strlen(ar2)); //Ok
|
||||
Writeln(Length(Ar2)); //Ok
|
||||
if l <> Length(ar2) then
|
||||
Halt(1);
|
||||
for i := 0 to l - 1 do
|
||||
if ar[i] <> ar2[i] then
|
||||
Halt(2 + i);
|
||||
//Readln;
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user