Sfoglia il codice sorgente

* fix for Mantis #37650: apply adjusted patch by Ryan Joseph do not range check the length of ShortStrings if their length parameter is based on a generic constant
+ added test

git-svn-id: trunk@46766 -

svenbarth 5 anni fa
parent
commit
b2177fb50e
3 ha cambiato i file con 29 aggiunte e 1 eliminazioni
  1. 1 0
      .gitattributes
  2. 6 1
      compiler/pexpr.pas
  3. 22 0
      tests/webtbs/tw37650.pp

+ 1 - 0
.gitattributes

@@ -18444,6 +18444,7 @@ tests/webtbs/tw37554.pp svneol=native#text/pascal
 tests/webtbs/tw3758.pp svneol=native#text/plain
 tests/webtbs/tw3764.pp svneol=native#text/plain
 tests/webtbs/tw3765.pp svneol=native#text/plain
+tests/webtbs/tw37650.pp svneol=native#text/pascal
 tests/webtbs/tw3768.pp svneol=native#text/plain
 tests/webtbs/tw3774.pp svneol=native#text/plain
 tests/webtbs/tw3777.pp svneol=native#text/plain

+ 6 - 1
compiler/pexpr.pas

@@ -114,7 +114,12 @@ implementation
                end
              else
                begin
-                if (tordconstnode(p).value<=0) then
+                { the node is a generic param while parsing a generic def
+                  so disable the range checking for the string }
+                if parse_generic and
+                  (nf_generic_para in p.flags) then
+                  tordconstnode(p).value:=255;
+                if tordconstnode(p).value<=0 then
                   begin
                      Message(parser_e_invalid_string_size);
                      tordconstnode(p).value:=255;

+ 22 - 0
tests/webtbs/tw37650.pp

@@ -0,0 +1,22 @@
+{ %NORUN }
+
+program tw37650;
+
+{$mode objfpc}
+
+type
+  generic TMyClass<const U: Integer> = class
+    type TKey = String[U];
+  end;
+
+generic procedure Test<const U: Integer>;
+type
+  TKey = String[U];
+begin
+end;
+
+type
+  TMyClass12 = specialize TMyClass<12>;
+begin
+  specialize Test<12>;
+end.