mirror of
https://github.com/byteworksinc/ORCA-C.git
synced 2025-08-15 07:27:27 +00:00
Give an error when trying to use sizeof on incomplete struct or union types.
The following demonstrates cases that would erroneously be allowed (and misleadingly give a size of 0) before: #include <stdio.h> struct s *S; int main(void) { printf("%lu %lu\n", sizeof(struct s), sizeof *S); }
This commit is contained in:
@@ -1199,9 +1199,8 @@ var
|
|||||||
codeGeneration := lCodeGeneration and (numErrors = 0);
|
codeGeneration := lCodeGeneration and (numErrors = 0);
|
||||||
op^.token.lval := expressionType^.size;
|
op^.token.lval := expressionType^.size;
|
||||||
with expressionType^ do
|
with expressionType^ do
|
||||||
if kind = arrayType then
|
if (size = 0) or ((kind = arrayType) and (elements = 0)) then
|
||||||
if (elements = 0) or (size = 0) then
|
Error(49);
|
||||||
Error(49);
|
|
||||||
end; {else}
|
end; {else}
|
||||||
op^.left := nil;
|
op^.left := nil;
|
||||||
end {if sizeofsy}
|
end {if sizeofsy}
|
||||||
@@ -1607,8 +1606,8 @@ if token.kind in startExpression then begin
|
|||||||
sp^.token.kind := ulongconst;
|
sp^.token.kind := ulongconst;
|
||||||
sp^.token.class := longConstant;
|
sp^.token.class := longConstant;
|
||||||
sp^.token.lval := typeSpec^.size;
|
sp^.token.lval := typeSpec^.size;
|
||||||
if typeSpec^.kind = arrayType then
|
with typeSpec^ do
|
||||||
if (typeSpec^.elements = 0) or (typeSpec^.size = 0) then
|
if (size = 0) or ((kind = arrayType) and (elements = 0)) then
|
||||||
Error(49);
|
Error(49);
|
||||||
sp^.next := stack;
|
sp^.next := stack;
|
||||||
stack := sp;
|
stack := sp;
|
||||||
|
@@ -529,7 +529,7 @@ if list or (numErr <> 0) then begin
|
|||||||
46: msg := @'you must initialize the individual elements of a struct, union, or non-char array';
|
46: msg := @'you must initialize the individual elements of a struct, union, or non-char array';
|
||||||
47: msg := @'type conflict';
|
47: msg := @'type conflict';
|
||||||
48: msg := @'pointer initializers must resolve to an integer, address or string';
|
48: msg := @'pointer initializers must resolve to an integer, address or string';
|
||||||
49: msg := @'the array size could not be determined';
|
49: msg := @'the size could not be determined';
|
||||||
50: msg := @'only parameters or types may be declared here';
|
50: msg := @'only parameters or types may be declared here';
|
||||||
51: msg := @'lint: undefined function';
|
51: msg := @'lint: undefined function';
|
||||||
52: msg := @'you cannot initialize a type';
|
52: msg := @'you cannot initialize a type';
|
||||||
|
Reference in New Issue
Block a user