From de58691e75b64891a12b106fcc243a79b63f15a6 Mon Sep 17 00:00:00 2001 From: Sergey Larin Date: Fri, 28 Jan 2022 13:09:52 +0300 Subject: [PATCH] Allow WideChar const to UTF8String const conversion --- compiler/ncnv.pas | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/compiler/ncnv.pas b/compiler/ncnv.pas index f27db02e70..4d435ad2b3 100644 --- a/compiler/ncnv.pas +++ b/compiler/ncnv.pas @@ -1282,7 +1282,9 @@ implementation begin if (torddef(left.resultdef).ordtype=uwidechar) then begin - if (current_settings.sourcecodepage<>CP_UTF8) then + if not((current_settings.sourcecodepage=CP_UTF8) or + ((tstringdef(resultdef).stringtype=st_ansistring) and + (tstringdef(resultdef).encoding=CP_UTF8))) then begin if tordconstnode(left).value.uvalue>127 then begin @@ -1311,6 +1313,13 @@ implementation l:=UnicodeToUtf8(@(sa[1]),Length(sa),@cw,1); SetLength(sa,l-1); hp:=cstringconstnode.createstr(sa); + { explicitly set the type of string constant to avoid unnecessary conversion } + if (tstringdef(resultdef).stringtype=st_ansistring) and + (tstringdef(resultdef).encoding=CP_UTF8) then + begin + hp.cst_type:=cst_ansistring; + hp.resultdef:=resultdef; + end; end end else