From db8a67747da9b5589d354962af0aacc5aeffbafc Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Fri, 8 Oct 2010 17:42:53 +0000 Subject: [PATCH] * 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 - --- .gitattributes | 1 + compiler/pexpr.pas | 2 ++ tests/webtbf/tw14354.pp | 15 +++++++++++++++ 3 files changed, 18 insertions(+) create mode 100644 tests/webtbf/tw14354.pp diff --git a/.gitattributes b/.gitattributes index 857357a874..63f0f1e244 100644 --- a/.gitattributes +++ b/.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 diff --git a/compiler/pexpr.pas b/compiler/pexpr.pas index 140dc398bc..7062992c68 100644 --- a/compiler/pexpr.pas +++ b/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 diff --git a/tests/webtbf/tw14354.pp b/tests/webtbf/tw14354.pp new file mode 100644 index 0000000000..30126a88b7 --- /dev/null +++ b/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.