Skip to content

Commit 75e697c

Browse files
committed
Merge branch 'dl/posix-unused-warning-clang' into jch
* dl/posix-unused-warning-clang: compat/posix.h: simplify GIT_GNUC_PREREQ() comparison compat/posix.h: clean up GIT_GNUC_PREREQ() and UNUSED compat/posix.h: enable UNUSED warning messages for Clang
2 parents 8e66f69 + cf48887 commit 75e697c

1 file changed

Lines changed: 23 additions & 12 deletions

File tree

compat/posix.h

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,33 @@
44
#define _FILE_OFFSET_BITS 64
55

66
/*
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).
108
* Use them like this:
119
* #if GIT_GNUC_PREREQ (2,8)
12-
* ... code requiring gcc 2.8 or later ...
10+
* ... code requiring GCC 2.8 or later ...
1311
* #endif
1412
*
13+
* Note that Clang and other compilers define __GNUC__ for compatibility; use
14+
* GIT_CLANG_PREREQ() to check for specific Clang versions.
15+
*
1516
* This macro of course is not part of POSIX, but we need it for the UNUSED
1617
* macro which is used by some of our POSIX compatibility wrappers.
17-
*/
18+
*/
1819
#if defined(__GNUC__) && defined(__GNUC_MINOR__)
1920
# 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)))
2132
#else
22-
#define GIT_GNUC_PREREQ(maj, min) 0
33+
# define GIT_CLANG_PREREQ(maj, min) 0
2334
#endif
2435

2536
/*
@@ -35,14 +46,14 @@
3546
* When a parameter may be used or unused, depending on conditional
3647
* compilation, consider using MAYBE_UNUSED instead.
3748
*/
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")))
4152
#elif defined(__GNUC__)
42-
#define UNUSED __attribute__((unused)) \
53+
# define UNUSED __attribute__((unused)) \
4354
__attribute__((deprecated))
4455
#else
45-
#define UNUSED
56+
# define UNUSED
4657
#endif
4758

4859
#ifdef __MINGW64__

0 commit comments

Comments
 (0)