浏览代码

* 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 15 年之前
父节点
当前提交
db8a67747d
共有 3 个文件被更改,包括 18 次插入0 次删除
  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/tw14248.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/tw14650a.pp svneol=native#text/plain
 tests/webtbf/tw1467.pp svneol=native#text/plain

+ 2 - 0
compiler/pexpr.pas

@@ -404,6 +404,8 @@ implementation
                 end
               else
                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
                     (not((p1.nodetype = vecn) 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.