On 06/01/2014 09:59 PM, Pádraig Brady wrote: > 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 <bdwal...@gmail.com> >> --- >> >> 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.
Actually the above should be abstracted away from rename.c, So you can instead do: out: _GL_UNUSED_LABEL I'll apply the following to gnulib-common.m4 to support that: +/* gcc supports the "unused" attribute on possibly unused labels, and + g++ has since version 4.5. */ +#if !defined __cplusplus || __GNUC__ > 4 \ + || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) +# define _GL_UNUSED_LABEL _GL_UNUSED; +#else +# define _GL_UNUSED_LABEL +#endif thanks, Pádraig.