Fix definition of ARRAY_SIZE for non-gcc builds

The improved ARRAY_SIZE macro uses BARF_UNLESS_AN_ARRAY which expands to a valid check for recent gcc versions and to 0 for older gcc versions but is not defined on non-gcc builds. Non-gcc builds need this macro to expand to 0 as well. The current outer test (defined(__GNUC__) && (__GNUC__ >= 3)) is a strictly weaker condition than the inner test (GIT_GNUC_PREREQ(3, 1)) so we can omit the outer test and cause the BARF_UNLESS_AN_ARRAY macro to be defined correctly on non-gcc builds as well as gcc builds with older versions. Signed-off-by: Charles Bailey <cbailey32@bloomberg.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Charles Bailey committed Jun 24, 2015 at 23:12 UTC e2c6f7cd5a66ed0009662d2651e0cf3c655e83a9
1 file changed +3 -5
git-compat-util.h
+3 -5
@@ -58,15 +58,13 @@
58 #define BUILD_ASSERT_OR_ZERO(cond) \
59 (sizeof(char [1 - 2*!(cond)]) - 1)
60
61 -#if defined(__GNUC__) && (__GNUC__ >= 3)
62 -# if GIT_GNUC_PREREQ(3, 1)
61 +#if GIT_GNUC_PREREQ(3, 1)
62 /* &arr[0] degrades to a pointer: a different type from an array */
63 # define BARF_UNLESS_AN_ARRAY(arr) \
64 BUILD_ASSERT_OR_ZERO(!__builtin_types_compatible_p(__typeof__(arr), \
65 __typeof__(&(arr)[0])))
67 -# else
68 -# define BARF_UNLESS_AN_ARRAY(arr) 0
69 -# endif
66 +#else
67 +# define BARF_UNLESS_AN_ARRAY(arr) 0
68 #endif
69 /*
70 * ARRAY_SIZE - get the number of elements in a visible array