From 4bc486eade01256769e3fb6360e0d7f8f426007b Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Mon, 12 Dec 2022 22:07:01 -0600 Subject: [PATCH] Do not require unused static functions to be defined. This mostly implements the rule in C17 6.9 p3, which requires a definition to be provided only if the function is used in an expression. Per that rule, we should also exclude most sizeof or _Alignof operands, but we don't do that yet. --- Symbol.pas | 27 ++++++++++++++------------- cc.notes | 2 ++ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Symbol.pas b/Symbol.pas index f87fbea..e5069bd 100644 --- a/Symbol.pas +++ b/Symbol.pas @@ -449,20 +449,21 @@ for i := 0 to hashSize do begin while sp <> nil do begin if sp^.storage = private then if sp^.itype^.kind = functionType then - if sp^.state <> defined then begin - numErrors := numErrors+1; - new(msg); - msg^ := concat('The static function ', sp^.name^, - ' was not defined.'); - writeln('*** ', msg^); - if terminalErrors then begin - if enterEditor then - ExitToEditor(msg, ord4(firstPtr)-ord4(bofPtr)) - else - TermError(0); + if sp^.state <> defined then + if sp^.used then begin + numErrors := numErrors+1; + new(msg); + msg^ := concat('The static function ', sp^.name^, + ' was used but never defined.'); + writeln('*** ', msg^); + if terminalErrors then begin + if enterEditor then + ExitToEditor(msg, ord4(firstPtr)-ord4(bofPtr)) + else + TermError(0); + end; {if} + liDCBGS.merrf := 16; end; {if} - liDCBGS.merrf := 16; - end; {if} sp := sp^.next; end; {while} end; {for} diff --git a/cc.notes b/cc.notes index e67093f..0a8c713 100644 --- a/cc.notes +++ b/cc.notes @@ -2063,6 +2063,8 @@ int foo(int[42]); 229. Each time a CDev written with ORCA/C was opened and closed, it would leak a user ID. If it was opened and closed many times, the system could run out of user IDs of the appropriate type, potentially causing problems. To avoid this, new cleanup code has been added that runs when a CDev is closed. To ensure this code gets run, CDevs written with ORCA/C should always set the wantClose flag so that they receive CloseCDEV messages, even if they do not otherwise need them. +230. It should be allowed to declare a static function that is never defined, provided that the function is also never used in an expression. + -- Bugs from C 2.1.0 that have been fixed ----------------------------------- 1. In some situations, fread() reread the first 1K or so of the file.