diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h --- a/sys/sys/cdefs.h +++ b/sys/sys/cdefs.h @@ -236,17 +236,33 @@ #endif #if !__has_extension(c_static_assert) -#if (defined(__cplusplus) && __cplusplus >= 201103L) || \ - __has_extension(cxx_static_assert) +#if defined(__cplusplus) +/* + * For C++ case, only define _Static_assert for C++ 2011 (or newer) or if the + * compiler has the cxx_static_assert extension. This is only to suppert C11+ + * code in headers that are included with C++ code. We don't define it for + * older versions of C++ because they have no _Static_assert or static_assert + * macros in the language and if either are implemented as macros, they break + * when used with templates (since it looks to CPP that the macro is invoked + * with more than 2 arguments). + */ +#if __cplusplus >= 201103L || __has_extension(cxx_static_assert) #define _Static_assert(x, y) static_assert(x, y) -#elif __GNUC_PREREQ__(4,6) && !defined(__cplusplus) +#endif +#elif __GNUC_PREREQ__(4,6) /* Nothing, gcc 4.6 and higher has _Static_assert built-in */ #elif defined(__COUNTER__) +/* + * Fallback for really old C compilers, using the __COUNTER__ hack. + */ #define _Static_assert(x, y) __Static_assert(x, __COUNTER__) #define __Static_assert(x, y) ___Static_assert(x, y) #define ___Static_assert(x, y) typedef char __assert_ ## y[(x) ? 1 : -1] \ __unused #else +/* + * Fallback for even older C compilers that don't implement that hack. + */ #define _Static_assert(x, y) struct __hack #endif #endif