bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] lib/rename.c: Conditionally define the out label


From: Pádraig Brady
Subject: Re: [PATCH] lib/rename.c: Conditionally define the out label
Date: Sun, 01 Jun 2014 21:59:29 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2

On 06/01/2014 09:34 AM, Ben Walton wrote:
>   * Avoid possible compiler warnings/errors by defining the out label
>     only when it may be accessed.
> 
> Signed-off-by: Ben Walton <address@hidden>
> ---
> 
> Hi All,
> 
> When building coreutils 8.22 on Solaris with -Werror=unused-label, the build
> fails with:
> 
> lib/rename.c: In function 'rpl_rename':
> lib/rename.c:465:2: error: label 'out' defined but not used 
> [-Werror=unused-label]
>   out:
>   ^

Are you building from a git checkout repo?
Otherwise you should have to configure --enable-gcc-warnings
to get -Werror enabled?

> I think this should make the compiler happier. Feel free to suggest better
> solutions though. I'm not sure this is the best way to handle it.
> 
>  lib/rename.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/lib/rename.c b/lib/rename.c
> index 2116028..9c507c2 100644
> --- a/lib/rename.c
> +++ b/lib/rename.c
> @@ -462,7 +462,14 @@ rpl_rename (char const *src, char const *dst)
>  
>    ret_val = rename (src_temp, dst_temp);
>    rename_errno = errno;
> +
> +# if (RENAME_TRAILING_SLASH_SOURCE_BUG || RENAME_DEST_EXISTS_BUG        \
> +      || RENAME_HARD_LINK_BUG)
> +  /* Avoid compiler warnings about unused labels. Only
> +     create this label if it will be used. */
>   out:
> +# endif
> +

Note one can mark a label as possibly unused like:

  out: _GL_UNUSED;

That's supported on all gcc, and newer g++ since
https://gcc.gnu.org/ml/gcc-patches/2009-05/msg01897.html
So to support compiling with older g++ one could:

  out:
#if (!defined __cplusplus) || __GNUC__ >=  ?
    || (__GNUC__ == ? && __GNUC_MINOR__ >= ?)
 _GL_UNUSED;
#endif

With the ?s filled in as appropriate.

thanks,
Pádraig.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]