Patchwork chg: silence warning of unused parameter 'sig'

login
register
mail settings
Submitter Yuya Nishihara
Date June 28, 2016, 2:30 p.m.
Message ID <6092992b98fa30d9ea30.1467124213@mimosa>
Download mbox | patch
Permalink /patch/15651/
State Accepted
Headers show

Comments

Yuya Nishihara - June 28, 2016, 2:30 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1467121146 -32400
#      Tue Jun 28 22:39:06 2016 +0900
# Node ID 6092992b98fa30d9ea30e0a05f4a7682b99862c6
# Parent  7dce56174916e09be39c690278942b4f7567b3f6
chg: silence warning of unused parameter 'sig'
Jun Wu - June 28, 2016, 8:21 p.m.
This looks good to me. Sorry for my careless. I actually noticed the issue
after sending the patch.

Alternative to the GNU extension "__attribute__", there are 2 common
patterns to silence the warning:

  void handlechildsignal(int /* sig */)

or in the body of the function:
  
  (void)sig;

Excerpts from Yuya Nishihara's message of 2016-06-28 23:30:13 +0900:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1467121146 -32400
> #      Tue Jun 28 22:39:06 2016 +0900
> # Node ID 6092992b98fa30d9ea30e0a05f4a7682b99862c6
> # Parent  7dce56174916e09be39c690278942b4f7567b3f6
> chg: silence warning of unused parameter 'sig'
> 
> diff --git a/contrib/chg/chg.c b/contrib/chg/chg.c
> --- a/contrib/chg/chg.c
> +++ b/contrib/chg/chg.c
> @@ -381,7 +381,7 @@ error:
>      abortmsgerrno("failed to handle stop signal");
>  }
>  
> -static void handlechildsignal(int sig)
> +static void handlechildsignal(int sig UNUSED_)
>  {
>      if (peerpid == 0 || pagerpid == 0)
>          return;
> diff --git a/contrib/chg/util.h b/contrib/chg/util.h
> --- a/contrib/chg/util.h
> +++ b/contrib/chg/util.h
> @@ -12,8 +12,10 @@
>  
>  #ifdef __GNUC__
>  #define PRINTF_FORMAT_ __attribute__((format(printf, 1, 2)))
> +#define UNUSED_ __attribute__((unused))
>  #else
>  #define PRINTF_FORMAT_
> +#define UNUSED_
>  #endif
>  
>  void abortmsg(const char *fmt, ...) PRINTF_FORMAT_;
Yuya Nishihara - June 29, 2016, 12:28 p.m.
On Tue, 28 Jun 2016 21:21:50 +0100, Jun Wu wrote:
> Alternative to the GNU extension "__attribute__", there are 2 common
> patterns to silence the warning:
> 
>   void handlechildsignal(int /* sig */)

It's C++.

> or in the body of the function:
>   
>   (void)sig;

Yes, I sometimes do that if I want to suppress the warning conditionally.
Pierre-Yves David - June 30, 2016, 1:12 a.m.
I've pushed this based on jun review. Thanks.

On 06/29/2016 02:28 PM, Yuya Nishihara wrote:
> On Tue, 28 Jun 2016 21:21:50 +0100, Jun Wu wrote:
>> Alternative to the GNU extension "__attribute__", there are 2 common
>> patterns to silence the warning:
>>
>>   void handlechildsignal(int /* sig */)
> 
> It's C++.
> 
>> or in the body of the function:
>>   
>>   (void)sig;
> 
> Yes, I sometimes do that if I want to suppress the warning conditionally.
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>

Patch

diff --git a/contrib/chg/chg.c b/contrib/chg/chg.c
--- a/contrib/chg/chg.c
+++ b/contrib/chg/chg.c
@@ -381,7 +381,7 @@  error:
 	abortmsgerrno("failed to handle stop signal");
 }
 
-static void handlechildsignal(int sig)
+static void handlechildsignal(int sig UNUSED_)
 {
 	if (peerpid == 0 || pagerpid == 0)
 		return;
diff --git a/contrib/chg/util.h b/contrib/chg/util.h
--- a/contrib/chg/util.h
+++ b/contrib/chg/util.h
@@ -12,8 +12,10 @@ 
 
 #ifdef __GNUC__
 #define PRINTF_FORMAT_ __attribute__((format(printf, 1, 2)))
+#define UNUSED_ __attribute__((unused))
 #else
 #define PRINTF_FORMAT_
+#define UNUSED_
 #endif
 
 void abortmsg(const char *fmt, ...) PRINTF_FORMAT_;