From: Jakub Jelinek <jakub@redhat.com>
To: Ulrich Drepper <drepper@redhat.com>
Cc: Glibc hackers <libc-hacker@sources.redhat.com>
Subject: [PATCH] Tweak assert -DNDEBUG for the new -Wunused-but-set-{variable,parameter} warnings
Date: Thu, 08 Apr 2010 10:22:00 -0000 [thread overview]
Message-ID: <20100408102141.GO3601@sunsite.ms.mff.cuni.cz> (raw)
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 <jakub@redhat.com>
* 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
next reply other threads:[~2010-04-08 10:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-08 10:22 Jakub Jelinek [this message]
2010-04-08 10:49 ` Andreas Schwab
2010-04-08 17:54 ` Roland McGrath
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100408102141.GO3601@sunsite.ms.mff.cuni.cz \
--to=jakub@redhat.com \
--cc=drepper@redhat.com \
--cc=libc-hacker@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).