Prevent tags from shadowing variable names within static initializers.

This occurred due to looking for the symbol in all namespaces rather than only variable space.

Here is an example affected by this:

int X;
int main(void) {
        struct X {int i;};
        static int *i = &X;
}
This commit is contained in:
Stephen Heumann 2023-03-05 22:29:09 -06:00
parent 1f6bc44b48
commit 645b210e7f
2 changed files with 5 additions and 3 deletions

View File

@ -2011,7 +2011,7 @@ var
end; {else}
end {else if}
else if tree^.token.kind = ident then begin
ip := FindSymbol(tree^.token, allSpaces, false, true);
ip := FindSymbol(tree^.token, variableSpace, false, true);
if ip = nil then begin
Error(31);
errorFound := true;
@ -2231,7 +2231,7 @@ var
if kind = ident then begin
{handle names of functions or static arrays}
ip := FindSymbol(tree^.token, allSpaces, false, true);
ip := FindSymbol(tree^.token, variableSpace, false, true);
if ip = nil then begin
Error(31);
errorFound := true;
@ -2267,7 +2267,7 @@ var
iPtr^.pPlus := true;
iPtr^.isName := true;
if tree^.token.kind = ident then begin
ip := FindSymbol(tree^.token, allSpaces, false, true);
ip := FindSymbol(tree^.token, variableSpace, false, true);
if ip = nil then begin
Error(31);
errorFound := true;

View File

@ -2144,6 +2144,8 @@ int foo(int[42]);
236. If a typedef name was used immediately after the end of an inner scope where the same name was used as a variable name or struct/union/enum tag, it might not be properly recognized as a typedef name, leading to spurious errors.
237. If the same identifier was used for both a variable or function name and a struct/union/enum tag, it might not be possible to take the address of the variable or function within the initializer for a static variable.
-- Bugs from C 2.1.0 that have been fixed -----------------------------------
1. In some situations, fread() reread the first 1K or so of the file.