If we set -DNDEBUG in CPPFLAGS, fail to build close_fail.c with
-Werror=unused-variable, as close_fail is used only to do assertion.

This patch avoids declaration of close_fail if defined NDEBUG.

$ LC_ALL=C make
make  all-recursive
make[1]: Entering directory '/usr/src/grep-2.21'
Making all in po
make[2]: Entering directory '/usr/src/grep-2.21/po'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/usr/src/grep-2.21/po'
Making all in lib
make[2]: Entering directory '/usr/src/grep-2.21/lib'
make  all-am
make[3]: Entering directory '/usr/src/grep-2.21/lib'
  CC       chdir-long.o
chdir-long.c: In function 'cdb_free':
chdir-long.c:62:12: error: unused variable 'close_fail' 
[-Werror=unused-variable]
       bool close_fail = close (cdb->fd);
            ^
cc1: all warnings being treated as errors
Makefile:1587: recipe for target 'chdir-long.o' failed
make[3]: *** [chdir-long.o] Error 1
make[3]: Leaving directory '/usr/src/grep-2.21/lib'
Makefile:1362: recipe for target 'all' failed
make[2]: *** [all] Error 2
make[2]: Leaving directory '/usr/src/grep-2.21/lib'
Makefile:1254: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/usr/src/grep-2.21'
Makefile:1195: recipe for target 'all' failed
make: *** [all] Error 2

From 998546559e67e8922f70c2ec4be240912a0a37aa Mon Sep 17 00:00:00 2001
From: Norihiro Tanaka <nori...@kcn.ne.jp>
Date: Sat, 20 Dec 2014 14:01:50 +0900
Subject: [PATCH] chdir-long: avoid -Werror=unused-variable with -DNDEBUG

* lib/chdir-long.c: Avoid declaration of close_fail, if defined NDEBUG.
---
 lib/chdir-long.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/chdir-long.c b/lib/chdir-long.c
index 5b1b18f..01be65e 100644
--- a/lib/chdir-long.c
+++ b/lib/chdir-long.c
@@ -59,8 +59,12 @@ cdb_free (struct cd_buf const *cdb)
 {
   if (0 <= cdb->fd)
     {
+#if NDEBUG
+      close (cdb->fd);
+#else
       bool close_fail = close (cdb->fd);
       assert (! close_fail);
+#endif
     }
 }
 
-- 
2.2.0

Reply via email to