From: Björn Jacke Date: Sun, 24 May 2020 11:57:46 +0000 (+0200) Subject: replace, attr.: use function attributes only if supported by feature macro (or old... X-Git-Tag: ldb-2.2.0~352 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f133019db60afb0fea997dd6350a9376a91806d3;p=thirdparty%2Fsamba.git replace, attr.: use function attributes only if supported by feature macro (or old gcc) BUG: https://bugzilla.samba.org/show_bug.cgi?id=12296 Signed-off-by: Bjoern Jacke Reviewed-by: Andrew Bartlett --- diff --git a/lib/replace/replace.h b/lib/replace/replace.h index 59f0b60f8a0..6c78311f2d3 100644 --- a/lib/replace/replace.h +++ b/lib/replace/replace.h @@ -447,8 +447,13 @@ int rep_dlclose(void *handle); /* prototype is in system/network.h */ #endif +/* for old gcc releases that don't have the feature test macro __has_attribute */ +#ifndef __has_attribute +#define __has_attribute(x) 0 +#endif + #ifndef PRINTF_ATTRIBUTE -#ifdef HAVE___ATTRIBUTE__ +#if __has_attribute(format) || (__GNUC__ >= 3) /** 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 diff --git a/lib/util/attr.h b/lib/util/attr.h index 8e542c14da3..af3e2442b3a 100644 --- a/lib/util/attr.h +++ b/lib/util/attr.h @@ -20,14 +20,18 @@ #ifndef __UTIL_ATTR_H__ #define __UTIL_ATTR_H__ +/* for old gcc releases that don't have the feature test macro __has_attribute */ +#ifndef __has_attribute +#define __has_attribute(x) 0 +#endif + #ifndef _UNUSED_ -#ifdef __GNUC__ +#if __has_attribute(unused) || ( (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 ) ) /** gcc attribute used on function parameters so that it does not emit * warnings about them being unused. **/ # define _UNUSED_ __attribute__ ((unused)) #else # define _UNUSED_ -/** Feel free to add definitions for other compilers here. */ #endif #endif #ifndef UNUSED @@ -35,7 +39,7 @@ #endif #ifndef _DEPRECATED_ -#ifdef HAVE___ATTRIBUTE__ +#if __has_attribute(deprecated) || ( (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 ) ) #define _DEPRECATED_ __attribute__ ((deprecated)) #else #define _DEPRECATED_ @@ -43,7 +47,7 @@ #endif #ifndef _WARN_UNUSED_RESULT_ -#ifdef HAVE___ATTRIBUTE__ +#if __has_attribute(warn_unused_result) || ( (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 ) ) #define _WARN_UNUSED_RESULT_ __attribute__ ((warn_unused_result)) #else #define _WARN_UNUSED_RESULT_ @@ -51,7 +55,7 @@ #endif #ifndef _NORETURN_ -#ifdef HAVE___ATTRIBUTE__ +#if __has_attribute(noreturn) || ( (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 ) ) #define _NORETURN_ __attribute__ ((noreturn)) #else #define _NORETURN_ @@ -59,7 +63,7 @@ #endif #ifndef _PURE_ -#ifdef HAVE___ATTRIBUTE__ +#if __has_attribute(pure) || ( (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 ) ) #define _PURE_ __attribute__((pure)) #else #define _PURE_ @@ -67,7 +71,7 @@ #endif #ifndef NONNULL -#ifdef HAVE___ATTRIBUTE__ +#if __has_attribute(nonnull) || ( (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 ) ) #define NONNULL(param) param __attribute__((nonnull)) #else #define NONNULL(param) param @@ -75,7 +79,7 @@ #endif #ifndef PRINTF_ATTRIBUTE -#ifdef HAVE___ATTRIBUTE__ +#if __has_attribute(format) || ( (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 ) ) /** 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 @@ -87,7 +91,7 @@ #endif #ifndef FORMAT_ATTRIBUTE -#ifdef HAVE___ATTRIBUTE__ +#if __has_attribute(format) || ( (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 ) ) /** 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