Slightly alter the C1X definitions in in cdefs.h:
- Add _Alignas(). Unfortunately this macro is only partially functional. The C1X standard will allow both an integer and a type name to be passed to this macro, while this macro only allows an integer. To be portable, one must use _Alignas(_Alignof(double)) to use type names. - Don't do _Static_assert() when __COUNTER__ is not supported. We'd better keep this implementation robust and allow it to be used in header files, without mysteriously breaking older compilers.
This commit is contained in:
parent
663e39b0b5
commit
e22e07ff3b
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=228495
@ -222,6 +222,7 @@
|
||||
* Keywords added in C1X.
|
||||
*/
|
||||
#if defined(__cplusplus) && __cplusplus >= 201103L
|
||||
#define _Alignas(e) alignas(e)
|
||||
#define _Alignof(e) alignof(e)
|
||||
#define _Noreturn [[noreturn]]
|
||||
#define _Static_assert(e, s) static_assert(e, s)
|
||||
@ -231,21 +232,23 @@
|
||||
#else
|
||||
/* Not supported. Implement them manually. */
|
||||
#ifdef __GNUC__
|
||||
#define _Alignas(e) __attribute__((__aligned__(e)))
|
||||
#define _Alignof(e) __alignof__(e)
|
||||
#define _Noreturn __attribute__((__noreturn__))
|
||||
#define _Thread_local __thread
|
||||
#else
|
||||
#define _Alignas(e)
|
||||
#define _Alignof(e) __offsetof(struct { char __a; e __b; }, __b)
|
||||
#define _Noreturn
|
||||
#define _Thread_local
|
||||
#endif
|
||||
#ifdef __COUNTER__
|
||||
#define _Static_assert(e, s) __Static_assert(e, __COUNTER__)
|
||||
#else
|
||||
#define _Static_assert(e, s) __Static_assert(e, __LINE__)
|
||||
#endif
|
||||
#define __Static_assert(e, c) ___Static_assert(e, c)
|
||||
#define ___Static_assert(e, c) typedef char __assert ## c[(e) ? 1 : -1]
|
||||
#else
|
||||
#define _Static_assert(e, s)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if __GNUC_PREREQ__(2, 96)
|
||||
|
Loading…
Reference in New Issue
Block a user