From 645b210e7fc6a19da55a5df325e2079fab72db84 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 5 Mar 2023 22:29:09 -0600 Subject: [PATCH] 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; } --- Parser.pas | 6 +++--- cc.notes | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Parser.pas b/Parser.pas index 25bf3d1..3f01793 100644 --- a/Parser.pas +++ b/Parser.pas @@ -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; diff --git a/cc.notes b/cc.notes index 448d27d..723e840 100644 --- a/cc.notes +++ b/cc.notes @@ -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.