Parcourir la source

* give an error when trying to use (bit)sizeof on a type that is not yet
resolved by the compiler (mantis #14354)

git-svn-id: trunk@16112 -

Jonas Maebe il y a 15 ans
Parent
commit
db8a67747d
3 fichiers modifiés avec 18 ajouts et 0 suppressions
  1. 1 0
      .gitattributes
  2. 2 0
      compiler/pexpr.pas
  3. 15 0
      tests/webtbf/tw14354.pp

+ 1 - 0
.gitattributes

@@ -9900,6 +9900,7 @@ tests/webtbf/tw14104b.pp svneol=native#text/plain
 tests/webtbf/tw14104c.pp svneol=native#text/plain
 tests/webtbf/tw14104c.pp svneol=native#text/plain
 tests/webtbf/tw14248.pp svneol=native#text/plain
 tests/webtbf/tw14248.pp svneol=native#text/plain
 tests/webtbf/tw1432.pp svneol=native#text/plain
 tests/webtbf/tw1432.pp svneol=native#text/plain
+tests/webtbf/tw14354.pp svneol=native#text/plain
 tests/webtbf/tw14650.pp svneol=native#text/plain
 tests/webtbf/tw14650.pp svneol=native#text/plain
 tests/webtbf/tw14650a.pp svneol=native#text/plain
 tests/webtbf/tw14650a.pp svneol=native#text/plain
 tests/webtbf/tw1467.pp svneol=native#text/plain
 tests/webtbf/tw1467.pp svneol=native#text/plain

+ 2 - 0
compiler/pexpr.pas

@@ -404,6 +404,8 @@ implementation
                 end
                 end
               else
               else
                begin
                begin
+                 if (p1.resultdef.typ=forwarddef) then
+                   Message1(type_e_type_is_not_completly_defined,tforwarddef(p1.resultdef).tosymname^);
                  if (l = in_sizeof_x) or
                  if (l = in_sizeof_x) or
                     (not((p1.nodetype = vecn) and
                     (not((p1.nodetype = vecn) and
                          is_packed_array(tvecnode(p1).left.resultdef)) and
                          is_packed_array(tvecnode(p1).left.resultdef)) and

+ 15 - 0
tests/webtbf/tw14354.pp

@@ -0,0 +1,15 @@
+{ %fail }
+
+{$mode objfpc}{$H+}
+
+type
+   PFoo = ^TFoo;
+   TFoo = array[0..10] of Integer;
+   TBar = array[0..SizeOf(PFoo(nil)^)] of Integer;
+var
+  Bar: TBar;
+
+begin
+  if High(Bar) <> SizeOf(TFoo) then
+    WriteLn('Error: ', High(Bar), ' <> ', SizeOf(TFoo));
+end.