From owner-svn-src-head@freebsd.org Fri Feb 28 04:17:47 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id D0827259231 for ; Fri, 28 Feb 2020 04:17:47 +0000 (UTC) (envelope-from marklmi@yahoo.com) Received: from sonic316-8.consmr.mail.gq1.yahoo.com (sonic316-8.consmr.mail.gq1.yahoo.com [98.137.69.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 48TGTz3vJXz438w for ; Fri, 28 Feb 2020 04:17:42 +0000 (UTC) (envelope-from marklmi@yahoo.com) X-YMail-OSG: EU7j6HwVM1mGDGXKkPTKNHc6b5Hsh4634HdidzWDpLVXPS.J0ty34I78lUNVJkS BxRUeIuSX5bfQpRZaDbs8f9fn3LgfvvzNgnFw_YqMJ0mp9N1IYCu1m7QD3xn5.HaSCybjNlIfGd_ bYYSRCUBlqcxsierhYiqZGRMyCRrUbDqv_ZjqctvED59SkW7HdowxVge6karlLPmX7G1e3zPrxrP vDwozBkeu_8zi11.YygljDRlzRI0h8L6XgxvzcFfB0i5ntMvbyaGW2WJmWOwHuajAdKUUUkMP0kN BIE03WtoG9OyqinFYCGdycsMOrP5NGvOnPitHhbU1g7SV37Qpw6BeCfpqlpwgeDonbppxAHDyVeE 4zObXmfesOiW2CadscZxIsSuZFNqBlzA2XQcaYh8evKjM9yFrAwUNBDjghaaDkEc24tCyMEMlv1_ Do6QCrlCZOw.kVfgRmZNikcH1srCHwyr_QAnQNq80MY.P7rpNc4EvUOMuapheI6bSC.3ampxnbWj OmMFTmnqrhAGU7AsQO5ibreeQCufmRkSQfq_vHwFix1XL2TD9BAu_m_ldc5I92pjLXsyp4tlSqoc tpiMNRXZ7ZQ0E9wfvhvEWegPl3uoBEabPiaCZ4qFrLLiNUACyRuouJJlgMZ07GX0HkpyH2Kfz2By DyPvsxjqIUWpXnJZHp1eS1GWlX6vE0ZaqsY5qoI1.3LUgFvITG2oJgDIweJX6H_4jST38.WEWv2U g5Pi2jCZf.Kqw9DuEvMkSqbw0ztjlluTS7.k6gU9U6TthBINjEA.gjJQp1gHfpWQl9bFVlI2p0m2 0Wn34O4iwUOH72TuOPQjQ.bM3QPW9yc7ZlOiEG_ryaJAh5OqrJbns9DU7xAmPcPO8OAF4XhvHZiG 2sbVgW.UEkyIfHnehzO_jtXhfyF2MI3P7UHYj0aKt4XWXIYKRXiRpSe8fZFFNuUD5F1CFyXABCwJ 6RzCwC5XwnlUOQ1dwgHbmrunBDcP0SaMAobaNNVLO9EI7xqsWp9X89uz2aBagBlwm_FMEIRQ6NrV OSAlzk4y1MM73v1dSMpMmBVRmXEL1uzMkOOEL1cs4yRIa.FMBKBhixu7tQFQpdLjqBVxBbuAg4JW xqiquC4A0NG6DjreGAtdZcuqIMZPqLmf74kuk7otX8Y7fklm_ejbtjtCeDJb5QXizTk289j0Lv7j 7pjniY1F0V1JYnSQ6KYZJNKU2d0jMLh5psbtKwPkRpQbI7MkS_HDAEl0Z1oIOz0UqS.YI8k5Li6H ClVZvwQ3sOadY4VpMlJG3s1zWlWY3bDEnu8K_p2itL64xVDmspa69UNPG9VWoELXwbxw34euoqK_ UTxcE4X..UPFD7QReN9JX703TmsyyCtdsbTqvhvhkHT7K5HuXIzUhFbzadQWzazzhoOjeSJLz0uo NTQWefDTV2cSn1tg.m.G9Yws- Received: from sonic.gate.mail.ne1.yahoo.com by sonic316.consmr.mail.gq1.yahoo.com with HTTP; Fri, 28 Feb 2020 04:17:41 +0000 Received: by smtp404.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 35fc1966e254083aa321d27842bab59d; Fri, 28 Feb 2020 04:17:40 +0000 (UTC) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.60.0.2.5\)) Subject: Re: svn commit: r358392 - head/share/man/man9 From: Mark Millard In-Reply-To: Date: Thu, 27 Feb 2020 20:17:39 -0800 Cc: svn-src-head@freebsd.org, Warner Losh Content-Transfer-Encoding: quoted-printable Message-Id: <45DC452F-C753-46D7-A071-0B231F6F6206@yahoo.com> References: <217D39BA-4FDC-490C-8490-533D244E79CE.ref@yahoo.com> <217D39BA-4FDC-490C-8490-533D244E79CE@yahoo.com> <59374055-922a-81f1-1b05-a572e1cb6b1a@FreeBSD.org> To: John Baldwin X-Mailer: Apple Mail (2.3608.60.0.2.5) X-Rspamd-Queue-Id: 48TGTz3vJXz438w X-Spamd-Bar: - X-Spamd-Result: default: False [-1.31 / 15.00]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ptr:yahoo.com]; FREEMAIL_FROM(0.00)[yahoo.com]; MV_CASE(0.50)[]; DKIM_TRACE(0.00)[yahoo.com:+]; DMARC_POLICY_ALLOW(-0.50)[yahoo.com,reject]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; FREEMAIL_ENVFROM(0.00)[yahoo.com]; ASN(0.00)[asn:36647, ipnet:98.137.64.0/21, country:US]; MID_RHS_MATCH_FROM(0.00)[]; DWL_DNSWL_NONE(0.00)[yahoo.com.dwl.dnswl.org : 127.0.5.0]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-0.18)[-0.176,0]; R_DKIM_ALLOW(-0.20)[yahoo.com:s=s2048]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; NEURAL_HAM_LONG(-0.64)[-0.636,0]; MIME_GOOD(-0.10)[text/plain]; IP_SCORE(0.00)[ip: (5.13), ipnet: 98.137.64.0/21(0.83), asn: 36647(0.66), country: US(-0.05)]; IP_SCORE_FREEMAIL(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[32.69.137.98.list.dnswl.org : 127.0.5.0]; RWL_MAILSPIKE_POSSIBLE(0.00)[32.69.137.98.rep.mailspike.net : 127.0.0.17]; RCVD_COUNT_TWO(0.00)[2] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Feb 2020 04:17:47 -0000 [Ignoring llvm-project and libstdc++, I only find about 24 other instances of "static_assert".] On 2020-Feb-27, at 19:03, Mark Millard wrote > On 2020-Feb-27, at 16:37, John Baldwin wrote: >=20 >> 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 = >>>> adds static_assert() as an alias, similar to defining = alignas, >>>> etc. I think what we should do for the kernel is have = 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 >>>=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 is guarded to not kick = in for >> C++. >=20 > 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) : >=20 > # 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 > . . . >=20 > # 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 > . . . >=20 > 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. >=20 > Messy, but possibly localized. >=20 > That prompted a more general grep: >=20 > # 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) >=20 > So not much else. Just an FYI: Looks like static_assert is little used (outside llvm-project and libstdc++): # grep -r "\" /usr/src/* | grep -v llvm-project | grep = -v "libstdc\+\+" | more /usr/src/contrib/googletest/googlemock/include/gmock/gmock-matchers.h: = static_assert( /usr/src/contrib/googletest/googlemock/include/gmock/gmock-matchers.h: = static_assert(sizeof...(Args) > 0, "Must have at least one matcher."); /usr/src/contrib/googletest/googlemock/docs/DesignDoc.md:Google Test = (the name is chosen to match `static_assert` in C++0x). = /usr/src/contrib/googletest/googletest/include/gtest/internal/gtest-port.h= :# define GTEST_COMPILE_ASSERT_(expr, msg) static_assert(expr, #msg) = /usr/src/contrib/googletest/googletest/include/gtest/internal/gtest-port.h= :// (In C++11, we simply use static_assert instead of the following) /usr/src/contrib/bsnmp/snmpd/trans_inet.c:static_assert(offsetof(struct = port_sock, input) =3D=3D 0, /usr/src/contrib/bsnmp/snmpd/trans_inet.c:static_assert(offsetof(struct = inet_port, tport) =3D=3D 0, /usr/src/contrib/libcxxrt/guard.cc:static_assert(sizeof(guard_t) =3D=3D = sizeof(uint64_t), ""); /usr/src/contrib/ofed/libibumad/umad.c:static_assert(sizeof(struct = ib_user_mad_reg_req) =3D=3D IOCPARM_LEN(IB_USER_MAD_REGISTER_AGENT), /usr/src/contrib/ofed/libibumad/umad.c:static_assert(sizeof(struct = ib_user_mad_reg_req2) =3D=3D IOCPARM_LEN(IB_USER_MAD_REGISTER_AGENT2), /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/contrib/zstd/contrib/pzstd/utils/FileSystem.h: = static_assert(false, "No POSIX stat() support."); /usr/src/sys/contrib/zstd/contrib/pzstd/utils/FileSystem.h: = static_assert(false, "NO POSIX stat() support."); /usr/src/usr.bin/dtc/HACKING:The code also makes use of = `static_assert()` to track compile-time invariants. /usr/src/usr.bin/dtc/util.hh:#ifndef static_assert /usr/src/usr.bin/dtc/util.hh:#define static_assert(x, y) ((void)0) /usr/src/usr.bin/dtc/util.hh: static_assert(sizeof(T) > 1, /usr/src/usr.sbin/bhyve/task_switch.c:static_assert(sizeof(struct tss32) = =3D=3D 104, "compile-time assertion failed"); /usr/src/usr.sbin/bhyve/pci_emul.h:static_assert(sizeof(struct msicap) = =3D=3D 14, "compile-time assertion failed"); /usr/src/usr.sbin/bhyve/pci_emul.h:static_assert(sizeof(struct msixcap) = =3D=3D 12, "compile-time assertion failed"); /usr/src/usr.sbin/bhyve/pci_emul.h:static_assert(sizeof(struct pciecap) = =3D=3D 60, "compile-time assertion failed"); /usr/src/usr.sbin/syslogd/syslogd.c: = static_assert(sizeof(f->f_prevline) =3D=3D sizeof(saved), _Static_assert looks to be far more common. (Too long to list here.) =3D=3D=3D Mark Millard marklmi at yahoo.com ( dsl-only.net went away in early 2018-Mar)