From nobody Mon Jun 29 10:11:21 2026 X-Original-To: dev-commits-src-all@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 4gphrV6pKNz6kMsB 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 4gphrT6cQyz3cLl for ; Mon, 29 Jun 2026 10:11:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1782727881; 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=rWlKnrJbF38vKLx7u/DV4Dk0z9DCqqLO5kJvePh0tEDT/xekRuHqA3uuM9a4Hz/LyVdiaK BdB2gPRl/40aEbrl5aJ3I0R8NSNe9VRfBFokCREpGJC8WBrVKtfiVcvEK/o80J4fzSGm2F XlD4PcQJ/cCi1f/C3iAHdp1CDDI9KO8VIrCPuUK7+lym3Apl0dJdY5i53E8iwr/jIe5ZBu kG8uh4tkVRJPoUgjylAsU4LNwRCQtbD+DTgFVBvYx1Ax58AsFXLSiqWzIqCex2nE4zvj+f /xwp8SMeMYNMSKhb0X5sLcfirEkrbekeeNAAMVbGW5uZRodyNB4LWtX0SxcEDA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1782727881; a=rsa-sha256; cv=none; b=yaiI+Qu2z0ncmws79By8dZU7vpCgSV6rq3/KHmNfbCLWoyt0uRkOveiF6LbAm1azRezuOz atzNY3XPd+5Pt954sQ93cOZoA5XV2oAG5FXw7wYwjcs5wJimoh6t3Iwrdff8//HHPmi0Ej r/mTzpmQW10/BFrkulA9hZ7sW4UZuvDf6/0yewv9SRgDg5BdoKYgqzQxNUGKrVHoortTEk Kb/WOu5wzhlWgzIaSEaz+r7nR/byFhTeBhaW6SGbGzc/hYjkNJYdECoOPFwadW3fq5Zh+w 3TCnAG/EGvvH+oKts5zt9VqfpEvXkM4CnfsRuIa99r5Lt4IFkLKmcv0hLCqYFQ== 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=1782727881; 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=tdOrtf5uVhcoswYALDAGQ8lF9CEj3/Tu4JWcJcVVwjo+tDxRsGOPrzy+nihnmDBrY4NFgB 7hm5USx/mar2CvX1j/hf1ed+7JmA/hs1T/2WtDliYY6OfCViYk4gjiIM2wiHQYhKqhUmcB BSCQviwBYjkFUx2TUrsOGt+MQKjM8d2JmofRIuCz5NNlOabWDAP6DaMT26s0htleznXfSG CfmSsshnrT6s/JBJZY6gms+M7TETT+cQAOQkrAIgdYMsN/D67gj3bf10GgSLGmvRU9OIGg TDR/hY1eHj59zagdhFzMXVb5HYxrIAl1IiqFIviNTGVYBjhePDJkEJKsY5t7FQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gphrT5htdzsy4 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: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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.