From nobody Wed Jun 10 17:58:17 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 4gbD6673PCz6gtwy for ; Wed, 10 Jun 2026 17:58: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 "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4gbD665ltDz3vLK for ; Wed, 10 Jun 2026 17:58:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1781114302; 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=JSyH+1BQx2iypQrYQmorEaWK5t4huBwdsqtNaRb9xIk=; b=xFBgCCsENSUTDkW7LBCCw2AvbWmGn16BGoGNda7znvOUeowHg1jEvPQ90Bz0GyB1hULgYV DEGFlcaildjo6fZAcpzYqc5ewUZ3o/dNn2IgJ34uD38VqRqXdSZymYvUSrBgw2NcNlPFuL xg4r48Xi/x5nuxCIdTF3fBYFyX/+Iiv5QTdWn6ev3quh7KPTdMNwtie9dAwIro0VStwC8S n6h9ofH1tfe4LUVbuEj4UAs94WAsG38nMf4wuEoGmk/F9UzOlCNDqGVfwyNA/P20JVHnVi E7eE5tAfP2aL2MJi7fGwM6ExLMacUOvEtjyZbpKhhQ6ao4OVnFt34a+NOFe1xg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1781114302; a=rsa-sha256; cv=none; b=lTdUKawlCyd96ICGpGzWeuMnycVeJ504P1DpEEN2HyOkSAlXy5ALvbRMjrOWLpWNWen0Uq LQL+pK8PPEzX2zWej8ns7yWixAY5IuAKOyrdltu/zvGsNwhVF+g0ppJbfD1LUMSog1p0ur pv3EELtTYDGWz8ZUJQE31bVpYwoHC5IctAI9CrkcFuPziwvqQbb3snObHb9cMMcuW2t3Xc xdxnrAfnzsP2WLQJY0/pRoHMSBM4pNMWrpIFaD+egw+2w5X+i5X+Pxu8w2tdofO76kJq3F VdU9HZA7NFYH6VLkpxbZ5lWosO77nUjGShKdLLxh/UPbR4A51RiyKs/jhKjokg== 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=1781114302; 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=JSyH+1BQx2iypQrYQmorEaWK5t4huBwdsqtNaRb9xIk=; b=ZkmKlCUsgu/8bhkCkHdGpfq1PCgMm3juOFV4WO6rDP+5AFCOI6IFilkjrpPicslssP9nb2 lH6xGArG1QyNbJS9BVF8YkT3EB9xwRcdAFlCNaf/oj7aQfcmvEzsGKq5608o3MSIRN1clN d1cfZzLo2M9yo/Q0UWiJ61gcC1EuEONfx6cv5ESZ/v52TzB5sQr4P+t2HxYPa6cZwlaK3P jHJJwd99OdFqWvbAW7WDtufXKCXsgdyfU929J8XUAJWZm7NI+cD9PebS1vP64XQIbBOvrq ogn9REd/4dEa/bURjuyFjvSJU8AIFmQ9cErWJGMp8ukSWWXA+ik/QVCM4S/uqw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gbD665JLcznm for ; Wed, 10 Jun 2026 17:58:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3fa1d by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 10 Jun 2026 17:58:17 +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: 48d20fd1cf90 - main - libc: Fix assert() sanitiser for C++ contextual bool conversion 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: 48d20fd1cf90179e778c6155900cbed2be140273 Auto-Submitted: auto-generated Date: Wed, 10 Jun 2026 17:58:17 +0000 Message-Id: <6a29a5b9.3fa1d.2a738968@gitrepo.freebsd.org> The branch main has been updated by fuz: URL: https://cgit.FreeBSD.org/src/commit/?id=48d20fd1cf90179e778c6155900cbed2be140273 commit 48d20fd1cf90179e778c6155900cbed2be140273 Author: Faraz Vahedi AuthorDate: 2026-06-06 11:38:47 +0000 Commit: Robert Clausecker CommitDate: 2026-06-10 16:14:32 +0000 libc: Fix assert() sanitiser for C++ contextual bool conversion Replace the `(bool(*)(bool))` probe in `__assert_sanitize()` with an unevaluated conditional expression, so types with `explicit operator bool()` that require a contextually converted constant expression of type `bool` are handled correctly. Ergo, arity check is now performed separately via `__assert_sanitize_arity()`, a unary template whose parameter pack must bind to exactly on argument after `__VA_ARGS__` is substituted into the call. Also align NDEBUG with C23 requirements. Reported by: dim, aokblast Signed-off-by: Faraz Vahedi Reviewed by: aokblast, fuz MFC after: 1 week Fixes: 867b51452ea78ece0b312a387e63fdbc2a11056a Pull Request: https://github.com/freebsd/freebsd-src/pull/2265 --- include/assert.h | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/include/assert.h b/include/assert.h index d4c9627bf3ea..afbf2c1092e0 100644 --- a/include/assert.h +++ b/include/assert.h @@ -46,42 +46,22 @@ #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 #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 */ +#define assert(...) ((void)(bool(__VA_ARGS__) ? ((void)0) : \ + __assert(__func__, __FILE__, __LINE__, \ + #__VA_ARGS__))) #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__, \ +#define assert(...) ((void)sizeof(((_Bool(*)(_Bool))0)(__VA_ARGS__)), \ + (__VA_ARGS__) ? (void)0 : \ + __assert(__func__, __FILE__, \ __LINE__, #__VA_ARGS__)) +#endif /* __cplusplus */ #define _assert(...) assert(__VA_ARGS__) #if __BSD_VISIBLE #define __assert_unreachable() assert(0 && "unreachable segment reached")