gmacros.h: use G_GNUC_CHECK_VERSION

Remove repeated `__GNUC__ > ... || (__GNUC__ == ... && __GNUC_MINOR__ >= ...)`.

Also effectively adds (missing?) `defined(__GNUC__)` check before
`__GNUC__ > ...` in a few places.
This commit is contained in:
Aleksandr Mezin 2021-04-07 22:17:26 +06:00
parent 0ab4ed5306
commit 2539d70d40

View File

@ -50,7 +50,7 @@
* where this is valid. This allows for warningless compilation of * where this is valid. This allows for warningless compilation of
* "long long" types even in the presence of '-ansi -pedantic'. * "long long" types even in the presence of '-ansi -pedantic'.
*/ */
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8) #if G_GNUC_CHECK_VERSION(2, 8)
#define G_GNUC_EXTENSION __extension__ #define G_GNUC_EXTENSION __extension__
#else #else
#define G_GNUC_EXTENSION #define G_GNUC_EXTENSION
@ -189,7 +189,7 @@
* Since: 2.58 * Since: 2.58
*/ */
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) #if G_GNUC_CHECK_VERSION(2, 96)
#define G_GNUC_PURE __attribute__((__pure__)) #define G_GNUC_PURE __attribute__((__pure__))
#define G_GNUC_MALLOC __attribute__((__malloc__)) #define G_GNUC_MALLOC __attribute__((__malloc__))
#define G_GNUC_NO_INLINE __attribute__((noinline)) #define G_GNUC_NO_INLINE __attribute__((noinline))
@ -218,7 +218,7 @@
* *
* Since: 2.8 * Since: 2.8
*/ */
#if __GNUC__ >= 4 #if G_GNUC_CHECK_VERSION(4, 0)
#define G_GNUC_NULL_TERMINATED __attribute__((__sentinel__)) #define G_GNUC_NULL_TERMINATED __attribute__((__sentinel__))
#else #else
#define G_GNUC_NULL_TERMINATED #define G_GNUC_NULL_TERMINATED
@ -232,9 +232,7 @@
* This symbol is private. * This symbol is private.
*/ */
#undef glib_typeof #undef glib_typeof
#if !defined(__cplusplus) && \ #if !defined(__cplusplus) && (G_GNUC_CHECK_VERSION(4, 8) || defined(__clang__))
((defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))) || \
defined(__clang__))
#define glib_typeof(t) __typeof__ (t) #define glib_typeof(t) __typeof__ (t)
#elif defined(__cplusplus) && __cplusplus >= 201103L #elif defined(__cplusplus) && __cplusplus >= 201103L
/* C++11 decltype() is close enough for our usage */ /* C++11 decltype() is close enough for our usage */
@ -325,8 +323,8 @@
* *
* Since: 2.18 * Since: 2.18
*/ */
#if (!defined(__clang__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) || \ #if (!defined(__clang__) && G_GNUC_CHECK_VERSION(4, 3)) || \
(defined(__clang__) && g_macro__has_attribute(__alloc_size__)) (defined(__clang__) && g_macro__has_attribute(__alloc_size__))
#define G_GNUC_ALLOC_SIZE(x) __attribute__((__alloc_size__(x))) #define G_GNUC_ALLOC_SIZE(x) __attribute__((__alloc_size__(x)))
#define G_GNUC_ALLOC_SIZE2(x,y) __attribute__((__alloc_size__(x,y))) #define G_GNUC_ALLOC_SIZE2(x,y) __attribute__((__alloc_size__(x,y)))
#else #else
@ -512,7 +510,7 @@
* See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-no_005finstrument_005ffunction-function-attribute) for more details. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-no_005finstrument_005ffunction-function-attribute) for more details.
*/ */
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) #if G_GNUC_CHECK_VERSION(2, 4)
#if !defined (__clang__) && G_GNUC_CHECK_VERSION (4, 4) #if !defined (__clang__) && G_GNUC_CHECK_VERSION (4, 4)
#define G_GNUC_PRINTF( format_idx, arg_idx ) \ #define G_GNUC_PRINTF( format_idx, arg_idx ) \
__attribute__((__format__ (gnu_printf, format_idx, arg_idx))) __attribute__((__format__ (gnu_printf, format_idx, arg_idx)))
@ -581,7 +579,7 @@
* *
* Since: 2.60 * Since: 2.60
*/ */
#if __GNUC__ > 6 #if G_GNUC_CHECK_VERSION(6, 0)
#define G_GNUC_FALLTHROUGH __attribute__((fallthrough)) #define G_GNUC_FALLTHROUGH __attribute__((fallthrough))
#elif g_macro__has_attribute (fallthrough) #elif g_macro__has_attribute (fallthrough)
#define G_GNUC_FALLTHROUGH __attribute__((fallthrough)) #define G_GNUC_FALLTHROUGH __attribute__((fallthrough))
@ -607,7 +605,7 @@
* *
* Since: 2.2 * Since: 2.2
*/ */
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || defined (__clang__) #if G_GNUC_CHECK_VERSION(3, 1) || defined(__clang__)
#define G_GNUC_DEPRECATED __attribute__((__deprecated__)) #define G_GNUC_DEPRECATED __attribute__((__deprecated__))
#else #else
#define G_GNUC_DEPRECATED #define G_GNUC_DEPRECATED
@ -636,7 +634,7 @@
* *
* Since: 2.26 * Since: 2.26
*/ */
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) || defined (__clang__) #if G_GNUC_CHECK_VERSION(4, 5) || defined(__clang__)
#define G_GNUC_DEPRECATED_FOR(f) \ #define G_GNUC_DEPRECATED_FOR(f) \
__attribute__((deprecated("Use " #f " instead"))) __attribute__((deprecated("Use " #f " instead")))
#else #else
@ -649,7 +647,7 @@
_Pragma ("warning (disable:1478)") _Pragma ("warning (disable:1478)")
#define G_GNUC_END_IGNORE_DEPRECATIONS \ #define G_GNUC_END_IGNORE_DEPRECATIONS \
_Pragma ("warning (pop)") _Pragma ("warning (pop)")
#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) #elif G_GNUC_CHECK_VERSION(4, 6)
#define G_GNUC_BEGIN_IGNORE_DEPRECATIONS \ #define G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
_Pragma ("GCC diagnostic push") \ _Pragma ("GCC diagnostic push") \
_Pragma ("GCC diagnostic ignored \"-Wdeprecated-declarations\"") _Pragma ("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
@ -683,7 +681,7 @@
* *
* Since: 2.14 * Since: 2.14
*/ */
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) #if G_GNUC_CHECK_VERSION(3, 3)
#define G_GNUC_MAY_ALIAS __attribute__((may_alias)) #define G_GNUC_MAY_ALIAS __attribute__((may_alias))
#else #else
#define G_GNUC_MAY_ALIAS #define G_GNUC_MAY_ALIAS
@ -707,7 +705,7 @@
* *
* Since: 2.10 * Since: 2.10
*/ */
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) #if G_GNUC_CHECK_VERSION(3, 4)
#define G_GNUC_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) #define G_GNUC_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#else #else
#define G_GNUC_WARN_UNUSED_RESULT #define G_GNUC_WARN_UNUSED_RESULT
@ -855,7 +853,7 @@
* fields through their offsets. * fields through their offsets.
*/ */
#if (defined(__GNUC__) && __GNUC__ >= 4) || defined (_MSC_VER) #if G_GNUC_CHECK_VERSION(4, 0) || defined(_MSC_VER)
#define G_STRUCT_OFFSET(struct_type, member) \ #define G_STRUCT_OFFSET(struct_type, member) \
((glong) offsetof (struct_type, member)) ((glong) offsetof (struct_type, member))
#else #else
@ -963,7 +961,7 @@
* evaluated when a header is included. This results in warnings in third party * evaluated when a header is included. This results in warnings in third party
* code which includes glib.h, even if the third party code doesnt use the new * code which includes glib.h, even if the third party code doesnt use the new
* macro itself. */ * macro itself. */
#if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__)) || (0x5110 <= __SUNPRO_C) #if G_GNUC_CHECK_VERSION(2, 8) || (0x5110 <= __SUNPRO_C)
/* For compatibility with G_NORETURN_FUNCPTR on clang, use /* For compatibility with G_NORETURN_FUNCPTR on clang, use
__attribute__((__noreturn__)), not _Noreturn. */ __attribute__((__noreturn__)), not _Noreturn. */
# define G_NORETURN __attribute__ ((__noreturn__)) # define G_NORETURN __attribute__ ((__noreturn__))
@ -1002,7 +1000,7 @@
* *
* Since: 2.68 * Since: 2.68
*/ */
#if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__)) || (0x5110 <= __SUNPRO_C) #if G_GNUC_CHECK_VERSION(2, 8) || (0x5110 <= __SUNPRO_C)
# define G_NORETURN_FUNCPTR __attribute__ ((__noreturn__)) \ # define G_NORETURN_FUNCPTR __attribute__ ((__noreturn__)) \
GLIB_AVAILABLE_MACRO_IN_2_68 GLIB_AVAILABLE_MACRO_IN_2_68
#else #else
@ -1018,7 +1016,7 @@
* The _G_BOOLEAN_EXPR macro is intended to trigger a gcc warning when * The _G_BOOLEAN_EXPR macro is intended to trigger a gcc warning when
* putting assignments in g_return_if_fail (). * putting assignments in g_return_if_fail ().
*/ */
#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) #if G_GNUC_CHECK_VERSION(2, 0) && defined(__OPTIMIZE__)
#define _G_BOOLEAN_EXPR(expr) \ #define _G_BOOLEAN_EXPR(expr) \
G_GNUC_EXTENSION ({ \ G_GNUC_EXTENSION ({ \
int _g_boolean_var_; \ int _g_boolean_var_; \
@ -1035,7 +1033,7 @@
#define G_UNLIKELY(expr) (expr) #define G_UNLIKELY(expr) (expr)
#endif #endif
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || defined (__clang__) #if G_GNUC_CHECK_VERSION(3, 1) || defined(__clang__)
#define G_DEPRECATED __attribute__((__deprecated__)) #define G_DEPRECATED __attribute__((__deprecated__))
#elif defined(_MSC_VER) && (_MSC_VER >= 1300) #elif defined(_MSC_VER) && (_MSC_VER >= 1300)
#define G_DEPRECATED __declspec(deprecated) #define G_DEPRECATED __declspec(deprecated)
@ -1043,7 +1041,7 @@
#define G_DEPRECATED #define G_DEPRECATED
#endif #endif
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) || defined (__clang__) #if G_GNUC_CHECK_VERSION(4, 5) || defined(__clang__)
#define G_DEPRECATED_FOR(f) __attribute__((__deprecated__("Use '" #f "' instead"))) #define G_DEPRECATED_FOR(f) __attribute__((__deprecated__("Use '" #f "' instead")))
#elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320) #elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320)
#define G_DEPRECATED_FOR(f) __declspec(deprecated("is deprecated. Use '" #f "' instead")) #define G_DEPRECATED_FOR(f) __declspec(deprecated("is deprecated. Use '" #f "' instead"))
@ -1051,7 +1049,7 @@
#define G_DEPRECATED_FOR(f) G_DEPRECATED #define G_DEPRECATED_FOR(f) G_DEPRECATED
#endif #endif
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) || defined (__clang__) #if G_GNUC_CHECK_VERSION(4, 5) || defined(__clang__)
#define G_UNAVAILABLE(maj,min) __attribute__((deprecated("Not available before " #maj "." #min))) #define G_UNAVAILABLE(maj,min) __attribute__((deprecated("Not available before " #maj "." #min)))
#elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320) #elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320)
#define G_UNAVAILABLE(maj,min) __declspec(deprecated("is not available before " #maj "." #min)) #define G_UNAVAILABLE(maj,min) __declspec(deprecated("is not available before " #maj "." #min))
@ -1082,7 +1080,7 @@
#endif #endif
#if !defined(GLIB_DISABLE_DEPRECATION_WARNINGS) && \ #if !defined(GLIB_DISABLE_DEPRECATION_WARNINGS) && \
(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || \ (G_GNUC_CHECK_VERSION(4, 6) || \
__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 4)) __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 4))
#define _GLIB_GNUC_DO_PRAGMA(x) _Pragma(G_STRINGIFY (x)) #define _GLIB_GNUC_DO_PRAGMA(x) _Pragma(G_STRINGIFY (x))
#define GLIB_DEPRECATED_MACRO _GLIB_GNUC_DO_PRAGMA(GCC warning "Deprecated pre-processor symbol") #define GLIB_DEPRECATED_MACRO _GLIB_GNUC_DO_PRAGMA(GCC warning "Deprecated pre-processor symbol")
@ -1095,7 +1093,7 @@
#endif #endif
#if !defined(GLIB_DISABLE_DEPRECATION_WARNINGS) && \ #if !defined(GLIB_DISABLE_DEPRECATION_WARNINGS) && \
((defined (__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1))) || \ (G_GNUC_CHECK_VERSION(6, 1) || \
(defined (__clang_major__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 0)))) (defined (__clang_major__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 0))))
#define GLIB_DEPRECATED_ENUMERATOR G_DEPRECATED #define GLIB_DEPRECATED_ENUMERATOR G_DEPRECATED
#define GLIB_DEPRECATED_ENUMERATOR_FOR(f) G_DEPRECATED_FOR(f) #define GLIB_DEPRECATED_ENUMERATOR_FOR(f) G_DEPRECATED_FOR(f)
@ -1107,7 +1105,7 @@
#endif #endif
#if !defined(GLIB_DISABLE_DEPRECATION_WARNINGS) && \ #if !defined(GLIB_DISABLE_DEPRECATION_WARNINGS) && \
((defined (__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))) || \ (G_GNUC_CHECK_VERSION(3, 1) || \
(defined (__clang_major__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 0)))) (defined (__clang_major__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 0))))
#define GLIB_DEPRECATED_TYPE G_DEPRECATED #define GLIB_DEPRECATED_TYPE G_DEPRECATED
#define GLIB_DEPRECATED_TYPE_FOR(f) G_DEPRECATED_FOR(f) #define GLIB_DEPRECATED_TYPE_FOR(f) G_DEPRECATED_FOR(f)