From nobody Mon Jun 29 10:11:21 2026 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4gphrV6rThz6kN82 for ; Mon, 29 Jun 2026 10:11:22 +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 "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4gphrV1WKnz3c2q for ; Mon, 29 Jun 2026 10:11:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1782727882; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=f3W0WINkxW5zfbEQYMbZHFH9w1Ky5RZWvrJ5+CmZHzA=; b=k285hXxFzc5BVask8Nb7z6ErBTg+A43ESL8rZ2wbgkyKFWyyduSOdZECFpKdAXZ7cMDdr6 Kj0ieigLcsrOvEQkD3YLUR+2GnkpTUsHMbEBUYOz3kgsD4eUo4b/ME7bs0FbwmR8lI3Neh q5j/k1PaayfAnzj43JbcoadibAs2bEMbaaqBPUTaA/7T8UBxZcFLg7ek8sxlOZqLXnbg47 ZTrwIK2vqavKOEBLjSc2W3gUHvuYurAPKNT7nQ/FBy2vn348vLGmSmtGKxEpA8QeNyfj7T SB+2mJjOhRogsGWcbbTBMww3mkIJH2fJAJCWqwBDKGpFa/MfUr5cuIX2QrGQqA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1782727882; a=rsa-sha256; cv=none; b=yJhUGz3CkFjqk5fAWEMxnL+IIYDMs3jeCsmLVmoeLXCvmuQizb+06XzUkROGu6ZVoUtH/J c+EQbjYJdBjZzSZ3V1wBHr9sPSCdE6WS6HD8VTxkAzqx+TD3+qwIkHZgctp+A2QTr0/aS3 Z56+fPhcUEytn25uhYJF1Nnxd23NiRashpVWuCtwyxNpsOCYdsC5mN6gHmCisnpYuPL8tE 7Ln2Jl6hswPV1DLqdZr/0WgIu1ndXUaAu+adZJybweN3oLv0KvqF1pjlqouZPIlh6TpswF MKlbG21fi6u0BEQVsuIanIlhWuF66exFhWVUIesrlNgg31ZF/2gIwMZt97Xstw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1782727882; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=f3W0WINkxW5zfbEQYMbZHFH9w1Ky5RZWvrJ5+CmZHzA=; b=utYxAjShqvF7Br1nHt9fhpXTPz1m4vunqDauMs3CH1peSOXRxur5PTBtb1jG1DbKWZVD5c CYskDUTOSbBhBhy+VYd2jxqIdC7LCNwJCIxKEPgyTeFjVDlgI0liNzIS6HnrQ/QyEsYRMG eCgbq4I15bVqIv7ttjVagkQnekRJqtD2Rs9AMWmgblyEPdhFg9PxwiVCNIjAShnQLBqIda pGq1NKwROSBmvruDlnbH3xQJleOwoSay+tvbaqMO/dk/Mlj4gmX/ikcEYFwnc08JQsE3cL AUDZ8gjug/phqOrfbQZr5tzfYSoAjp66Dsg1vvUPK92bZ79hHGfVzEtS1v05ng== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gphrT5j80zss4 for ; Mon, 29 Jun 2026 10:11:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3708f by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 29 Jun 2026 10:11:21 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Cc: Faraz Vahedi From: Robert Clausecker Subject: git: f57a6d5d888e - stable/15 - assert.3: Update as per C23 List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: fuz X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: f57a6d5d888e6f8ef1b38232a36bfa6b66470be4 Auto-Submitted: auto-generated Date: Mon, 29 Jun 2026 10:11:21 +0000 Message-Id: <6a4244c9.3708f.2072f99d@gitrepo.freebsd.org> The branch stable/15 has been updated by fuz: URL: https://cgit.FreeBSD.org/src/commit/?id=f57a6d5d888e6f8ef1b38232a36bfa6b66470be4 commit f57a6d5d888e6f8ef1b38232a36bfa6b66470be4 Author: Faraz Vahedi AuthorDate: 2026-05-20 07:22:19 +0000 Commit: Robert Clausecker CommitDate: 2026-06-29 08:23:02 +0000 assert.3: Update as per C23 Signed-off-by: Faraz Vahedi Reviewed by: fuz MFC after: 1 month Pull Request: https://github.com/freebsd/freebsd-src/pull/2203 (cherry picked from commit c115aad996d52f5270ccd22b27d1f34b4f0f4160) --- share/man/man3/assert.3 | 76 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 61 insertions(+), 15 deletions(-) diff --git a/share/man/man3/assert.3 b/share/man/man3/assert.3 index f219aa1d6743..2782ffe7de18 100644 --- a/share/man/man3/assert.3 +++ b/share/man/man3/assert.3 @@ -25,7 +25,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd April 20, 2021 +.Dd May 17, 2026 .Dt ASSERT 3 .Os .Sh NAME @@ -40,15 +40,14 @@ .Sh DESCRIPTION The .Fn assert -macro tests the given -.Ar expression +macro tests the given scalar +.Ar expression , and if it is false, -the calling process is terminated. -A diagnostic message is written to +a diagnostic message is written to .Dv stderr and the function .Xr abort 3 -is called, effectively terminating the program. +is called, effectively terminating the calling process. .Pp If .Ar expression @@ -57,6 +56,22 @@ the .Fn assert macro does nothing. .Pp +In all compilation modes, +.Fn assert +is defined as a macro with an ellipsis parameter, consistent with the +C23 standard. +This allows expressions containing commas to be passed directly without +requiring an extra pair of enclosing parentheses. +Only a single scalar expression is evaluated. +Supplying multiple arguments is prohibited, and hence are top-level comma +operators. +In particular, this guards against accidentally writing +.Fn assert +in the style of +.Fn static_assert , +which would otherwise silently evaluate as always true via the comma +operator. +.Pp The .Fn assert macro @@ -73,7 +88,7 @@ may be included multiple times. Each time whether or not .Dv NDEBUG is defined determines the behavior of assert from that point forward -until the end of the unit or another include of +until the end of the unit or another inclusion of .In assert.h . .Pp The @@ -82,9 +97,9 @@ 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 +In pre-C23 compilation modes .Fn static_assert -macro expands to +is implemented as a macro and expands to .Fn _Static_assert , and, contrarily to .Fn assert , @@ -94,8 +109,14 @@ 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. +the other form with no string literal conforms to C23 standard. +.Pp +In C23 and later, +.Fn static_assert +is a language keyword, and +.Fn _Static_assert +is provided as an obsolescent alternative spelling that should not be +used for new code and development. .Sh EXAMPLES The assertion: .Dl "assert(1 == 0);" @@ -111,7 +132,20 @@ 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. +The following example asserts that the +.Va iov_len +member of the compound literal, reflecting the value of +.Va len , +is non-zero. +The compound literal contains a comma that is not protected by +parentheses, which the variadic +.Fn assert +macro handles transparently: +.Dl assert((struct iovec){ buf, len }.iov_len); +.Pp +The following asserts that the size of the +.Vt 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"");" @@ -123,14 +157,26 @@ If none is provided, it only points at the constraint. The .Fn assert macro conforms to -.St -isoC-99 . +.St -isoC-2023 . .Pp The .Fn static_assert macro conforms to .St -isoC-2011 . +In +.St -isoC-2023 , +it is a language keyword; whether the macro is defined or not +depends on compilation mode. .Sh HISTORY -An +The .Nm -macro appeared in +macro first appeared in .At v7 . +Starting with +.Fx 15.2 , +it accepts a variadic argument list, allowing expressions +containing commas, such as compound literals, to be passed +without requiring extra enclosing parentheses. +This conforms to +.St -isoC-2023 , +but made available in all compilation modes.