From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 19829 invoked from network); 24 May 2023 14:02:52 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 24 May 2023 14:02:52 -0000 Received: (qmail 31991 invoked by uid 550); 24 May 2023 14:01:36 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 31767 invoked from network); 24 May 2023 14:01:33 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=message-id:in-reply-to:references:from:date:to: resent-date:resent-from:subject:resent-message-id: resent-to; bh=GbkgOTgeLrNEcSEKmMktY9rD7uUxFY6/MDS/lD/Aqnk=; b=AEm3EuSOcntJjzzTs/oOQ9K5q+odCD0H4FFOPiay+/i+y6QQeHn0zd5T 8RBT6FlLHgjEZKPC+QvCwC5KX43jXhwccdt1XJ727j8fD0XCp14/ABmYT 11a5hlmxhr+atU6qNIczAKJLWHi+isVo/limOFeNNnp/tXbP/Q10gAxDO c=; Authentication-Results: mail3-relais-sop.national.inria.fr; dkim=none (message not signed) header.i=none; spf=SoftFail smtp.mailfrom=jens.gustedt@inria.fr; dmarc=fail (p=none dis=none) d=inria.fr X-IronPort-AV: E=Sophos;i="6.00,189,1681164000"; d="scan'208";a="56883724" Message-Id: <1fb2486a2f84e40acb728524b0f074d6ce073602.1684932861.git.Jens.Gustedt@inria.fr> In-Reply-To: References: From: Jens Gustedt Date: Wed, 19 Apr 2023 14:17:04 +0200 To: musl@lists.openwall.com Resent-Date: Wed, 24 May 2023 15:58:30 +0200 Resent-From: =?UTF-8?B?SuKCkeKCmeKCmw==?= Gustedt Resent-Message-ID: <20230524155830.50d64f65@inria.fr> Resent-To: musl@lists.openwall.com Subject: [musl] [C23 divers headers 12/17] C23: change the assert macro to ... arguments Macro arguments are ambiguate fellows. A single C expression such as (struct toto){ 1, 2}.a appears as two macro arguments. This mandatory change has the macro accept an unlimited number of macro-parameters, but which then must resolve to a single C expression. This is achieved by squeezing the argument list through a trivial function call to a static function. By that we ensure that lists that represent more than one expression (such as `1, 2`) and empty lists are diagnosed. --- include/assert.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/assert.h b/include/assert.h index 71007a10..034c4aa7 100644 --- a/include/assert.h +++ b/include/assert.h @@ -2,10 +2,17 @@ #undef assert +// Ensure that this version only accepts arguments that resolve to one +// C expression after preprocessing. +#ifndef __ASSERT_EXPRESSION +#define __ASSERT_EXPRESSION(...) __assert_expression(__VA_ARGS__) +static inline _Bool __assert_expression(_Bool __x) { return __x; } +#endif + #ifdef NDEBUG -#define assert(x) (void)0 +#define assert(...) (void)0 #else -#define assert(x) ((void)((x) || (__assert_fail(#x, __FILE__, __LINE__, __func__),0))) +#define assert(...) ((void)(__ASSERT_EXPRESSION(__VA_ARGS__) || (__assert_fail(#__VA_ARGS__, __FILE__, __LINE__, __func__),0))) #endif #if __STDC_VERSION__ >= 201112L && __STDC_VERSION__ < 202311L && !defined(__cplusplus) -- 2.34.1