On Sun, Jun 1, 2014 at 9:59 PM, Pádraig Brady <p...@draigbrady.com> 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 configured with: $ /home/bwalton/opencsw/coreutils/trunk/work/solaris10-i386/build-isa-pentium_pro/coreutils-8.22/configure --prefix=/opt/csw --exec_prefix=/opt/csw --bindir=/opt/csw/bin --sbindir=/opt/csw/sbin --libexecdir= /opt/csw/libexec --datadir=/opt/csw/share --sysconfdir=/etc/opt/csw --sharedstatedir=/opt/csw/share --localstatedir=/var/opt/csw --libdir=/opt/csw/lib --infodir=/opt/csw/share/info --includedir=/opt/csw/includ e --mandir=/opt/csw/share/man --program-prefix=g --with-libintl-prefix=/opt/csw --with-libiconv-prefix=/opt/csw --enable-no-install-program=chcon,su --enable-install-program=hostname,arch > >> 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. Ok, I hadn't noticed this ability. WIth your suggested followup (prerequisite), I think that it's a better solution. I'll resubmit. Thanks -Ben -- --------------------------------------------------------------------------------------------------------------------------- Take the risk of thinking for yourself. Much more happiness, truth, beauty and wisdom will come to you that way. -Christopher Hitchens ---------------------------------------------------------------------------------------------------------------------------