Date: Thu, 27 Feb 2020 19:03:58 -0800 From: Mark Millard <marklmi@yahoo.com> To: John Baldwin <jhb@FreeBSD.org> Cc: svn-src-head@freebsd.org, Warner Losh <imp@bsdimp.com> Subject: Re: svn commit: r358392 - head/share/man/man9 Message-ID: <DE283429-4303-4929-96A6-8EF43BDF8F17@yahoo.com> In-Reply-To: <59374055-922a-81f1-1b05-a572e1cb6b1a@FreeBSD.org> References: <217D39BA-4FDC-490C-8490-533D244E79CE.ref@yahoo.com> <217D39BA-4FDC-490C-8490-533D244E79CE@yahoo.com> <59374055-922a-81f1-1b05-a572e1cb6b1a@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2020-Feb-27, at 16:37, John Baldwin <jhb at FreeBSD.org> wrote: > On 2/27/20 2:45 PM, Mark Millard wrote: >> John Baldwin jhb at FreeBSD.org wrote on >> Thu Feb 27 16:55:01 UTC 2020: >>=20 >>> On 2/27/20 7:30 AM, Warner Losh wrote: >>>> Author: imp >>>> Date: Thu Feb 27 15:30:13 2020 >>>> New Revision: 358392 >>>> URL: https://svnweb.freebsd.org/changeset/base/358392 >>>>=20 >>>> Log: >>>> _Static_assert is to be preferred to CTASSERT. >>>>=20 >>>> Document the existing prefernce that _Static_assert be used in = preference to the >>>> old CTASSERT we used to use for compile time assertions. >>>=20 >>> Actually, I think what we want to use is static_assert(). The = intention in >>> userland C is that _Static_assert() is an internal keyword and = <assert.h> >>> adds static_assert() as an alias, similar to <stdalign.h> defining = alignas, >>> etc. I think what we should do for the kernel is have <sys/systm.h> = define >>> map static_assert to _Static_assert and replace existing = _Static_assert >>> usage with the proper spelling. >>>=20 >>=20 >> Be warned static_assert is a C++ keyword as of C++11. >>=20 >> c++11 added: static_assert(bool_constexpr,message) >> c++17 added: static_assert(bool_constexpr) >>=20 >> C11 added _Static_assert(expression,message) >> C2x gets _Static_assert(expression) >>=20 >> C11 added "#define static_assert _Static_assert" to <assert.h> >>=20 >> It makes for a bit of a mess in code to be allowed >> to be processed by both C and C++. >>=20 >> The wording may need to specify enough to tell what to >> do for such code and the headers may need logic to >> cause that context to exist across both languages >> when the header is allowed for both. >=20 > The intent of the C11 changes is to permit equivalent use of = static_assert() > in both languages. The #define in <assert.h> is guarded to not kick = in for > C++. Ahh. I had vague memories of past oddities in the area that I was involved in. So I looked and found (in head -r3578132 source) : # more /usr/src/sys/sys/cdefs.h . . . #if !__has_extension(c_static_assert) #if (defined(__cplusplus) && __cplusplus >=3D 201103L) || \ __has_extension(cxx_static_assert) #define _Static_assert(x, y) static_assert(x, y) #elif __GNUC_PREREQ__(4,6) && !defined(__cplusplus) /* Nothing, gcc 4.6 and higher has _Static_assert built-in */ #elif defined(__COUNTER__) #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 #define _Static_assert(x, y) struct __hack #endif #endif . . . # more /usr/include/assert.h . . . /* * Static assertions. In principle we could define static_assert for * C++ older than C++11, but this breaks if _Static_assert is * implemented as a macro. * * C++ template parameters may contain commas, even if not enclosed in * parentheses, causing the _Static_assert macro to be invoked with more * than two parameters. */ #if __ISO_C_VISIBLE >=3D 2011 && !defined(__cplusplus) #define static_assert _Static_assert #endif . . . So one can define a _Static_assert macro, sometimes in terms of static_assert, and the other sometimes defines a static_assert macro in terms of _Static_assert. Messy, but possibly localized. That prompted a more general grep: # grep -r "define[ _]*[Ss]tatic_assert" /usr/src/* | more /usr/src/contrib/llvm-project/libcxx/include/__config:# define = static_assert(...) _Static_assert(__VA_ARGS__) /usr/src/contrib/llvm-project/libunwind/src/config.h: #define = static_assert(__b, __m) \ /usr/src/include/assert.h: * Static assertions. In principle we could = define static_assert for /usr/src/include/assert.h:#define static_assert _Static_assert /usr/src/sys/sys/cdefs.h:#define _Static_assert(x, y) = static_assert(x, y) /usr/src/sys/sys/cdefs.h:#define _Static_assert(x, y) = __Static_assert(x, __COUNTER__) /usr/src/sys/sys/cdefs.h:#define __Static_assert(x, y) = ___Static_assert(x, y) /usr/src/sys/sys/cdefs.h:#define ___Static_assert(x, y) typedef = char __assert_ ## y[(x) ? 1 : -1] \ /usr/src/sys/sys/cdefs.h:#define _Static_assert(x, y) struct = __hack /usr/src/usr.bin/dtc/util.hh:#define static_assert(x, y) ((void)0) So not much else. =3D=3D=3D Mark Millard marklmi at yahoo.com ( dsl-only.net went away in early 2018-Mar)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?DE283429-4303-4929-96A6-8EF43BDF8F17>