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.
This commit is contained in:
Stephen Heumann 2022-12-12 22:07:01 -06:00
parent fe62f70d51
commit 4bc486eade
2 changed files with 16 additions and 13 deletions

View File

@ -449,20 +449,21 @@ for i := 0 to hashSize do begin
while sp <> nil do begin while sp <> nil do begin
if sp^.storage = private then if sp^.storage = private then
if sp^.itype^.kind = functionType then if sp^.itype^.kind = functionType then
if sp^.state <> defined then begin if sp^.state <> defined then
numErrors := numErrors+1; if sp^.used then begin
new(msg); numErrors := numErrors+1;
msg^ := concat('The static function ', sp^.name^, new(msg);
' was not defined.'); msg^ := concat('The static function ', sp^.name^,
writeln('*** ', msg^); ' was used but never defined.');
if terminalErrors then begin writeln('*** ', msg^);
if enterEditor then if terminalErrors then begin
ExitToEditor(msg, ord4(firstPtr)-ord4(bofPtr)) if enterEditor then
else ExitToEditor(msg, ord4(firstPtr)-ord4(bofPtr))
TermError(0); else
TermError(0);
end; {if}
liDCBGS.merrf := 16;
end; {if} end; {if}
liDCBGS.merrf := 16;
end; {if}
sp := sp^.next; sp := sp^.next;
end; {while} end; {while}
end; {for} end; {for}

View File

@ -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. 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 ----------------------------------- -- Bugs from C 2.1.0 that have been fixed -----------------------------------
1. In some situations, fread() reread the first 1K or so of the file. 1. In some situations, fread() reread the first 1K or so of the file.