From e99733c1c2ed6b6768ffbd030217abc0b8c28147 Mon Sep 17 00:00:00 2001 From: c0rp3n Date: Sun, 9 Jun 2024 15:02:18 +0100 Subject: [PATCH] Fix for #972 when a static is used by a stock Function This adds stock functions to the maybe used set which seems most appropriate. We can then mark all of the functions they refer too as maybe used also. --- compiler/semantics.cpp | 4 ++++ tests/compile-only/ok-static-used-by-stock.inc | 7 +++++++ tests/compile-only/ok-static-used-by-stock.sp | 5 +++++ 3 files changed, 16 insertions(+) create mode 100644 tests/compile-only/ok-static-used-by-stock.inc create mode 100644 tests/compile-only/ok-static-used-by-stock.sp diff --git a/compiler/semantics.cpp b/compiler/semantics.cpp index 732d7927..45ee793b 100644 --- a/compiler/semantics.cpp +++ b/compiler/semantics.cpp @@ -2876,6 +2876,10 @@ bool Semantics::CheckFunctionDeclImpl(FunctionDecl* info) { if (info->as()) maybe_used_.emplace_back(info); + // We never warn about unused stock functions. + if (info->is_stock()) + maybe_used_.emplace_back(info); + auto fwd = info->prototype(); if (fwd && fwd->deprecate() && !info->is_stock()) report(info->pos(), 234) << info->name() << fwd->deprecate(); diff --git a/tests/compile-only/ok-static-used-by-stock.inc b/tests/compile-only/ok-static-used-by-stock.inc new file mode 100644 index 00000000..32fd7c52 --- /dev/null +++ b/tests/compile-only/ok-static-used-by-stock.inc @@ -0,0 +1,7 @@ +static void SomeHelperFunction() +{} + +stock void HelpMe() +{ + SomeHelperFunction(); +} diff --git a/tests/compile-only/ok-static-used-by-stock.sp b/tests/compile-only/ok-static-used-by-stock.sp new file mode 100644 index 00000000..755df5c8 --- /dev/null +++ b/tests/compile-only/ok-static-used-by-stock.sp @@ -0,0 +1,5 @@ +// warnings_are_errors: true +#include "ok-static-used-by-stock.inc" + +public void main() +{}