[PATCH, libiberty]: Avoid 'right-hand operand of comma expression has no effect' when compiling regex.c
Hello! When compiling regex.c from libiberty, several warnings are emitted: ../../gcc-svn/trunk/libiberty/regex.c: In function 'byte_regex_compile': ../../gcc-svn/trunk/libiberty/regex.c:154:47: warning: right-hand operand of comma expression has no effect [-Wunused-value] # define bzero(s, n) (memset (s, '\0', n), (s)) ^ ../../gcc-svn/trunk/libiberty/regex.c:3126:13: note: in expansion of macro 'bzero' bzero (b, (1 BYTEWIDTH) / BYTEWIDTH); ^ Attached patch changes the return value of the bzero macro to void, as defined in a 4.3BSD: void bzero(void *s, size_t n); As an additional benefit, the changed macro now generates warning when its return value is used (which is *not* the case in regex.c): --cut here-- int *arr; # define bzero(s, n) (memset (s, '\0', n), (void) 0) void test (void) { void *t = bzero (arr, 1); (void) t; } --cut here-- gcc -O2 -Wall bz.c: In function 'test': bz.c:7:27: error: void value not ignored as it ought to be # define bzero(s, n) (memset (s, '\0', n), (void) 0) ^ bz.c:11:13: note: in expansion of macro 'bzero' void *t = bzero (arr, 1); ^ 2014-03-13 Uros Bizjak ubiz...@gmail.com * regex.c (bzero) [!_LIBC]: Change return value to void. Patch was bootstrapped and regression tested on x86_64-pc-linux-gnu. OK for mainline (and release branches, perhaps)? Uros. Index: regex.c === --- regex.c (revision 208529) +++ regex.c (working copy) @@ -151,7 +151,7 @@ char *realloc (); #include string.h #ifndef bzero # ifndef _LIBC -# define bzero(s, n) (memset (s, '\0', n), (s)) +# define bzero(s, n) (memset (s, '\0', n), (void) 0) # else # define bzero(s, n) __bzero (s, n) # endif
Re: [PATCH, libiberty]: Avoid 'right-hand operand of comma expression has no effect' when compiling regex.c
On Thu, Mar 13, 2014 at 3:36 AM, Uros Bizjak ubiz...@gmail.com wrote: Attached patch changes the return value of the bzero macro to void, as defined in a 4.3BSD: void bzero(void *s, size_t n); As an additional benefit, the changed macro now generates warning when its return value is used (which is *not* the case in regex.c): I'm not worried about anybody using the return value incorrectly in this file. I think we should just # define bzero(s, n) memset (s, '\0', n) I'll approve that change if it works. Ian
Re: [PATCH, libiberty]: Avoid 'right-hand operand of comma expression has no effect' when compiling regex.c
On Thu, Mar 13, 2014 at 6:30 PM, Ian Lance Taylor i...@google.com wrote: On Thu, Mar 13, 2014 at 3:36 AM, Uros Bizjak ubiz...@gmail.com wrote: Attached patch changes the return value of the bzero macro to void, as defined in a 4.3BSD: void bzero(void *s, size_t n); As an additional benefit, the changed macro now generates warning when its return value is used (which is *not* the case in regex.c): I'm not worried about anybody using the return value incorrectly in this file. I think we should just # define bzero(s, n) memset (s, '\0', n) I'll approve that change if it works. Attached patch compiles without warnings as well. However, in some case, we have similar situation with unused return value of # define memcpy(d, s, n)(bcopy (s, d, n), (d)) so, I put (void) casts to memcpy call to avoid eventual right-hand operand of comma expression has no effect warnings there. 2014-03-13 Uros Bizjak ubiz...@gmail.com * regex.c (bzero) [!_LIBC]: Define without coma expression. (regerror): Cast the call to memcpy to (void) to avoid unused value warnings. Is this version acceptable for mainline? Uros. Index: ChangeLog === --- ChangeLog (revision 208550) +++ ChangeLog (working copy) @@ -1,3 +1,9 @@ +2014-03-13 Uros Bizjak ubiz...@gmail.com + + * regex.c (bzero) [!_LIBC]: Define without coma expression. + (regerror): Cast the call to memcpy to (void) to avoid unused + value warnings. + 2014-01-28 Thomas Schwinge tho...@codesourcery.com * cp-demangle.c (d_demangle_callback): Put an abort call in place, Index: regex.c === --- regex.c (revision 208550) +++ regex.c (working copy) @@ -151,7 +151,7 @@ char *realloc (); #include string.h #ifndef bzero # ifndef _LIBC -# define bzero(s, n) (memset (s, '\0', n), (s)) +# define bzero(s, n) memset (s, '\0', n) # else # define bzero(s, n) __bzero (s, n) # endif @@ -8093,12 +8093,12 @@ regerror (int errcode, const regex_t *preg ATTRIBU #if defined HAVE_MEMPCPY || defined _LIBC *((char *) mempcpy (errbuf, msg, errbuf_size - 1)) = '\0'; #else - memcpy (errbuf, msg, errbuf_size - 1); + (void) memcpy (errbuf, msg, errbuf_size - 1); errbuf[errbuf_size - 1] = 0; #endif } else -memcpy (errbuf, msg, msg_size); +(void) memcpy (errbuf, msg, msg_size); } return msg_size;
Re: [PATCH, libiberty]: Avoid 'right-hand operand of comma expression has no effect' when compiling regex.c
On Thu, Mar 13, 2014 at 11:24 AM, Uros Bizjak ubiz...@gmail.com wrote: On Thu, Mar 13, 2014 at 6:30 PM, Ian Lance Taylor i...@google.com wrote: On Thu, Mar 13, 2014 at 3:36 AM, Uros Bizjak ubiz...@gmail.com wrote: Attached patch changes the return value of the bzero macro to void, as defined in a 4.3BSD: void bzero(void *s, size_t n); As an additional benefit, the changed macro now generates warning when its return value is used (which is *not* the case in regex.c): I'm not worried about anybody using the return value incorrectly in this file. I think we should just # define bzero(s, n) memset (s, '\0', n) I'll approve that change if it works. Attached patch compiles without warnings as well. However, in some case, we have similar situation with unused return value of # define memcpy(d, s, n)(bcopy (s, d, n), (d)) so, I put (void) casts to memcpy call to avoid eventual right-hand operand of comma expression has no effect warnings there. 2014-03-13 Uros Bizjak ubiz...@gmail.com * regex.c (bzero) [!_LIBC]: Define without coma expression. (regerror): Cast the call to memcpy to (void) to avoid unused value warnings. Is this version acceptable for mainline? This is OK. Thanks. Ian
Re: [PATCH, libiberty]: Avoid 'right-hand operand of comma expression has no effect' when compiling regex.c
On 03/13/2014 10:36 AM, Uros Bizjak wrote: +# define bzero(s, n)(memset (s, '\0', n), (void) 0) AFAICS, the comma operator was only needed because of the intention to return 's'. If 's' is not be returned, then simply # define bzero(s, n) ((void) memset (s, '\0', n)) should work. -- Pedro Alves
Re: [PATCH, libiberty]: Avoid 'right-hand operand of comma expression has no effect' when compiling regex.c
On Thu, Mar 13, 2014 at 10:24 PM, Pedro Alves pal...@redhat.com wrote: On 03/13/2014 10:36 AM, Uros Bizjak wrote: +# define bzero(s, n)(memset (s, '\0', n), (void) 0) AFAICS, the comma operator was only needed because of the intention to return 's'. If 's' is not be returned, then simply # define bzero(s, n) ((void) memset (s, '\0', n)) should work. I think that adding (void) is the best solution. I'll commit this version as soon as bootstrap ends. Thanks, Uros.