[systemd-devel] [PATCH] Remove static_assert related warnings

Holger Schurig holgerschurig at gmail.com
Thu Feb 20 05:38:40 PST 2014


Make macro assert_cc() not emit "declaration after statements" warnings.

This can be done by using the GCC pragmas 'diagnostic ignore "undefined"'.
In order to be able to use that pragma inside a macro, we need to put it
into the (C99-introduced) _Pragma() pseudo-function.
---
 src/shared/macro.h |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/shared/macro.h b/src/shared/macro.h
index dfbc201..f93a4f0 100644
--- a/src/shared/macro.h
+++ b/src/shared/macro.h
@@ -156,7 +156,11 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) {
 #if defined(static_assert)
 #define assert_cc(expr) static_assert(expr, #expr)
 #else
-#define assert_cc(expr) struct UNIQUE(_assert_struct_) { char x[(expr) ? 0 : -1]; };
+#define assert_cc(expr) \
+ _Pragma("GCC diagnostic push"); \
+ _Pragma("GCC diagnostic ignored \"-Wdeclaration-after-statement\""); \
+ struct UNIQUE(_assert_struct_) { char x[(expr) ? 0 : -1]; }; \
+ _Pragma("GCC diagnostic pop");
 #endif
 
 #define assert_return(expr, r)                                          \
-- 
1.7.10.4



More information about the systemd-devel mailing list