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

--- Comment #71 from Petr Skocik <pskocik at gmail dot com> ---
An Ignore macro that works everywhere where a (void) cast syntactically works
(i.e., even on void types for whatever reason) is easy:

#define IGN$(Val) (__extension__({  \
    __auto_type IGN$ = _Generic((typeof(Val)*)0, \
            void*: ((void)(Val),0), default: Val); (void)IGN$; }))

///////////////////////////
__attribute((warn_unused_result)) int getInt(void);
void getVoid(void);

void ign_test(void){
    getInt(); //warning
    getVoid(); //no warning

    (void)getInt(); //traditionally with a warning
    (void)getVoid(); //no warning
    IGN$(getInt()); //no warning
    IGN$(getVoid()); //no warning
}


https://godbolt.org/z/4qa8TcWMM

(Can be easily done wihtout __auto-type (=>use typeof) or (__extension__({ })
too (use do ;while(0)).

Would strongly prefer if the current semantics of warn_unused_result were not
broken by a late "correction".
The time for a discussion on the semantics of warn_unused_result in combo with
void cast is long gone. It's now been long established that simple (void) casts
do NOT silence warn_unused_result.
Let's not break code that expects such semantics.

A conditional compiler flag to enable void casts to silence WUR might be in
order, however, considering that clang disregards the established semantics and
a void cast does silence WUR on clang (https://godbolt.org/z/4qa8TcWMM).

Reply via email to