bug-gnulib
[Top][All Lists]
Advanced

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

test-verify.c: avoid -Wshadow warnings


From: Jim Meyering
Subject: test-verify.c: avoid -Wshadow warnings
Date: Sat, 19 Sep 2020 19:29:27 -0700

I noticed a new build failure in coreutils when configuring with 
--enable-gcc-warnings.
Fixed with the attached. Tested with the following. Fails before, succeeds 
after:

  CFLAGS='-Werror -Wshadow' ./gnulib-tool --create-testdir --test --dir /tmp/x 
--with-tests verify

Symptoms:
...
gcc -DHAVE_CONFIG_H -I. -I../../gltests  -DGNULIB_STRICT_CHECKING=1 -I. 
-I../../gltests -I.. -I../../gltests/.. -I../gllib -I../../gltests/../gllib   
-Werror -Wshadow -MT test-verify.o -MD -MP -MF .deps/test-verify.Tpo -c -o 
test-verify.o ../../gltests/test-verify.c
../../gltests/test-verify.c: In function ‘f’:
../../gltests/test-verify.c:76:8: error: declaration of ‘a’ shadows a global 
declaration [-Werror=shadow]
   76 | f (int a)
      |    ~~~~^
../../gltests/test-verify.c:31:8: note: shadowed declaration is here
   31 | enum { a, b, c };
      |        ^
../../gltests/test-verify.c: In function ‘test_assume_optimization’:
../../gltests/test-verify.c:94:31: error: declaration of ‘x’ shadows a global 
declaration [-Werror=shadow]
   94 | test_assume_optimization (int x)
      |                           ~~~~^
../../gltests/test-verify.c:30:5: note: shadowed declaration is here
   30 | int x;
      |     ^

>From 40518bb8dee997613ebabc05331b6701870bdf01 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@fb.com>
Date: Sat, 19 Sep 2020 19:24:42 -0700
Subject: [PATCH] test-verify.c: avoid -Wshadow warnings

* tests/test-verify.c (gx): Rename global from "x". Adjust use.
(enum): Capitalize member names. Adjust uses.
---
 ChangeLog           |  6 ++++++
 tests/test-verify.c | 10 +++++-----
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f094e97f1..541f5d7a4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2020-09-19  Jim Meyering  <meyering@fb.com>
+
+       test-verify.c: avoid -Wshadow warnings
+       * tests/test-verify.c (gx): Rename global from "x". Adjust use.
+       (enum): Capitalize member names. Adjust uses.
+
 2020-09-19  Bruno Haible  <bruno@clisp.org>

        havelib: Avoid linking with libc.a on GNU systems.
diff --git a/tests/test-verify.c b/tests/test-verify.c
index 7201ca1ff..05e113c0a 100644
--- a/tests/test-verify.c
+++ b/tests/test-verify.c
@@ -27,13 +27,13 @@

 /* ======================= Test verify, verify_expr ======================= */

-int x;
-enum { a, b, c };
+int gx;
+enum { A, B, C };

 #if EXP_FAIL == 1
-verify (x >= 0);                  /* should give ERROR: non-constant 
expression */
+verify (gx >= 0);                 /* should give ERROR: non-constant 
expression */
 #endif
-verify (c == 2);                  /* should be ok */
+verify (C == 2);                  /* should be ok */
 #if EXP_FAIL == 2
 verify (1 + 1 == 3);              /* should give ERROR */
 #endif
@@ -50,7 +50,7 @@ function (int n)
 #if EXP_FAIL == 3
   verify (n >= 0);                  /* should give ERROR: non-constant 
expression */
 #endif
-  verify (c == 2);                  /* should be ok */
+  verify (C == 2);                  /* should be ok */
 #if EXP_FAIL == 4
   verify (1 + 1 == 3);              /* should give ERROR */
 #endif
-- 
2.28.0.497.g54e85e7af1


reply via email to

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