diff options
Diffstat (limited to 'include/apr_general.h')
-rw-r--r-- | include/apr_general.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/include/apr_general.h b/include/apr_general.h index 4f2a6e8c4..5e53bb63d 100644 --- a/include/apr_general.h +++ b/include/apr_general.h @@ -29,6 +29,9 @@ #include "apr_pools.h" #include "apr_errno.h" +#if APR_HAVE_ASSERT_H +#include <assert.h> +#endif #if APR_HAVE_SIGNAL_H #include <signal.h> #endif @@ -112,6 +115,42 @@ typedef enum { APR_WAIT_READ, APR_WAIT_WRITE } apr_wait_type_t; #define APR_OFFSETOF(s_type,field) APR_OFFSET(s_type*,field) #endif +/** + * Compile time assertions. + * @param predicate static condition + * @param errstring static error message (literal) + */ +#if defined(static_assert) \ + || __has_builtin(static_assert) \ + || (defined(__cplusplus) && (__cplusplus >= 201103L || \ + __has_extension(cxx_static_assert))) \ + || (defined(_MSC_VER ) && _MSC_VER >= 1600) +#define APR_STATIC_ASSERT static_assert + +#elif defined(_Static_assert) \ + || __has_builtin(_Static_assert) \ + || __has_extension(c_static_assert) \ + || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && \ + __GNUC_MINOR__ >= 6))) +#define APR_STATIC_ASSERT _Static_assert + +#else /* !static_assert && !_Static_assert */ +#define APR__STATIC_CONCAT_(x, y) x##y +#define APR__STATIC_CONCAT(x, y) APR__STATIC_CONCAT_(x, y) +#if defined(__COUNTER__) +#define APR_STATIC_ASSERT(predicate, errstring) \ + typedef struct { \ + int static_assert_failure:!!(predicate)*2-1; \ + } APR__STATIC_CONCAT(static_assert_test_, __COUNTER__); +#else /* !__COUNTER__ */ +#define APR_STATIC_ASSERT(predicate, errstring) \ + typedef struct { \ + int static_assert_failure:!!(predicate)*2-1; \ + } APR__STATIC_CONCAT(static_assert_test_, __LINE__); +#endif /* !__COUNTER__ */ + +#endif /* !static_assert && !_Static_assert */ + #ifndef DOXYGEN /* A couple of prototypes for functions in case some platform doesn't |