diff --git a/glib/gmacros.h b/glib/gmacros.h
index b07eba7..7957755 100644
--- a/glib/gmacros.h
+++ b/glib/gmacros.h
@@ -156,14 +156,27 @@
 #define	G_STRINGIFY_ARG(contents)	#contents
 
 #ifndef __GI_SCANNER__ /* The static assert macro really confuses the introspection parser */
-#define G_PASTE_ARGS(identifier1,identifier2) identifier1 ## identifier2
-#define G_PASTE(identifier1,identifier2)      G_PASTE_ARGS (identifier1, identifier2)
-#ifdef __COUNTER__
-#define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1]
-#else
-#define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __LINE__)[(expr) ? 1 : -1]
-#endif
-#define G_STATIC_ASSERT_EXPR(expr) ((void) sizeof (char[(expr) ? 1 : -1]))
+#  define G_PASTE_ARGS(identifier1,identifier2) identifier1 ## identifier2
+#  define G_PASTE(identifier1,identifier2)      G_PASTE_ARGS (identifier1, identifier2)
+#  if defined(__GNUC__)
+#    define G_ATTRIBUTE_UNUSED __attribute__((unused))
+#  else /* !__GNUC__ */
+#    define G_ATTRIBUTE_UNUSED
+#  endif /* __GNUC___*/
+#  if defined(__cplusplus) && __cplusplus >= 201103
+#    define G_STATIC_ASSERT(expr) static_assert(expr, "G_STATIC_ASSERT(" #expr ")")
+#    define G_STATIC_ASSERT2(expr,message) static_assert(expr, message)
+#  elif defined(__GNUC__) && __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) && !defined(__cplusplus)
+#    define G_STATIC_ASSERT(expr) _Static_assert(expr, "G_STATIC_ASSERT(" #expr ")")
+#    define G_STATIC_ASSERT2(expr,message) _Static_assert(expr, message)
+#  elif defined(__COUNTER__)
+#    define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1] G_ATTRIBUTE_UNUSED
+#    define G_STATIC_ASSERT2(expr,message) G_STATIC_ASSERT(expr)
+#  else
+#    define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __LINE__)[(expr) ? 1 : -1] G_ATTRIBUTE_UNUSED
+#    define G_STATIC_ASSERT2(expr,message) G_STATIC_ASSERT(expr)
+#  endif
+#  define G_STATIC_ASSERT_EXPR(expr) ((void) sizeof (char[(expr) ? 1 : -1]))
 #endif
 
 /* Provide a string identifying the current code position */
