[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result
From: |
Markus Armbruster |
Subject: |
Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result |
Date: |
Wed, 21 Sep 2016 14:31:36 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) |
"Daniel P. Berrange" <address@hidden> writes:
> On Wed, Sep 21, 2016 at 10:00:23AM +0000, Felipe Franciosi wrote:
>>
>> > On 21 Sep 2016, at 07:24, Markus Armbruster <address@hidden> wrote:
>> >
>> > "Pavel Dovgalyuk" <address@hidden> writes:
>> >
>> >>> From: Felipe Franciosi [mailto:address@hidden
>> >>> If compiling with -Werror=unused-result, replay-internal.c won't build
>> >>> due to a call to fwrite() where the returned value is ignored. A simple
>> >>> cast to (void) is not sufficient on recent GCCs, so this fixes it.
>> >>>
>> >>> Signed-off-by: Felipe Franciosi <address@hidden>
>> >>> ---
>> >>> replay/replay-internal.c | 2 +-
>> >>> 1 file changed, 1 insertion(+), 1 deletion(-)
>> >>>
>> >>> diff --git a/replay/replay-internal.c b/replay/replay-internal.c
>> >>> index 5835e8d..6978d76 100644
>> >>> --- a/replay/replay-internal.c
>> >>> +++ b/replay/replay-internal.c
>> >>> @@ -65,7 +65,7 @@ void replay_put_array(const uint8_t *buf, size_t size)
>> >>> {
>> >>> if (replay_file) {
>> >>> replay_put_dword(size);
>> >>> - fwrite(buf, 1, size, replay_file);
>> >>> + (void)(fwrite(buf, 1, size, replay_file)+1);
>> >>> }
>> >>> }
>> >>
>> >> This looks very weird.
>>
>> Oh I couldn't agree more. I hate this syntax. It is, however, the simplest
>> way to get around this issue. See:
>> http://stackoverflow.com/questions/11888594/ignoring-return-values-in-c
>
> If we want to ignore return value reliably, lets just pull in the
> ignore_value macro from gnulib which is known to work across GCC
> versions
>
>
> /* Normally casting an expression to void discards its value, but GCC
> versions 3.4 and newer have __attribute__ ((__warn_unused_result__))
> which may cause unwanted diagnostics in that case. Use __typeof__
> and __extension__ to work around the problem, if the workaround is
> known to be needed. */
> #if 3 < __GNUC__ + (4 <= __GNUC_MINOR__)
> # define ignore_value(x) \
> (__extension__ ({ __typeof__ (x) __x = (x); (void) __x; }))
> #else
> # define ignore_value(x) ((void) (x))
> #endif
Casting a value to void is the traditional and obvious way to say "yes,
I mean to ignore this value". Now compilers start to reply "no, you
don't". We can invent new (and less obvious) ways to say "yes, I do",
and compilers can then learn them so they can again reply "no, you
don't". Why have compilers started to behave like two-year-olds?
[...]
- [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Felipe Franciosi, 2016/09/21
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Pavel Dovgalyuk, 2016/09/21
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Markus Armbruster, 2016/09/21
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Felipe Franciosi, 2016/09/21
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Pavel Dovgalyuk, 2016/09/21
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Daniel P. Berrange, 2016/09/21
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Felipe Franciosi, 2016/09/21
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Felipe Franciosi, 2016/09/21
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result,
Markus Armbruster <=
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Eric Blake, 2016/09/21
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Felipe Franciosi, 2016/09/21
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Daniel P. Berrange, 2016/09/21
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Felipe Franciosi, 2016/09/21
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Eric Blake, 2016/09/21
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Markus Armbruster, 2016/09/21
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Eric Blake, 2016/09/21
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Daniel P. Berrange, 2016/09/22
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Markus Armbruster, 2016/09/22
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Eric Blake, 2016/09/22