@@ -4309,18 +4309,31 @@ function or at file scope (outside of any function).
43094309 * We use a bit-field instead of an array because gcc accepts
43104310 typedef char x[n]
43114311 where n is not a compile-time constant. We want to enforce constantness.
4312- */
4313- # define STATIC_ASSERT_2 (COND, SUFFIX ) \
4314- typedef struct { \
4315- unsigned int _static_assertion_failed_##SUFFIX : (COND) ? 1 : -1 ; \
4316- } _static_assertion_failed_##SUFFIX PERL_UNUSED_DECL
4317- # define STATIC_ASSERT_1 (COND, SUFFIX ) STATIC_ASSERT_2(COND, SUFFIX)
4318- # define STATIC_ASSERT_DECL (COND ) STATIC_ASSERT_1(COND, __LINE__)
4312+ *
4313+ * We need the FOOL macros to get proper cpp parameter concatanation. */
4314+ # define STATIC_ASSERT_STRUCT_NAME_FOOL_CPP_2_ (line ) \
4315+ static_assertion_failed_##line
4316+ # define STATIC_ASSERT_STRUCT_NAME_FOOL_CPP_ (line ) \
4317+ STATIC_ASSERT_STRUCT_NAME_FOOL_CPP_2_ (line)
4318+ /* Return the struct and element name */
4319+ # define STATIC_ASSERT_STRUCT_NAME_ \
4320+ STATIC_ASSERT_STRUCT_NAME_FOOL_CPP_ (__LINE__)
4321+
4322+ /* Return the struct body */
4323+ # define STATIC_ASSERT_STRUCT_BODY_ (COND, NAME ) \
4324+ struct { unsigned NAME : (COND) ? 1 : -1 ; }
4325+
4326+ # define STATIC_ASSERT_DECL (COND ) \
4327+ typedef STATIC_ASSERT_STRUCT_BODY_ (COND, STATIC_ASSERT_STRUCT_NAME_) \
4328+ STATIC_ASSERT_STRUCT_NAME_ PERL_UNUSED_DECL
4329+
43194330#endif
4331+
43204332/* We need this wrapper even in C11 because 'case X: static_assert(...);' is an
43214333 error (static_assert is a declaration, and only statements can have labels).
43224334*/
4323- #define STATIC_ASSERT_STMT (COND ) STMT_START { STATIC_ASSERT_DECL (COND); } STMT_END
4335+ #define STATIC_ASSERT_STMT (COND ) \
4336+ STMT_START { STATIC_ASSERT_DECL(COND); } STMT_END
43244337
43254338#ifndef __has_builtin
43264339# define __has_builtin (x ) 0 /* not a clang style compiler */
0 commit comments