|
4 | 4 | #define _FILE_OFFSET_BITS 64 |
5 | 5 |
|
6 | 6 | /* |
7 | | - * Derived from Linux "Features Test Macro" header |
8 | | - * Convenience macros to test the versions of gcc (or |
9 | | - * a compatible compiler). |
| 7 | + * Convenience macros to test the versions of GCC (or a compatible compiler). |
10 | 8 | * Use them like this: |
11 | 9 | * #if GIT_GNUC_PREREQ (2,8) |
12 | | - * ... code requiring gcc 2.8 or later ... |
| 10 | + * ... code requiring GCC 2.8 or later ... |
13 | 11 | * #endif |
14 | 12 | * |
| 13 | + * Note that Clang and other compilers define __GNUC__ for compatibility; use |
| 14 | + * GIT_CLANG_PREREQ() to check for specific Clang versions. |
| 15 | + * |
15 | 16 | * This macro of course is not part of POSIX, but we need it for the UNUSED |
16 | 17 | * macro which is used by some of our POSIX compatibility wrappers. |
17 | | -*/ |
| 18 | + */ |
18 | 19 | #if defined(__GNUC__) && defined(__GNUC_MINOR__) |
19 | 20 | # define GIT_GNUC_PREREQ(maj, min) \ |
20 | | - ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) |
| 21 | + ((__GNUC__ > (maj)) || \ |
| 22 | + (__GNUC__ == (maj) && __GNUC_MINOR__ >= (min))) |
| 23 | +#else |
| 24 | +# define GIT_GNUC_PREREQ(maj, min) 0 |
| 25 | +#endif |
| 26 | + |
| 27 | +/* Similar for Clang. */ |
| 28 | +#if defined(__clang__) && defined(__clang_minor__) && defined(__clang_major__) |
| 29 | +# define GIT_CLANG_PREREQ(maj, min) \ |
| 30 | + ((__clang_major__ > (maj)) || \ |
| 31 | + (__clang_major__ == (maj) && __clang_minor__ >= (min))) |
21 | 32 | #else |
22 | | - #define GIT_GNUC_PREREQ(maj, min) 0 |
| 33 | +# define GIT_CLANG_PREREQ(maj, min) 0 |
23 | 34 | #endif |
24 | 35 |
|
25 | 36 | /* |
|
35 | 46 | * When a parameter may be used or unused, depending on conditional |
36 | 47 | * compilation, consider using MAYBE_UNUSED instead. |
37 | 48 | */ |
38 | | -#if GIT_GNUC_PREREQ(4, 5) |
39 | | -#define UNUSED __attribute__((unused)) \ |
40 | | - __attribute__((deprecated ("parameter declared as UNUSED"))) |
| 49 | +#if GIT_GNUC_PREREQ(4, 5) || GIT_CLANG_PREREQ(2, 9) |
| 50 | +# define UNUSED __attribute__((unused)) \ |
| 51 | + __attribute__((deprecated("parameter declared as UNUSED"))) |
41 | 52 | #elif defined(__GNUC__) |
42 | | -#define UNUSED __attribute__((unused)) \ |
| 53 | +# define UNUSED __attribute__((unused)) \ |
43 | 54 | __attribute__((deprecated)) |
44 | 55 | #else |
45 | | -#define UNUSED |
| 56 | +# define UNUSED |
46 | 57 | #endif |
47 | 58 |
|
48 | 59 | #ifdef __MINGW64__ |
|
0 commit comments