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

--- Comment #75 from Zdenek Sojka <zsojka at seznam dot cz> ---
(In reply to Florian Weimer from comment #74)
> (In reply to Zdenek Sojka from comment #73)
> > See MISRA C:2012 Rule 17.7:
> > "...  If the return value of a function is intended not to be used
> > explicitly, it should be cast to the void type. ..."
> > 
> > It would be helpful if gcc could be used to write MISRA-compliant code, or
> > at least if it wouldn't generate compilation warnings when the programmer is
> > targeting MISRA-compliancy.
> 
> Doesn't this (interpretation of MISRA) mean that compliant code cannot use
> __attribute__((warn_unused_result))? That doesn't require any GCC changes.

With the current state of things, yes. MISRA suggests adding the (void) cast,
that does not suppress the warning.

For me the ideal state would be to have a -Wwarn-any-unused-result, to consider
all functions as having the "__attribute__((__warn_unused_result__))"
attribute, with the option of (void) cast to suppress the warning.

Just the following sentence of the MISRA C:2012 explains the "(void)" cast as
the way of preventing dead code; the example from comment #72:

> if (foo()) {
>   /* The return value of foo can be ignored here because X and Y.  */
> }

creates a condition that needs to be covered, even though it might not be
possible to trigger either FALSE or TRUE outcome.

Of course there are other solutions (and possible justifications); I just
wanted to show that the (void) cast of unused function result might not be that
uncommon.

Reply via email to