瀏覽代碼

* when simplifying a constant string concatenation that gets assigned to a
rawbytestring, ensure the resulting constant string does not get CP_NONE
as codepage, but the default system code page (mantis #30082)

git-svn-id: trunk@33597 -

Jonas Maebe 9 年之前
父節點
當前提交
2bbab60c92
共有 3 個文件被更改,包括 22 次插入2 次删除
  1. 1 0
      .gitattributes
  2. 6 2
      compiler/nadd.pas
  3. 15 0
      tests/webtbs/tw30082.pp

+ 1 - 0
.gitattributes

@@ -15044,6 +15044,7 @@ tests/webtbs/tw30035.pp svneol=native#text/plain
 tests/webtbs/tw30035a.pp svneol=native#text/plain
 tests/webtbs/tw3004.pp svneol=native#text/plain
 tests/webtbs/tw3005.pp svneol=native#text/plain
+tests/webtbs/tw30082.pp svneol=native#text/plain
 tests/webtbs/tw3010.pp svneol=native#text/plain
 tests/webtbs/tw3012.pp svneol=native#text/plain
 tests/webtbs/tw3023.pp svneol=native#text/plain

+ 6 - 2
compiler/nadd.pas

@@ -824,7 +824,11 @@ implementation
                   begin
                     t:=cstringconstnode.createpchar(concatansistrings(s1,s2,l1,l2),l1+l2,nil);
                     typecheckpass(t);
-                    tstringconstnode(t).changestringtype(resultdef);
+                    if not is_ansistring(resultdef) or
+                       (tstringdef(resultdef).encoding<>globals.CP_NONE) then
+                      tstringconstnode(t).changestringtype(resultdef)
+                    else
+                      tstringconstnode(t).changestringtype(getansistringdef)
                   end;
                 ltn :
                   t:=cordconstnode.create(byte(compareansistrings(s1,s2,l1,l2)<0),pasbool8type,true);
@@ -1859,7 +1863,7 @@ implementation
                     begin
                       { use same code page if possible (don't force same code
                         page in case both are ansistrings with code page <>
-                        CP_NONE, since then data loss can occur (the ansistring
+                        CP_NONE, since then data loss can occur: the ansistring
                         helpers will convert them at run time to an encoding
                         that can represent both encodings) }
                       if is_ansistring(ld) and

+ 15 - 0
tests/webtbs/tw30082.pp

@@ -0,0 +1,15 @@
+{$mode objfpc}
+{$h+}
+
+var
+  s : rawByteString;
+begin
+ s:='REGISTER'+'DATA';
+ writeln(stringcodepage(s));
+ if stringcodepage(s)<>0 then
+   halt(1);
+ s:=s+'NAME';
+ writeln(stringcodepage(s));
+ if stringcodepage(s)<>0 then
+   halt(2);
+end.