git: 7e6f5e494a76 - stable/13 - assert.3: Document static_assert and _Static_assert

From: Mateusz Piotrowski <0mp_at_FreeBSD.org>
Date: Wed, 29 Jun 2022 08:23:56 UTC
The branch stable/13 has been updated by 0mp (doc, ports committer):

URL: https://cgit.FreeBSD.org/src/commit/?id=7e6f5e494a76b91ae23c7dbd250dff2d1c6e03bf

commit 7e6f5e494a76b91ae23c7dbd250dff2d1c6e03bf
Author:     Faraz Vahedi <kfv@kfv.io>
AuthorDate: 2021-04-20 08:50:36 +0000
Commit:     Mateusz Piotrowski <0mp@FreeBSD.org>
CommitDate: 2022-06-29 08:22:38 +0000

    assert.3: Document static_assert and _Static_assert
    
    Reviewed by:    imp, 0mp
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D29833
    
    (cherry picked from commit 33f8d79d765230e3189876dec9f0dad2d768de1a)
---
 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 324a843201aa..33101026c01a 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