From owner-svn-src-head@freebsd.org Fri Feb 28 05:46:54 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 DE64B25AA07 for ; Fri, 28 Feb 2020 05:46:54 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: from mail-qt1-x833.google.com (mail-qt1-x833.google.com [IPv6:2607:f8b0:4864:20::833]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48TJSr4SPsz48t0 for ; Fri, 28 Feb 2020 05:46:52 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: by mail-qt1-x833.google.com with SMTP id l16so1250834qtq.1 for ; Thu, 27 Feb 2020 21:46:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=X0mnjLlFpg1dAL++Y/0Mm+Ul0c4lrq1QtiPihbMx/go=; b=ahPQaPcR7jXC1nzaYtCbL77XB1Y4ewQwpkC8Cuxa97SsnStgmhuAyYu1Bsp0nTow5A usJWA0tfNuef83gqiUt+TrL5uLP1KvjpQH0rpl126VcrRJDSzzEOI7IL1vKAU7E3rfTz 6I6+j+u2wSEJTrMr/cAdfgIS9FQRN3foRRPRzXt3Bl6hQY8zD35/m0jNMnrLjuwHgkkQ ioh+au2ktpQ+C2L7PLrV7WsbWzbsiSnbyp/azvGi+eyzls0mIyqTHLOQpjaV1wCgUzR8 f9wuMVlWynfpp0mwIVuPTsWMLWKX9sc5g3apmmuKYqLEC00Hke7eexvJf7EFRhTILUBR BTkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=X0mnjLlFpg1dAL++Y/0Mm+Ul0c4lrq1QtiPihbMx/go=; b=OIFhb/6lkOvIKlTMVR8o4pro4rdqwFWMrARstar63iOSobQ5jjG31jFEOHTc4j/va6 ykkTQAehbSePKKkJiH7ekYg48HvfX3REpZ/4nj5nHm+jS13nM8rZatswjctF3EnQizbi vDURI6Dxh0QCg4vHKW8nUWI5HznJVcmVquisZawOcYDgmG4HbMujlMqSYxy4JOeNZ8nr +I8FhOsT/Ck69EZfnpCVpJUTlYwHUFBoSnrMWYD47Qq9NY6RNJnYdoT8dzyCNI16Huh3 G4cAZ4OUxM/FhaXBqqiIar82O0xIYPMPUXqVcoaOnVYVt4UqTtBduGCBZoZkbxzCcTxW B7cg== X-Gm-Message-State: APjAAAUyHIQg0vyMbTiDSRCyZ7TRS3ruOvNHiuL6K2Kw9vGyfaq3YsAF LWdeMw0KHJeg7hLuN70KHfFwp3W+Vgktf1DstWT7zQ== X-Google-Smtp-Source: APXvYqwVUDAn10RqedkGWJUTuHsXujlUJjpr5ZUnzkClJd8WaeFYg5yedEuv0xQzLerx37f8vMLtTJC/ZPKeHBAnIT8= X-Received: by 2002:ac8:4e93:: with SMTP id 19mr2796148qtp.32.1582868810831; Thu, 27 Feb 2020 21:46:50 -0800 (PST) MIME-Version: 1.0 References: <217D39BA-4FDC-490C-8490-533D244E79CE.ref@yahoo.com> <217D39BA-4FDC-490C-8490-533D244E79CE@yahoo.com> <59374055-922a-81f1-1b05-a572e1cb6b1a@FreeBSD.org> <45DC452F-C753-46D7-A071-0B231F6F6206@yahoo.com> In-Reply-To: <45DC452F-C753-46D7-A071-0B231F6F6206@yahoo.com> From: Warner Losh Date: Thu, 27 Feb 2020 22:46:38 -0700 Message-ID: Subject: Re: svn commit: r358392 - head/share/man/man9 To: Mark Millard Cc: John Baldwin , svn-src-head X-Rspamd-Queue-Id: 48TJSr4SPsz48t0 X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=bsdimp-com.20150623.gappssmtp.com header.s=20150623 header.b=ahPQaPcR; dmarc=none; spf=none (mx1.freebsd.org: domain of wlosh@bsdimp.com has no SPF policy when checking 2607:f8b0:4864:20::833) smtp.mailfrom=wlosh@bsdimp.com X-Spamd-Result: default: False [-3.56 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; R_DKIM_ALLOW(-0.20)[bsdimp-com.20150623.gappssmtp.com:s=20150623]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; PREVIOUSLY_DELIVERED(0.00)[svn-src-head@freebsd.org]; DMARC_NA(0.00)[bsdimp.com]; URI_COUNT_ODD(1.00)[9]; TO_MATCH_ENVRCPT_SOME(0.00)[]; TO_DN_ALL(0.00)[]; DKIM_TRACE(0.00)[bsdimp-com.20150623.gappssmtp.com:+]; RCVD_IN_DNSWL_NONE(0.00)[3.3.8.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.4.6.8.4.0.b.8.f.7.0.6.2.list.dnswl.org : 127.0.5.0]; R_SPF_NA(0.00)[]; FORGED_SENDER(0.30)[imp@bsdimp.com,wlosh@bsdimp.com]; FREEMAIL_TO(0.00)[yahoo.com]; MIME_TRACE(0.00)[0:+,1:+,2:~]; IP_SCORE(-2.56)[ip: (-9.19), ipnet: 2607:f8b0::/32(-1.88), asn: 15169(-1.67), country: US(-0.05)]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; FROM_NEQ_ENVFROM(0.00)[imp@bsdimp.com,wlosh@bsdimp.com]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2] Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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 05:46:55 -0000 On Thu, Feb 27, 2020, 9:17 PM Mark Millard wrote: > [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: > > > >> 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: > >>> > >>>> 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 > >>>>> > >>>>> Log: > >>>>> _Static_assert is to be preferred to CTASSERT. > >>>>> > >>>>> Document the existing prefernce that _Static_assert be used in > preference to the > >>>>> old CTASSERT we used to use for compile time assertions. > >>>> > >>>> 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. > >>>> > >>> > >>> Be warned static_assert is a C++ keyword as of C++11. > >>> > >>> c++11 added: static_assert(bool_constexpr,message) > >>> c++17 added: static_assert(bool_constexpr) > >>> > >>> C11 added _Static_assert(expression,message) > >>> C2x gets _Static_assert(expression) > >>> > >>> C11 added "#define static_assert _Static_assert" to > >>> > >>> It makes for a bit of a mess in code to be allowed > >>> to be processed by both C and C++. > >>> > >>> 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. > >> > >> 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++. > > > > 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 >= 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 >= 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. > > 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) == 0, > /usr/src/contrib/bsnmp/snmpd/trans_inet.c:static_assert(offsetof(struct > inet_port, tport) == 0, > /usr/src/contrib/libcxxrt/guard.cc:static_assert(sizeof(guard_t) == > sizeof(uint64_t), ""); > /usr/src/contrib/ofed/libibumad/umad.c:static_assert(sizeof(struct > ib_user_mad_reg_req) == IOCPARM_LEN(IB_USER_MAD_REGISTER_AGENT), > /usr/src/contrib/ofed/libibumad/umad.c:static_assert(sizeof(struct > ib_user_mad_reg_req2) == 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) > == 104, "compile-time assertion failed"); > /usr/src/usr.sbin/bhyve/pci_emul.h:static_assert(sizeof(struct msicap) == > 14, "compile-time assertion failed"); > /usr/src/usr.sbin/bhyve/pci_emul.h:static_assert(sizeof(struct msixcap) == > 12, "compile-time assertion failed"); > /usr/src/usr.sbin/bhyve/pci_emul.h:static_assert(sizeof(struct pciecap) == > 60, "compile-time assertion failed"); > /usr/src/usr.sbin/syslogd/syslogd.c: > static_assert(sizeof(f->f_prevline) == sizeof(saved), > > _Static_assert looks to be far more common. (Too long > to list here.) > Right.. originally I was going to document static_asset(), but then people on irc said the other was far more common. A quick grep confirmed it. So it met my test of documenting an overwhelming practice. Whether we should change or not is a separate question. Warner === > Mark Millard > marklmi at yahoo.com > ( dsl-only.net went > away in early 2018-Mar) > >