X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2FCompiler.h;h=38c008f4bbe66e515d5366788b4493073cc6a382;hb=3af5c3a185fc23b8fb9d528a9c0a14f70093ac70;hp=a3a48118aae3d8b4578085f104c962ce8df2babd;hpb=a90450bc099218c49c122744bbd52f21a0d7bb7c;p=ncmpc.git diff --git a/src/Compiler.h b/src/Compiler.h index a3a4811..38c008f 100644 --- a/src/Compiler.h +++ b/src/Compiler.h @@ -20,10 +20,6 @@ #ifndef COMPILER_H #define COMPILER_H -#define GCC_CHECK_VERSION(major, minor) \ - (defined(__GNUC__) && \ - (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))) - #define GCC_MAKE_VERSION(major, minor, patchlevel) ((major) * 10000 + (minor) * 100 + patchlevel) #ifdef __GNUC__ @@ -38,7 +34,30 @@ # define CLANG_VERSION 0 #endif -#if GCC_CHECK_VERSION(4,0) +/** + * Are we building with the specified version of gcc (not clang or any + * other compiler) or newer? + */ +#define GCC_CHECK_VERSION(major, minor) \ + (!CLANG_VERSION && \ + GCC_VERSION >= GCC_MAKE_VERSION(major, minor, 0)) + +/** + * Are we building with clang (any version) or at least the specified + * gcc version? + */ +#define CLANG_OR_GCC_VERSION(major, minor) \ + (CLANG_VERSION || GCC_CHECK_VERSION(major, minor)) + +/** + * Are we building with gcc (not clang or any other compiler) and a + * version older than the specified one? + */ +#define GCC_OLDER_THAN(major, minor) \ + (GCC_VERSION && !CLANG_VERSION && \ + GCC_VERSION < GCC_MAKE_VERSION(major, minor, 0)) + +#if CLANG_OR_GCC_VERSION(4,0) /* GCC 4.x */ @@ -98,7 +117,7 @@ #endif -#if GCC_CHECK_VERSION(4,3) +#if CLANG_OR_GCC_VERSION(4,3) #define gcc_hot __attribute__((hot)) #define gcc_cold __attribute__((cold)) @@ -110,7 +129,7 @@ #endif /* ! GCC_UNUSED >= 40300 */ -#if GCC_CHECK_VERSION(4,6) && !defined(__clang__) +#if GCC_CHECK_VERSION(4,6) #define gcc_flatten __attribute__((flatten)) #else #define gcc_flatten @@ -119,7 +138,7 @@ #ifndef __cplusplus /* plain C99 has "restrict" */ #define gcc_restrict restrict -#elif GCC_CHECK_VERSION(4,0) +#elif CLANG_OR_GCC_VERSION(4,0) /* "__restrict__" is a GCC extension for C++ */ #define gcc_restrict __restrict__ #else @@ -132,12 +151,12 @@ #if defined(__cplusplus) /* support for C++11 "override" was added in gcc 4.7 */ -#if !defined(__clang__) && !GCC_CHECK_VERSION(4,7) +#if GCC_OLDER_THAN(4,7) #define override #define final #endif -#if defined(__clang__) || GCC_CHECK_VERSION(4,8) +#if CLANG_OR_GCC_VERSION(4,8) #define gcc_alignas(T, fallback) alignas(T) #else #define gcc_alignas(T, fallback) gcc_aligned(fallback)