diff mbox

[1/2] compiler: add ignore_value() macro

Message ID 1474471622-12802-1-git-send-email-felipe@nutanix.com
State New
Headers show

Commit Message

Felipe Franciosi Sept. 21, 2016, 3:27 p.m. UTC
On GCC versions 3.4 and newer, simply using (void) in front of a
function that has been declared with WUR will no longer suppress a
compilation warning. This commit brings the ignore_value() macro from
GNULIB's ignore_value.h, licensed under the terms of LGPLv2+.

See the link below for the original author's comment:
https://lists.nongnu.org/archive/html/qemu-devel/2016-09/msg05148.html

Signed-off-by: Felipe Franciosi <felipe@nutanix.com>
---
 include/qemu/compiler.h | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Eric Blake Sept. 21, 2016, 6:15 p.m. UTC | #1
On 09/21/2016 10:27 AM, Felipe Franciosi wrote:
> On GCC versions 3.4 and newer, simply using (void) in front of a
> function that has been declared with WUR will no longer suppress a
> compilation warning. This commit brings the ignore_value() macro from
> GNULIB's ignore_value.h, licensed under the terms of LGPLv2+.
> 
> See the link below for the original author's comment:
> https://lists.nongnu.org/archive/html/qemu-devel/2016-09/msg05148.html
> 
> Signed-off-by: Felipe Franciosi <felipe@nutanix.com>
> ---
>  include/qemu/compiler.h | 8 ++++++++
>  1 file changed, 8 insertions(+)

Reviewed-by: Eric Blake <eblake@redhat.com>
Felipe Franciosi Oct. 12, 2016, 5:20 p.m. UTC | #2
> On 21 Sep 2016, at 19:15, Eric Blake <eblake@redhat.com> wrote:
> 
> On 09/21/2016 10:27 AM, Felipe Franciosi wrote:
>> On GCC versions 3.4 and newer, simply using (void) in front of a
>> function that has been declared with WUR will no longer suppress a
>> compilation warning. This commit brings the ignore_value() macro from
>> GNULIB's ignore_value.h, licensed under the terms of LGPLv2+.
>> 
>> See the link below for the original author's comment:
>> https://lists.nongnu.org/archive/html/qemu-devel/2016-09/msg05148.html
>> 
>> Signed-off-by: Felipe Franciosi <felipe@nutanix.com>
>> ---
>> include/qemu/compiler.h | 8 ++++++++
>> 1 file changed, 8 insertions(+)
> 
> Reviewed-by: Eric Blake <eblake@redhat.com>
> 
> -- 
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
> 

Hi Eric,

Now that the header and licensing of compiler.h got amended, can we look at this again?

I think the right solution (at least for the moment) is to stick with my series to fix the build.
1/2) We get the ignore_value() macro in.
2/2) We ignore the return value of that fwrite().

As I clarified on my last e-mail in this thread (21/sept), there are many other calls around the replay code which could potentially fail and are all unchecked. We could at least fix the build now and then talk about a separate series to address those, if neccesary.

Thanks,
Felipe
Felipe Franciosi Oct. 25, 2016, 3:21 p.m. UTC | #3
> On 12 Oct 2016, at 18:20, Felipe Franciosi <felipe@nutanix.com> wrote:
> 
> 
>> On 21 Sep 2016, at 19:15, Eric Blake <eblake@redhat.com> wrote:
>> 
>> On 09/21/2016 10:27 AM, Felipe Franciosi wrote:
>>> On GCC versions 3.4 and newer, simply using (void) in front of a
>>> function that has been declared with WUR will no longer suppress a
>>> compilation warning. This commit brings the ignore_value() macro from
>>> GNULIB's ignore_value.h, licensed under the terms of LGPLv2+.
>>> 
>>> See the link below for the original author's comment:
>>> https://lists.nongnu.org/archive/html/qemu-devel/2016-09/msg05148.html
>>> 
>>> Signed-off-by: Felipe Franciosi <felipe@nutanix.com>
>>> ---
>>> include/qemu/compiler.h | 8 ++++++++
>>> 1 file changed, 8 insertions(+)
>> 
>> Reviewed-by: Eric Blake <eblake@redhat.com>
>> 
>> -- 
>> Eric Blake   eblake redhat com    +1-919-301-3266
>> Libvirt virtualization library http://libvirt.org
>> 
> 
> Hi Eric,
> 
> Now that the header and licensing of compiler.h got amended, can we look at this again?
> 
> I think the right solution (at least for the moment) is to stick with my series to fix the build.
> 1/2) We get the ignore_value() macro in.
> 2/2) We ignore the return value of that fwrite().
> 
> As I clarified on my last e-mail in this thread (21/sept), there are many other calls around the replay code which could potentially fail and are all unchecked. We could at least fix the build now and then talk about a separate series to address those, if neccesary.
> 
> Thanks,
> Felipe


Ping?
Eric Blake Nov. 18, 2016, 9:09 p.m. UTC | #4
On 10/25/2016 10:21 AM, Felipe Franciosi wrote:
> 
>> On 12 Oct 2016, at 18:20, Felipe Franciosi <felipe@nutanix.com> wrote:
>>
>>
>>> On 21 Sep 2016, at 19:15, Eric Blake <eblake@redhat.com> wrote:
>>>
>>> On 09/21/2016 10:27 AM, Felipe Franciosi wrote:
>>>> On GCC versions 3.4 and newer, simply using (void) in front of a
>>>> function that has been declared with WUR will no longer suppress a
>>>> compilation warning. This commit brings the ignore_value() macro from
>>>> GNULIB's ignore_value.h, licensed under the terms of LGPLv2+.
>>>>
>>>> See the link below for the original author's comment:
>>>> https://lists.nongnu.org/archive/html/qemu-devel/2016-09/msg05148.html
>>>>
>>>> Signed-off-by: Felipe Franciosi <felipe@nutanix.com>
>>>> ---
>>>> include/qemu/compiler.h | 8 ++++++++
>>>> 1 file changed, 8 insertions(+)
>>>
>>> Reviewed-by: Eric Blake <eblake@redhat.com>
>>>

> 
> Ping?

It's missed 2.8, but I still think it is a useful patch; I just
commented on another thread about a case where a cast-to-void might look
better with the use of ignore_value().
diff mbox

Patch

diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
index 338d3a6..655d0c7 100644
--- a/include/qemu/compiler.h
+++ b/include/qemu/compiler.h
@@ -26,6 +26,14 @@ 
 #define QEMU_WARN_UNUSED_RESULT
 #endif
 
+/* The ignore_value() macro comes from GNULIB's LGPLv2+ ignore-value.h */
+#if QEMU_GNUC_PREREQ(3, 4)
+# define ignore_value(x) \
+         (__extension__ ({ __typeof__ (x) __x = (x); (void) __x; }))
+#else
+# define ignore_value(x) ((void) (x))
+#endif
+
 #if QEMU_GNUC_PREREQ(4, 0)
 #define QEMU_SENTINEL __attribute__((sentinel))
 #else