From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45159) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bmi0C-00011Y-89 for qemu-devel@nongnu.org; Wed, 21 Sep 2016 09:55:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bmi07-00046l-8H for qemu-devel@nongnu.org; Wed, 21 Sep 2016 09:55:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58558) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bmi06-00046f-US for qemu-devel@nongnu.org; Wed, 21 Sep 2016 09:55:51 -0400 References: <1474391326-871-1-git-send-email-felipe@nutanix.com> <000301d213c7$7142f980$53c8ec80$@ru> <87y42l93dr.fsf@dusky.pond.sub.org> <20160921100718.GO15535@redhat.com> <87mvj11ljr.fsf@dusky.pond.sub.org> From: Eric Blake Message-ID: Date: Wed, 21 Sep 2016 08:55:47 -0500 MIME-Version: 1.0 In-Reply-To: <87mvj11ljr.fsf@dusky.pond.sub.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="k3GLqiXKra9PCs3Uk6OK6mhCKPeGHJiLq" 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: Markus Armbruster , "Daniel P. Berrange" Cc: Pavel Dovgalyuk , qemu-devel , Pavel Dovgalyuk , Felipe Franciosi This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --k3GLqiXKra9PCs3Uk6OK6mhCKPeGHJiLq From: Eric Blake To: Markus Armbruster , "Daniel P. Berrange" Cc: Pavel Dovgalyuk , qemu-devel , Pavel Dovgalyuk , Felipe Franciosi Message-ID: Subject: Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result References: <1474391326-871-1-git-send-email-felipe@nutanix.com> <000301d213c7$7142f980$53c8ec80$@ru> <87y42l93dr.fsf@dusky.pond.sub.org> <20160921100718.GO15535@redhat.com> <87mvj11ljr.fsf@dusky.pond.sub.org> In-Reply-To: <87mvj11ljr.fsf@dusky.pond.sub.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 09/21/2016 07:31 AM, Markus Armbruster wrote: >> >> 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 <=3D __GNUC_MINOR__) >> # define ignore_value(x) \ >> (__extension__ ({ __typeof__ (x) __x =3D (x); (void) __x; })) >> #else >> # define ignore_value(x) ((void) (x)) >> #endif >=20 > 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? gcc has been doing the "__warn_unused_value__ means cast-to-void is insufficient" complaint for years (since at least 2008, per the gnulib history). But the gnulib workaround has also been effectively silencing it for years (it was actually my work in 2011, commit 939dedd, which came up with the form listed above). The other nice thing about "ignore_value(wur_function())" is that you are avoiding a cast in your local code, and the burden of shutting up the annoying compiler is hidden behind a macro that can easily be changed to affect all clients of the macro, should gcc regress yet again and we need some other formula to shut it up. And yes, the gnulib mailing list has threads complaining about gcc's behavior back when the macro had to be invented, and again when glibc added wur markings to functions that can legitimately be ignored (fread() is one of them; because there are valid programming paradigms where you check ferror() later on rather than having to check every intermediate fread(), at the expense of less-specific error messages). --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --k3GLqiXKra9PCs3Uk6OK6mhCKPeGHJiLq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJX4pFjAAoJEKeha0olJ0Nqq7wIAIwmaQbJkVODevQ5op6Xy09q E6Mcz2xraiBgX9rAyfG40JnSEOUWq6xeOZMHMtPL1k6LwWy96Oalm+5XGG0WS+aR EGguM0QwA2DOxpmECtExlFqM1XLpcUhLGzwMUof5ZB0g56k37yYL2RKYTe67168d tu/zED0yucK6iSJVaV1wq5psGo+ZX4LasTe9prmowboHwmoMS9t9plktq9ezxgd9 XYMLuC0OFvFdnDFC9skKCnX9mViFvC7PEhYIA+EpqvFIExd8zNgwn18GHJJlKU3k qm0XBnsYxccAk18+3PAvtgLGTbINSiPIdumIYg6gMJccf5Jj2/amQf8E6jix36s= =tH36 -----END PGP SIGNATURE----- --k3GLqiXKra9PCs3Uk6OK6mhCKPeGHJiLq--