util/attr.h: use HAVE___ATTRIBUTE__, not __GNUC__ comparisons
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Tue, 22 Mar 2016 22:16:48 +0000 (11:16 +1300)
committerUri Simchoni <uri@samba.org>
Thu, 24 Mar 2016 14:13:15 +0000 (15:13 +0100)
The comparisons that look like

    #if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 )

fail if __GNUC_MINOR__ is 0.  The intended comparison is something
more like

    #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)

However, given that:

 * these checks are really trying to test the presence of
   __attribute__,

 * there are now credible compilers that are not GCC, which have
   __attribute__ but might not be good at emulating __GNUC__
   numbers, and

 * we really face little risk of running into GCC 2.95

 * we have a HAVE___ATTRIBUTE__ check in ./configure

let's not do the version comparisons.

(Untested on GCC 2.95, GCC 3.0 and GCC 3.1).

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Uri Simchoni <uri@samba.org>
lib/util/attr.h

index b72696a8dc3c8ca515d273b3cc8683c617fa409d..8e542c14da3ce6779599096df5e7e53315773247 100644 (file)
@@ -35,7 +35,7 @@
 #endif
 
 #ifndef _DEPRECATED_
-#if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 )
+#ifdef HAVE___ATTRIBUTE__
 #define _DEPRECATED_ __attribute__ ((deprecated))
 #else
 #define _DEPRECATED_
@@ -43,7 +43,7 @@
 #endif
 
 #ifndef _WARN_UNUSED_RESULT_
-#if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 )
+#ifdef HAVE___ATTRIBUTE__
 #define _WARN_UNUSED_RESULT_ __attribute__ ((warn_unused_result))
 #else
 #define _WARN_UNUSED_RESULT_
@@ -51,7 +51,7 @@
 #endif
 
 #ifndef _NORETURN_
-#if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 )
+#ifdef HAVE___ATTRIBUTE__
 #define _NORETURN_ __attribute__ ((noreturn))
 #else
 #define _NORETURN_
@@ -59,7 +59,7 @@
 #endif
 
 #ifndef _PURE_
-#if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1)
+#ifdef HAVE___ATTRIBUTE__
 #define _PURE_ __attribute__((pure))
 #else
 #define _PURE_
@@ -67,7 +67,7 @@
 #endif
 
 #ifndef NONNULL
-#if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1)
+#ifdef HAVE___ATTRIBUTE__
 #define NONNULL(param) param __attribute__((nonnull))
 #else
 #define NONNULL(param) param
@@ -75,7 +75,7 @@
 #endif
 
 #ifndef PRINTF_ATTRIBUTE
-#if __GNUC__ >= 3
+#ifdef HAVE___ATTRIBUTE__
 /** Use gcc attribute to check printf fns.  a1 is the 1-based index of
  * the parameter containing the format, and a2 the index of the first
  * argument. Note that some gcc 2.x versions don't handle this
 #endif
 
 #ifndef FORMAT_ATTRIBUTE
-#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
+#ifdef HAVE___ATTRIBUTE__
 /** Use gcc attribute to check printf fns.  a1 is argument to format()
  * in the above macro.  This is needed to support Heimdal's printf
  * decorations. Note that some gcc 2.x versions don't handle this
- * properly, and as such I've used the same minimum from heimdal: GCC 3.1 **/
+ * properly. **/
 #define FORMAT_ATTRIBUTE(a) __attribute__ ((format a))
 #else
 #define FORMAT_ATTRIBUTE(a)