1From 6ef0094fa931b86c42125a8ee357b2f0e3156254 Mon Sep 17 00:00:00 2001 2From: Florian Weimer <fweimer@redhat.com> 3Date: Thu, 7 Feb 2019 09:03:02 +0100 4Subject: [PATCH 01/20] array_length: Make usable as a constant expression 5 6Do not use a statement expression in array_length, so that 7array_length can be used at file scope and as a constant expression. 8Instead, put the _Static_assert into a struct (as a declaration), 9and nest this in the expression using a sizeof expression. 10 11(cherry picked from commit 8311c83f91a3127ccd2fe684e25bc60c5178d23b) 12Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com> 13--- 14 include/array_length.h | 12 ++++++------ 15 1 file changed, 6 insertions(+), 6 deletions(-) 16 17diff --git a/include/array_length.h b/include/array_length.h 18index 94bf2b2d..29087a7d 100644 19--- a/include/array_length.h 20+++ b/include/array_length.h 21@@ -22,12 +22,12 @@ 22 /* array_length (VAR) is the number of elements in the array VAR. VAR 23 must evaluate to an array, not a pointer. */ 24 #define array_length(var) \ 25- __extension__ ({ \ 26- _Static_assert (!__builtin_types_compatible_p \ 27- (__typeof (var), __typeof (&(var)[0])), \ 28- "argument must be an array"); \ 29- sizeof (var) / sizeof ((var)[0]); \ 30- }) 31+ (sizeof (var) / sizeof ((var)[0]) \ 32+ + 0 * sizeof (struct { \ 33+ _Static_assert (!__builtin_types_compatible_p \ 34+ (__typeof (var), __typeof (&(var)[0])), \ 35+ "argument must be an array"); \ 36+ })) 37 38 /* array_end (VAR) is a pointer one past the end of the array VAR. 39 VAR must evaluate to an array, not a pointer. */ 40-- 412.20.1 42 43