mirror of
https://github.com/byteworksinc/ORCA-C.git
synced 2025-01-18 03:29:49 +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:
parent
5950002d03
commit
8b4c83f527
@ -1199,8 +1199,7 @@ var
|
||||
codeGeneration := lCodeGeneration and (numErrors = 0);
|
||||
op^.token.lval := expressionType^.size;
|
||||
with expressionType^ do
|
||||
if kind = arrayType then
|
||||
if (elements = 0) or (size = 0) then
|
||||
if (size = 0) or ((kind = arrayType) and (elements = 0)) then
|
||||
Error(49);
|
||||
end; {else}
|
||||
op^.left := nil;
|
||||
@ -1607,8 +1606,8 @@ if token.kind in startExpression then begin
|
||||
sp^.token.kind := ulongconst;
|
||||
sp^.token.class := longConstant;
|
||||
sp^.token.lval := typeSpec^.size;
|
||||
if typeSpec^.kind = arrayType then
|
||||
if (typeSpec^.elements = 0) or (typeSpec^.size = 0) then
|
||||
with typeSpec^ do
|
||||
if (size = 0) or ((kind = arrayType) and (elements = 0)) then
|
||||
Error(49);
|
||||
sp^.next := stack;
|
||||
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';
|
||||
47: msg := @'type conflict';
|
||||
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';
|
||||
51: msg := @'lint: undefined function';
|
||||
52: msg := @'you cannot initialize a type';
|
||||
|
Loading…
x
Reference in New Issue
Block a user