From 995ded07a5937fd8d0579dddcdf12e493ba3db6b Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Tue, 4 Oct 2022 18:45:11 -0500 Subject: [PATCH] Always treat "struct T;" as declaring the tag within the current scope. A declaration of this exact form always declares the tag T within the current scope, and as such makes this "struct T" a distinct type from any other "struct T" type in an outer scope. (Similarly for unions.) See C17 section 6.7.2.3 p7 (and corresponding places in all other C standards). Here is an example of a program affected by this: struct S {char a;}; int main(void) { struct S; struct S *sp; struct S {long b;} s; sp = &s; sp->b = sizeof(*sp); return s.b; } --- Parser.pas | 4 +++- cc.notes | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Parser.pas b/Parser.pas index 04dbd52..444557a 100644 --- a/Parser.pas +++ b/Parser.pas @@ -3265,7 +3265,9 @@ while token.kind in allowedTokens do begin NextToken; {skip the structure name} if structPtr = nil then begin {if the name hasn't been defined then...} if token.kind <> lbracech then - structPtr := FindSymbol(ttoken, tagSpace, false, true); + if (token.kind <> semicolonch) or + (myDeclarationModifiers <> []) then + structPtr := FindSymbol(ttoken, tagSpace, false, true); if structPtr <> nil then structTypePtr := structPtr^.itype else begin diff --git a/cc.notes b/cc.notes index be023c1..eded887 100644 --- a/cc.notes +++ b/cc.notes @@ -1899,6 +1899,10 @@ int foo(int[42]); 206. If an enum type defined in an outer scope was used in an inner scope, and then a new struct, union, or enum type was declared with the same tag in the same inner scope, a spurious error was reported. +(Bug fixes below here were added in ORCA/C 2.2.0 B7.) + +207. If a struct or union type with a tag T has been declared within an outer scope, a declaration "struct T;" or "union T;" within an inner scope should declare a separate type, distinct from the one in the outer scope. + -- Bugs from C 2.1.0 that have been fixed ----------------------------------- 1. In some situations, fread() reread the first 1K or so of the file.