Received: from eggs.gnu.org ([2001:4830:134:3::10]:55304) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bmggh-0006zQ-Tc for qemu-devel@nongnu.org; Wed, 21 Sep 2016 08:31:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bmgge-0003FX-Ls for qemu-devel@nongnu.org; Wed, 21 Sep 2016 08:31:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50074) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bmgge-0003Ez-CK for qemu-devel@nongnu.org; Wed, 21 Sep 2016 08:31:40 -0400 From: Markus Armbruster References: <1474391326-871-1-git-send-email-felipe@nutanix.com> <000301d213c7$7142f980$53c8ec80$@ru> <87y42l93dr.fsf@dusky.pond.sub.org> <20160921100718.GO15535@redhat.com> Date: Wed, 21 Sep 2016 14:31:36 +0200 In-Reply-To: <20160921100718.GO15535@redhat.com> (Daniel P. Berrange's message of "Wed, 21 Sep 2016 11:07:18 +0100") Message-ID: <87mvj11ljr.fsf@dusky.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" Cc: Felipe Franciosi , Pavel Dovgalyuk , Pavel Dovgalyuk , qemu-devel "Daniel P. Berrange" writes: > On Wed, Sep 21, 2016 at 10:00:23AM +0000, Felipe Franciosi wrote: >> >> > On 21 Sep 2016, at 07:24, Markus Armbruster wrote: >> > >> > "Pavel Dovgalyuk" writes: >> > >> >>> From: Felipe Franciosi [mailto:felipe@nutanix.com] >> >>> 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 >> >>> --- >> >>> 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? [...]