From nobody Sat May 30 13:44:28 2026 X-Original-To: dev-commits-src-main@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 4gSM0D5dycz6fxpQ for ; Sat, 30 May 2026 13:44:28 +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 "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4gSM0D2FBxz3Xrb for ; Sat, 30 May 2026 13:44:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1780148668; 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=ptAXkj3dg3/+OzRGmX6e9UKzgYni/+io+6mQCs1Nrj8=; b=bDDQl9/xGBO9H1Qm27tS/AqwRvWTobnsJR/Zo/YzGXgDuVk8r2tSwvmsWWq+ETB5kZhmyc jcjOmgPoS0ZXHjLjkgY7LdlTm7JIoG9HJakQOg6OM1Bqh7J7ldZ1a1bdvuSmy05kBHg4Tt Frhnycdd3PW8jBmVObVuVEDTp2fFNZdnjt0cZaMvd3xPjr8iZsQdk93TZ70Nz7OWCRMVHl l/iL2Xls564OTdDIxlJn2I+psLtn3xnSDMhgWBlH5LfwdxVMIj4tZ2oon6YQV88sjURk2f h1Qn+sCAUF5JS8sOwUAOKVPkQWuUp03mCqyMG3BxVLfMsHUcNsSwQXZg3PAURQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1780148668; a=rsa-sha256; cv=none; b=p6OMJ34GFCWAXY0enjm5jnkjbqZR9Ml7By0p2NhU3qY3VEWYwXt9BGlCJMMsCp05JUCdvG Vdo3u4ZLV8G1u3mUBnj5ZWew+rznj0xI6fafXR5P5vAr9w6uQC3PFHbbKgZXDKK4aUAIfr OZX9iVos4WhB48s2bncGgnt/mxH9TQcaJ5LO4jP0w/aggC8zIMwjarsoBC3REE15a27kdN q85IGSAlW14Uz/KxbPpihTsrjCsPCyazjJ8Wu+WTo8P1X3UvSEc1w7cHlgdY0w697elrEh /OayowqsdgDyEkCXhQ2UcC1wPfUyBPUd74rpJUdw22BSrOJsN4zsLjF+sW8s2Q== 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=1780148668; 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=ptAXkj3dg3/+OzRGmX6e9UKzgYni/+io+6mQCs1Nrj8=; b=rj+TRMN5l3xRqYRyncOQ1r9FhP1vVrbpJRodzKMH2Se4E15vIYiHBcxFCV8wzmqBMWLUGf J+AsXJGALQnuDIFxStMq0za0K3uFKwnWeiNDTc5E/9RvV6bQYoJiD41ddiYrnXt94dp5dc /HmncuVaSxboSXmg74YUap/E6SHvQEH1fDULbIS2Z1T2QY2N/aUDPg1z8r0+gJsyfwliLw 6BrvE5+93Ut1IWbMZy1/lOUzZbZei0U4cHQKcwZ0rduyrvn18wPcdtGf/v+NPanIEiR0it AWtWXXfFnkNafcnmetsEeC2XQOPaYxIJaBVXf9U1eR4WBvNRu+pyZVE698cBtw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gSM0D1rjxz1LhC for ; Sat, 30 May 2026 13:44:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 27dc1 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sat, 30 May 2026 13:44:28 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: Faraz Vahedi From: Robert Clausecker Subject: git: 867b51452ea7 - main - libc: Add variadic assert in accordance with C23 List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 867b51452ea78ece0b312a387e63fdbc2a11056a Auto-Submitted: auto-generated Date: Sat, 30 May 2026 13:44:28 +0000 Message-Id: <6a1ae9bc.27dc1.4cecadc6@gitrepo.freebsd.org> The branch main has been updated by fuz: URL: https://cgit.FreeBSD.org/src/commit/?id=867b51452ea78ece0b312a387e63fdbc2a11056a commit 867b51452ea78ece0b312a387e63fdbc2a11056a Author: Faraz Vahedi AuthorDate: 2026-05-28 07:31:29 +0000 Commit: Robert Clausecker CommitDate: 2026-05-30 13:43:51 +0000 libc: Add variadic assert in accordance with C23 Signed-off-by: Faraz Vahedi Reviewed by: fuz MFC after: 1 month Pull Request: https://github.com/freebsd/freebsd-src/pull/2203 --- include/assert.h | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/include/assert.h b/include/assert.h index 7dd48e61c082..159efacfa45b 100644 --- a/include/assert.h +++ b/include/assert.h @@ -46,16 +46,43 @@ #undef __assert_unreachable #ifdef NDEBUG -#define assert(e) ((void)0) -#define _assert(e) ((void)0) +#define assert(...) ((void)0) +#define _assert(...) ((void)0) #if __BSD_VISIBLE #define __assert_unreachable() __unreachable() #endif /* __BSD_VISIBLE */ #else -#define _assert(e) assert(e) - -#define assert(e) ((e) ? (void)0 : __assert(__func__, __FILE__, \ - __LINE__, #e)) +#ifdef __cplusplus +#if __cplusplus < 202002L +/* + * C++ modes prior to C++20 cannot simultaneously satisfy all three + * desirable properties of the sanitiser: + * + * Approach No double-eval Lambda support Arity check + * ----------------------------- -------------- -------------- ----------- + * sizeof(cast(expression)) yes no yes + * static_cast(expression) no yes no + * (void)bool(expression) no yes no + * + * NOTE: C++20 introduced lambdas in unevaluated contexts; see P0315R4. + * + * Since no approach satisfies all three below C++20, the least harmful + * choice is to forgo the check entirely rather than silently break one + * of the remaining guarantees. + * + */ +#define __assert_sanitize(...) ((void)0) +#else +#define __assert_sanitize(...) (void)sizeof(((bool(*)(bool))0)(__VA_ARGS__)) +#endif /* __cplusplus < 202002L */ +#else +#define __assert_sanitize(...) (void)sizeof(((_Bool(*)(_Bool))0)(__VA_ARGS__)) +#endif /* __cplusplus */ +#define assert(...) (__assert_sanitize(__VA_ARGS__), \ + (__VA_ARGS__) ? (void)0 : \ + __assert(__func__, __FILE__, \ + __LINE__, #__VA_ARGS__)) +#define _assert(...) assert(__VA_ARGS__) #if __BSD_VISIBLE #define __assert_unreachable() assert(0 && "unreachable segment reached") #endif /* __BSD_VISIBLE */ @@ -76,7 +103,8 @@ * C23 defines static_assert and its obsolescent alternative spelling, * _Static_assert, as keywords. */ -#if __ISO_C_VISIBLE >= 2011 && __ISO_C_VISIBLE < 2023 && !defined(__cplusplus) +#if __ISO_C_VISIBLE >= 2011 && !defined(__cplusplus) && \ + __STDC_VERSION__ < 202311L #define static_assert _Static_assert #endif