]> git.sur5r.net Git - cc65/blobdiff - src/cc65/symtab.c
Merge pull request #381 from pfusik/static-forward-decl
[cc65] / src / cc65 / symtab.c
index 191daddad50df5c213effd4617921f5891bbd38c..3275332c5490c68b89ab7a5c4b6e560716574144 100644 (file)
@@ -268,7 +268,9 @@ void EnterFunctionLevel (void)
     TagTab  = S;
 
     /* Create and assign a new label table */
-    LabelTab = NewSymTable (SYMTAB_SIZE_LABEL);
+    S = NewSymTable (SYMTAB_SIZE_LABEL);
+    S->PrevTab = LabelTab;
+    LabelTab = S;
 }
 
 
@@ -286,6 +288,7 @@ void RememberFunctionLevel (struct FuncDesc* F)
     /* Don't delete the tables */
     SymTab = SymTab->PrevTab;
     TagTab = TagTab->PrevTab;
+    LabelTab = LabelTab->PrevTab;
 }
 
 
@@ -810,6 +813,25 @@ SymEntry* AddGlobalSym (const char* Name, const Type* T, unsigned Flags)
             }
         }
 
+        /* If a static declaration follows a non-static declaration, then
+        ** warn about the conflict.  (It will compile a public declaration.)
+        */
+        if ((Flags & SC_EXTERN) == 0 && (Entry->Flags & SC_EXTERN) != 0) {
+            Warning ("static declaration follows non-static declaration of `%s'.", Name);
+        }
+
+        /* An extern declaration must not change the current linkage. */
+        if (IsFunc || (Flags & (SC_EXTERN | SC_STORAGE)) == SC_EXTERN) {
+            Flags &= ~SC_EXTERN;
+        }
+
+        /* If a public declaration follows a static declaration, then
+        ** warn about the conflict.  (It will compile a public declaration.)
+        */
+        if ((Flags & SC_EXTERN) != 0 && (Entry->Flags & SC_EXTERN) == 0) {
+            Warning ("public declaration follows static declaration of `%s'.", Name);
+        }
+
         /* Add the new flags */
         Entry->Flags |= Flags;