Tautological comparison in gcc 6.1.1

Michael Adam obnox at samba.org
Wed Jul 13 11:08:40 UTC 2016


On 2016-07-13 at 21:57 +1200, Andrew Bartlett wrote:
> On Wed, 2016-07-13 at 14:21 +1000, Amitay Isaacs wrote:
> 
> > Reviewed-by: me.
> > 
> > Let's wait and see if anyone has a better idea.
> > 
> > Amitay.
> 
> Build some files with -Wno-tautological-compare?
> 
> The problem with the solutions I've seen proposed is that they just
> wait for the compiler to get smarter, or the -O level to be raised, and
> then we are back where we started.  It also makes elegant code less
> -elegant.

All agreed.
I just did not know how to do it more elegantly before,
since these are header files...

Ira gave me the hint to consider using "#pragma GCC diagnostic".
Thanks!

The attached patch lets me build successfully with gcc6 and
older gcc. Maybe we should use ignore instead of warning here
to silence the build a little?

Cheers - Michael
-------------- next part --------------
From aa73e47fcaca11a549a3b65e84c6ec8f943bc8ad Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Wed, 13 Jul 2016 12:35:13 +0200
Subject: [PATCH 1/3] lib:dlinklist: avoid -Wtautological-compare errors with
 gcc6

Thanks to Ira Cooper <ira at wakeful.net> for the hint with #pragma.

Signed-off-by: Michael Adam <obnox at samba.org>
---
 lib/util/dlinklist.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lib/util/dlinklist.h b/lib/util/dlinklist.h
index 8a1b84d..600df4c 100644
--- a/lib/util/dlinklist.h
+++ b/lib/util/dlinklist.h
@@ -55,6 +55,10 @@
   O(1) time
  */
 
+#pragma GCC diagnostic push
+#if (__GNUC__ >= 6)
+#pragma GCC diagnostic warning "-Wtautological-compare"
+#endif /* __GNUC >= 6 */
 
 /*
    add an element at the front of a list
@@ -171,4 +175,6 @@ do { \
 	} \
 } while (0)
 
+#pragma GCC diagnostic push
+
 #endif /* _DLINKLIST_H */
-- 
2.5.5


From 1500245310ed27e95718aafb3db853e356f799f6 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Wed, 13 Jul 2016 12:36:21 +0200
Subject: [PATCH 2/3] tevent: avoid -Wtautological-compare errors with gcc6

Thanks to Ira Cooper <ira at wakeful.net> for the hint with #pragma.

Signed-off-by: Michael Adam <obnox at samba.org>
---
 lib/tevent/tevent_util.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lib/tevent/tevent_util.h b/lib/tevent/tevent_util.h
index e2cdbb8..987da82 100644
--- a/lib/tevent/tevent_util.h
+++ b/lib/tevent/tevent_util.h
@@ -55,6 +55,10 @@
   O(1) time
  */
 
+#pragma GCC diagnostic push
+#if (__GNUC__ >= 6)
+#pragma GCC diagnostic warning "-Wtautological-compare"
+#endif /* __GNUC__ >= 6 */
 
 /*
    add an element at the front of a list
@@ -171,6 +175,8 @@ do { \
 	} \
 } while (0)
 
+#pragma GCC diagnostic push
+
 #endif /* _DLINKLIST_H */
 
 const char **ev_str_list_add(const char **list, const char *s);
-- 
2.5.5


From e408f745d3e70532cf2a4936c89a9b28e4c4d2ce Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Wed, 13 Jul 2016 12:37:19 +0200
Subject: [PATCH 3/3] ldb:dlinklist: avoid -Wtautological-compare errors with
 gcc6

Thanks to Ira Cooper <ira at wakeful.net> for the hint with #pragma.

Signed-off-by: Michael Adam <obnox at samba.org>
---
 lib/ldb/include/dlinklist.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lib/ldb/include/dlinklist.h b/lib/ldb/include/dlinklist.h
index ef01aec..0c0decf 100644
--- a/lib/ldb/include/dlinklist.h
+++ b/lib/ldb/include/dlinklist.h
@@ -59,6 +59,10 @@
   O(1) time
  */
 
+#pragma GCC diagnostic push
+#if (__GNUC__ >= 6)
+#pragma GCC diagnostic warning "-Wtautological-compare"
+#endif /* __GNUC__ >= 6 */
 
 /*
    add an element at the front of a list
@@ -175,4 +179,6 @@ do { \
 	} \
 } while (0)
 
+#pragma GCC diagnostic push
+
 #endif /* _DLINKLIST_H */
-- 
2.5.5

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20160713/df41e4ee/signature.sig>


More information about the samba-technical mailing list