diff --git a/ppci/lang/c/semantics.py b/ppci/lang/c/semantics.py index 4aa97dd6..cd1c616b 100644 --- a/ppci/lang/c/semantics.py +++ b/ppci/lang/c/semantics.py @@ -320,7 +320,10 @@ def check_redeclaration_storage_class(self, sym, declaration): old_storage_class = sym.declaration.storage_class new_storage_class = declaration.storage_class # None == automatic storage class. - invalid_combos = [(None, "static"), ("extern", "static")] + # changes of linkage between internal and external are illegal + invalid_combos = [(None, "static"), + ("extern", "static"), + ("static", None)] combo = (old_storage_class, new_storage_class) if combo in invalid_combos: message = "Invalid redefine of storage class. Was {}, but now {}".format( @@ -328,9 +331,10 @@ def check_redeclaration_storage_class(self, sym, declaration): ) self.invalid_redeclaration(sym, declaration, message) - if not declaration.storage_class: - if sym.declaration.storage_class: - declaration.storage_class = sym.declaration.storage_class + # if new storage-class is "extern", keep the old storage-class + # otherwise use the new one + if new_storage_class == "extern": + declaration.storage_class = old_storage_class def invalid_redeclaration( self, sym, declaration, message="Invalid redefinition"