util: simplify _COGL_STATIC_ASSERT definition

This updates the definition of _COGL_STATIC_ASSERT to just use
_Static_assert if available or be NOP if not. We no longer worry about
supporting static assertions with older compilers. This fixes some
verbose warnings that newer compilers were giving with the old typedef
based static assertion method.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 645e3607ea7f210d6dcb9d217204790051de7c82)
This commit is contained in:
Robert Bragg 2013-10-14 17:28:11 +01:00
parent 669b3ad864
commit 8d998b64c9

View File

@ -261,30 +261,12 @@ _cogl_util_pixel_format_from_masks (unsigned long r_mask,
* *
* Note: Only Gcc >= 4.6 supports the c11 _Static_assert which lets us * Note: Only Gcc >= 4.6 supports the c11 _Static_assert which lets us
* print a nice message if the compile time assertion fails. * print a nice message if the compile time assertion fails.
*
* Note: this assertion macro can only be used in C code where it is
* valid to use a typedef. This macro should not be used in headers
* because we can't guarantee a unique name for the typedef due to
* the name being based on the line number of the file it's used in.
*
* Although we can remove this limitation if the compiler supports
* _Static_assert we currently choose to maintain the limitation in
* any case to help ensure we don't accidentally create code that
* doesn't compile on some toolchains because we forgot about this
* limitation.
*/ */
#ifdef HAVE_STATIC_ASSERT #ifdef HAVE_STATIC_ASSERT
#define _COGL_STATIC_ASSERT(EXPRESSION, MESSAGE) \ #define _COGL_STATIC_ASSERT(EXPRESSION, MESSAGE) \
_Static_assert (EXPRESSION, MESSAGE); \ _Static_assert (EXPRESSION, MESSAGE);
_COGL_TYPEDEF_ASSERT(EXPRESSION)
#else #else
#define _COGL_STATIC_ASSERT(EXPRESSION, MESSAGE) \ #define _COGL_STATIC_ASSERT(EXPRESSION, MESSAGE)
_COGL_TYPEDEF_ASSERT(EXPRESSION)
/* So that we can safely use _Static_assert() if we want to add
* assertions to internal headers we define it to a NOP here
* if it's not supported by the compiler. */
#define _Static_assert(EXPRESSION, MESSAGE)
#endif #endif
#ifdef HAVE_MEMMEM #ifdef HAVE_MEMMEM