From owner-dev-commits-src-all@freebsd.org Tue Apr 20 09:22:14 2021 Return-Path: Delivered-To: dev-commits-src-all@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 A081E5ED916; Tue, 20 Apr 2021 09:22:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FPdVt49zgz4Vmg; Tue, 20 Apr 2021 09:22:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 781611015A; Tue, 20 Apr 2021 09:22:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 13K9ME3o022602; Tue, 20 Apr 2021 09:22:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 13K9ME2h022601; Tue, 20 Apr 2021 09:22:14 GMT (envelope-from git) Date: Tue, 20 Apr 2021 09:22:14 GMT Message-Id: <202104200922.13K9ME2h022601@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mateusz Piotrowski <0mp@FreeBSD.org> Subject: git: 33f8d79d7652 - main - assert.3: Document static_assert and _Static_assert MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: 0mp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 33f8d79d765230e3189876dec9f0dad2d768de1a Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Apr 2021 09:22:14 -0000 The branch main has been updated by 0mp (doc, ports committer): URL: https://cgit.FreeBSD.org/src/commit/?id=33f8d79d765230e3189876dec9f0dad2d768de1a commit 33f8d79d765230e3189876dec9f0dad2d768de1a Author: Faraz Vahedi AuthorDate: 2021-04-20 08:50:36 +0000 Commit: Mateusz Piotrowski <0mp@FreeBSD.org> CommitDate: 2021-04-20 09:17:44 +0000 assert.3: Document static_assert and _Static_assert Reviewed by: imp, 0mp MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D29833 --- share/man/man3/Makefile | 1 + share/man/man3/assert.3 | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/share/man/man3/Makefile b/share/man/man3/Makefile index d33c0d63ea0d..ea82f04c7825 100644 --- a/share/man/man3/Makefile +++ b/share/man/man3/Makefile @@ -72,6 +72,7 @@ MLINKS= arb.3 ARB8_ENTRY.3 \ arb.3 ARB_RIGHT.3 \ arb.3 ARB_RIGHTIDX.3 \ arb.3 ARB_ROOT.3 +MLINKS+= assert.3 static_assert.3 MLINKS+= ATOMIC_VAR_INIT.3 atomic_compare_exchange_strong.3 \ ATOMIC_VAR_INIT.3 atomic_compare_exchange_strong_explicit.3 \ ATOMIC_VAR_INIT.3 atomic_compare_exchange_weak.3 \ diff --git a/share/man/man3/assert.3 b/share/man/man3/assert.3 index 8bdf076233c8..cc23f96360f0 100644 --- a/share/man/man3/assert.3 +++ b/share/man/man3/assert.3 @@ -28,15 +28,18 @@ .\" @(#)assert.3 8.1 (Berkeley) 6/9/93 .\" $FreeBSD$ .\" -.Dd May 31, 2018 +.Dd April 20, 2021 .Dt ASSERT 3 .Os .Sh NAME -.Nm assert +.Nm assert , +.Nm static_assert .Nd expression verification macro .Sh SYNOPSIS .In assert.h .Fn assert expression +.Fn static_assert expression +.Fn static_assert expression message .Sh DESCRIPTION The .Fn assert @@ -81,6 +84,21 @@ The macro should only be used for ensuring the developer's expectations hold true. It is not appropriate for regular run-time error detection. +.Pp +The +.Fn static_assert +macro expands to +.Fn _Static_assert , +and, contrarily to +.Fn assert , +makes assertions at compile-time. +Once the constraint is violated, the compiler produces a diagnostic +message including the string literal message, if provided. +The initial form of the +.Fn _Static_assert +containing a string literal message was introduced in C11 standard, and +the other form with no string literal is to be implemented by C2x and +some compilers may lack its adoption at present. .Sh EXAMPLES The assertion: .Dl "assert(1 == 0);" @@ -95,14 +113,29 @@ indicate a bug. Second, the code will disappear if .Dv NDEBUG is defined, changing the semantics of the program. +.Pp +The following asserts that the size of the S structure is 16. +Otherwise, it produces a diagnostic message which points at the +constraint and includes the provided string literal: +.Dl "static_assert(sizeof(struct S) == 16, ""size mismatch"");" +If none is provided, it only points at the constraint. .Sh SEE ALSO .Xr abort2 2 , .Xr abort 3 .Sh STANDARDS +.Rs The .Fn assert macro conforms to .St -isoC-99 . +.Re +.Pp +.Rs +The +.Fn static_assert +macro conforms to +.St -isoC-2011 . +.Re .Sh HISTORY An .Nm