https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128411
Bug ID: 128411
Summary: Feature request: Add a flag to strictly check unused
variables, ignoring name exemptions
Product: gcc
Version: 14.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: ada
Assignee: unassigned at gcc dot gnu.org
Reporter: oliverbrooks316 at gmail dot com
CC: dkm at gcc dot gnu.org
Target Milestone: ---
GNAT currently suppresses unused variable warnings if the variable name
contains the substrings DISCARD, DUMMY, IGNORE, JUNK, UNUSE, TMP, or TEMP. See:
https://gcc.gnu.org/onlinedocs/gnat_rm/Pragma-Unused.html
While this is something specific to GNAT and can be convenient, it is not
required by ISO/IEC 8652. Therefore, a flag that suppresses these name
exceptions to warn about unused variables regardless of their names can be made
available.
My main objection is that these rules rely on the assumption that these
substrings are exclusive to contexts where a value is temporary or unimportant.
However, this may not be the case. For example, a medical codebase might name a
variable Temporal_Bone, which is completely unrelated to the variable having a
temporary value.
Moreover, this can be problematic in non-English speaking codebases, too. Using
variable names in the native language is common practice, and there are many
words that are completely unrelated to ignoring or discarding, yet they contain
or match those substrings.
That's why there should be a flag that disables this exception. It doesn't have
to be set by default if backwards compatibility is an issue, but at least give
the choice to disable this behavior.