Jelajahi Sumber

* give an error when trying to get the address of an element of a dynamic
string in a typed constant, like Delphi (instead of generating a bogus
address)

git-svn-id: trunk@33958 -

Jonas Maebe 9 tahun lalu
induk
melakukan
b8ed0fac5d
5 mengubah file dengan 33 tambahan dan 1 penghapusan
  1. 3 0
      .gitattributes
  2. 3 1
      compiler/ngtcon.pas
  3. 9 0
      tests/tbf/tb0252a.pp
  4. 9 0
      tests/tbf/tb0252b.pp
  5. 9 0
      tests/tbf/tb0252c.pp

+ 3 - 0
.gitattributes

@@ -10343,6 +10343,9 @@ tests/tbf/tb0248.pp svneol=native#text/pascal
 tests/tbf/tb0249.pp svneol=native#text/pascal
 tests/tbf/tb0250.pp svneol=native#text/pascal
 tests/tbf/tb0251.pp svneol=native#text/pascal
+tests/tbf/tb0252a.pp svneol=native#text/plain
+tests/tbf/tb0252b.pp svneol=native#text/plain
+tests/tbf/tb0252c.pp svneol=native#text/plain
 tests/tbf/ub0115.pp svneol=native#text/plain
 tests/tbf/ub0149.pp svneol=native#text/plain
 tests/tbf/ub0158a.pp svneol=native#text/plain

+ 3 - 1
compiler/ngtcon.pas

@@ -919,7 +919,9 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
                        case hp.nodetype of
                          vecn :
                            begin
-                             if is_constintnode(tvecnode(hp).right) then
+                             if is_constintnode(tvecnode(hp).right) and
+                                not is_ansistring(tvecnode(hp).left.resultdef) and
+                                not is_wide_or_unicode_string(tvecnode(hp).left.resultdef) then
                                ftcb.queue_vecn(tvecnode(hp).left.resultdef,get_ordinal_value(tvecnode(hp).right))
                              else
                                Message(parser_e_illegal_expression);

+ 9 - 0
tests/tbf/tb0252a.pp

@@ -0,0 +1,9 @@
+{ %FAIL }
+
+const
+  s  : ansistring = 'test';
+
+  pc : pchar = @s[1];
+
+begin
+end.

+ 9 - 0
tests/tbf/tb0252b.pp

@@ -0,0 +1,9 @@
+{ %FAIL }
+
+const
+  w  : widestring = 'abcdef';
+
+  pw : pwidechar = @w[3];
+
+begin
+end.

+ 9 - 0
tests/tbf/tb0252c.pp

@@ -0,0 +1,9 @@
+{ %FAIL }
+
+const
+  u  : unicodestring = '123456879';
+
+  pu : punicodechar = @u[4];
+
+begin
+end.