This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Kill 4 warnings, assert()


Jakub Jelinek wrote:

> --- libc/iconvdata/iso-2022-jp-3.c.jj   Mon Jul  1 12:31:43 2002
> +++ libc/iconvdata/iso-2022-jp-3.c      Mon Jul  1 13:53:09 2002
> @@ -109,9 +109,8 @@ enum
>                     {                                                         \
>                       /* Write out the shift sequence before the last         \
>                          character.  */                                       \
> -                     int set = data->__statep->__count & CURRENT_SEL_MASK;   \
> -                                                                             \
> -                     assert (set == JISX0208_1983_set);                      \
> +                     assert ((data->__statep->__count & CURRENT_SEL_MASK)    \
> +                             == JISX0208_1983_set);                          \
>                       *outbuf++ = ESC;                                        \
>                       *outbuf++ = '$';                                        \
>                       *outbuf++ = 'B';                                        \


The problem is not specific to iso-2022-jp-3.c, it appears often
anywhere 'assert' is used. The fix should be in the assert macro.
We can use 'sizeof' to avoid the "unused variable" warnings.


--- glibc-20020425/assert/assert.h.bak	Tue Jul 10 22:57:40 2001
+++ glibc-20020425/assert/assert.h	Wed Jul  3 23:14:50 2002
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991,1992,1994-1999,2000,2001 Free Software Foundation, Inc.
+/* Copyright (C) 1991,1992,1994-1999,2000-2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -48,7 +48,7 @@
 
 #ifdef	NDEBUG
 
-# define assert(expr)		(__ASSERT_VOID_CAST (0))
+# define assert(expr)		(__ASSERT_VOID_CAST (sizeof (expr)))
 
 /* void assert_perror (int errnum);
 
@@ -57,9 +57,13 @@
    (This is a GNU extension.) */
 
 # ifdef	__USE_GNU
-#  define assert_perror(errnum)	(__ASSERT_VOID_CAST (0))
+#  define assert_perror(errnum)	(__ASSERT_VOID_CAST (sizeof (errnum)))
 # endif
 
+/* The use of 'sizeof' above ensures that EXPRESSION and ERRNUM don't get
+   evaluated, and still variables only used by EXPRESSION don't trigger
+   gcc warnings about "unused variable".  */
+
 #else /* Not NDEBUG.  */
 
 __BEGIN_DECLS


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]