From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24530 invoked by alias); 8 Apr 2010 10:22:07 -0000 Received: (qmail 24426 invoked by uid 22791); 8 Apr 2010 10:22:06 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 08 Apr 2010 10:22:00 +0000 Received: from sunsite.mff.cuni.cz (localhost [127.0.0.1]) by sunsite.mff.cuni.cz (8.14.3/8.14.3) with ESMTP id o38ALfUB014560; Thu, 8 Apr 2010 12:21:41 +0200 Received: (from jj@localhost) by sunsite.mff.cuni.cz (8.14.3/8.14.3/Submit) id o38ALfjc014559; Thu, 8 Apr 2010 12:21:41 +0200 Date: Thu, 08 Apr 2010 10:22:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] Tweak assert -DNDEBUG for the new -Wunused-but-set-{variable,parameter} warnings Message-ID: <20100408102141.GO3601@sunsite.ms.mff.cuni.cz> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.19 (2009-01-05) Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2010-04/txt/msg00002.txt.bz2 Hi! I've yesterday committed to GCC trunk a patch to support new -Wunused-but-set-{variable,parameter} warnings where GCC warns about variables that have been just set but not really used. This can create unwanted warnings with current definition of assert and -DNDEBUG - people often do something like: void foo (void) { int r; r = bar (); assert (r != 6); } The variable is set and used without -DNDEBUG, but with it if assert expands just to (void) 0 then it is just set but not used. The following patch shouldn't result in worse code generation (not even with -O0 I believe) with -DNDEBUG, should quiet that warning and also allow some checking of expr. With -DNDEBUG assert will happily accept even syntax errors within its arguments etc., which would only show up without -DNDEBUG, this patch ought to cure that too. Alternative to the 0 && (expr) could be sizeof (expr) or something else where the expression isn't evaluated, but is parsed. 2010-04-08 Jakub Jelinek * assert/assert.h [NDEBUG] (assert, assert_perror): Include the argument after "0 &&". --- libc/assert/assert.h.jj 2009-05-16 19:23:29.000000000 +0200 +++ libc/assert/assert.h 2010-04-08 12:10:06.000000000 +0200 @@ -1,4 +1,4 @@ -/* Copyright (C) 1991,1992,1994-2001,2003,2004,2007 +/* Copyright (C) 1991,1992,1994-2001,2003,2004,2007,2010 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -49,7 +49,7 @@ #ifdef NDEBUG -# define assert(expr) (__ASSERT_VOID_CAST (0)) +# define assert(expr) (__ASSERT_VOID_CAST (0 && (expr))) /* void assert_perror (int errnum); @@ -58,7 +58,7 @@ (This is a GNU extension.) */ # ifdef __USE_GNU -# define assert_perror(errnum) (__ASSERT_VOID_CAST (0)) +# define assert_perror(errnum) (__ASSERT_VOID_CAST (0 && (errnum))) # endif #else /* Not NDEBUG. */ Jakub