https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80354

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
This is the expected behavior.  Whether or not a function's return value is
considered used depends on optimization.  Simply assigning it to a variable and
doing nothing with it that affects the behavior of the program is not in this
situation considered using it.  This applies to all the cases here.  This isn't
a property of the warning itself but rather that of its dependency on prior
optimizations (which eliminate code that doesn't actually use the value).

The idea is that programs that allow output truncation to go undetected are
likely buggy.  Besides actually handling the truncation (e.g., branching on it
and taking some action that does affect the behavior), storing the return value
in a volatile variable and reading it should suppress it.

Reply via email to