Skip to content

Commit

Permalink
Fix for alliedmodders#976 to ignore unused stock Variables
Browse files Browse the repository at this point in the history
This change treats stock variables the same as public during when checking for unused variables.
  • Loading branch information
c0rp3n committed Jun 9, 2024
1 parent 2213b8e commit 1e1fea5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
11 changes: 8 additions & 3 deletions compiler/semantics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2355,9 +2355,14 @@ bool Semantics::TestSymbol(Decl* sym, bool testconst) {
default: {
auto var = sym->as<VarDeclBase>();
/* a variable */
if (!var->is_used() && !var->is_public()) {
report(sym, 203) << sym->name(); /* symbol isn't used (and not public) */
} else if (!var->is_public() && !var->is_read()) {

// We ignore variables that are marked as public or stock.
if (var->is_public() || var->is_stock())
break;

if (!var->is_used()) {
report(sym, 203) << sym->name(); /* symbol isn't used (and not public/stock) */
} else if (!var->is_read()) {
report(sym, 204) << sym->name(); /* value assigned to symbol is never used */
}
}
Expand Down
9 changes: 9 additions & 0 deletions tests/compile-only/ok-stock-array-unused
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// warnings_are_errors: true

stock const char messages[2][] =
{
"first",
"second"
};

public void main() {}
5 changes: 5 additions & 0 deletions tests/compile-only/ok-stock-var-unused.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// warnings_are_errors: true

stock const int X = 1;

public void main() {}

0 comments on commit 1e1fea5

Please sign in to comment.