mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-13 15:56:23 +01:00
Merge branch 'nirbheek/static-assert-try-2' into 'master'
gmacros: Use _Static_assert only for non-expr static assert See merge request GNOME/glib!962
This commit is contained in:
commit
a656555f76
@ -734,13 +734,19 @@
|
|||||||
#ifndef __GI_SCANNER__ /* The static assert macro really confuses the introspection parser */
|
#ifndef __GI_SCANNER__ /* The static assert macro really confuses the introspection parser */
|
||||||
#define G_PASTE_ARGS(identifier1,identifier2) identifier1 ## identifier2
|
#define G_PASTE_ARGS(identifier1,identifier2) identifier1 ## identifier2
|
||||||
#define G_PASTE(identifier1,identifier2) G_PASTE_ARGS (identifier1, identifier2)
|
#define G_PASTE(identifier1,identifier2) G_PASTE_ARGS (identifier1, identifier2)
|
||||||
|
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
|
||||||
|
#define G_STATIC_ASSERT(expr) _Static_assert (expr, "Expression evaluates to false")
|
||||||
|
#elif defined(__cplusplus) && __cplusplus >= 201103L
|
||||||
|
#define G_STATIC_ASSERT(expr) static_assert (expr, "Expression evaluates to false")
|
||||||
|
#else
|
||||||
#ifdef __COUNTER__
|
#ifdef __COUNTER__
|
||||||
#define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1] G_GNUC_UNUSED
|
#define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1] G_GNUC_UNUSED
|
||||||
#else
|
#else
|
||||||
#define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __LINE__)[(expr) ? 1 : -1] G_GNUC_UNUSED
|
#define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __LINE__)[(expr) ? 1 : -1] G_GNUC_UNUSED
|
||||||
#endif
|
#endif
|
||||||
|
#endif /* __STDC_VERSION__ */
|
||||||
#define G_STATIC_ASSERT_EXPR(expr) ((void) sizeof (char[(expr) ? 1 : -1]))
|
#define G_STATIC_ASSERT_EXPR(expr) ((void) sizeof (char[(expr) ? 1 : -1]))
|
||||||
#endif
|
#endif /* !__GI_SCANNER__ */
|
||||||
|
|
||||||
/* Provide a string identifying the current code position */
|
/* Provide a string identifying the current code position */
|
||||||
#if defined(__GNUC__) && (__GNUC__ < 3) && !defined(__cplusplus)
|
#if defined(__GNUC__) && (__GNUC__ < 3) && !defined(__cplusplus)
|
||||||
|
@ -20,6 +20,15 @@
|
|||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
|
/* Test that G_STATIC_ASSERT_EXPR can be used as an expression */
|
||||||
|
static void
|
||||||
|
test_assert_static (void)
|
||||||
|
{
|
||||||
|
G_STATIC_ASSERT (4 == 4);
|
||||||
|
if (G_STATIC_ASSERT_EXPR (1 == 1), sizeof (gchar) == 2)
|
||||||
|
g_assert_not_reached ();
|
||||||
|
}
|
||||||
|
|
||||||
/* Test G_ALIGNOF() gives the same results as the G_STRUCT_OFFSET fallback. This
|
/* Test G_ALIGNOF() gives the same results as the G_STRUCT_OFFSET fallback. This
|
||||||
* should be the minimal alignment for the given type.
|
* should be the minimal alignment for the given type.
|
||||||
*
|
*
|
||||||
@ -48,6 +57,7 @@ main (int argc,
|
|||||||
g_test_init (&argc, &argv, NULL);
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
|
||||||
g_test_add_func ("/alignof/fallback", test_alignof_fallback);
|
g_test_add_func ("/alignof/fallback", test_alignof_fallback);
|
||||||
|
g_test_add_func ("/assert/static", test_assert_static);
|
||||||
|
|
||||||
return g_test_run ();
|
return g_test_run ();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user