[systemd-devel] [RFC] make static_assert() run without warnings
Holger Schurig
holgerschurig at gmail.com
Thu Feb 20 01:35:06 PST 2014
Make C++11 static_assert work without warning by using C99 _Pragma() as well.
---
NOTE: this patch is probably whitespace damaged, because I'm pasting
it in via Google's web interface. I declared this patch as RFC because
I'm unsure how clang behaves on it.
Index: systemd-test/src/shared/macro.h
===================================================================
--- systemd-test.orig/src/shared/macro.h 2014-02-20 10:09:53.300892884 +0100
+++ systemd-test/src/shared/macro.h 2014-02-20 10:20:25.656892808 +0100
@@ -156,7 +156,12 @@ static inline size_t ALIGN_TO(size_t l,
#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) 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) \
More information about the systemd-devel
mailing list