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

--- Comment #68 from Andrew Church <achurch+gcc at achurch dot org> ---
(In reply to uecker from comment #67)
> But also the library could switch to "discard"  or add a condition that the
> lets the user of the library choose it. 

The issue here is that the library user has no control over what the library
author chooses to do.  If the library author does not make that change, the
user currently has no recourse (other than the pragma workaround you suggest).

> As a last resort, on the compiler side one can already use a pragma to turn
> off the
> warning at a specific point.

While true, this also introduces both a compiler-specific hack and a lot of
verboseness around what ought to be a simple declaration of "I wish to ignore
this return value", and I feel like most code authors who encounter this
problem are more likely to add -Wno-unused-result to their compiler flags (thus
losing the check everywhere) than do a whole
    #pragma GCC diagnostic push
    #pragma GCC diagnostic ignored "-Wunused-result"
        system(foo);
    #pragma GCC diagnostic pop
just to make that one instance go away.

I do agree that "(void)" is very idiomatic, and something like a [[discard]]
statement attribute (which would silence warnings for both __attribute__((wur))
and [[nodiscard]]) would make the intent clearer.  Perhaps something to suggest
for a future version of the C standard?

Reply via email to