Hi Collin,

>     gcc -DHAVE_CONFIG_H -I. -I..  -DGNULIB_STRICT_CHECKING=1   -Wshadow -MT 
> mbrtoc32.o -MD -MP -MF .deps/mbrtoc32.Tpo -c -o mbrtoc32.o mbrtoc32.c
>     mbrtoc32.c: In function ‘rpl_mbrtoc32’:
>     mbrtoc32.c:228:23: warning: declaration of ‘c’ shadows a previous local 
> [-Wshadow]
>       228 |         unsigned char c = (unsigned char) p[0];
>           |                       ^
>     In file included from mbrtoc32.c:214:
>     mbrtowc-impl-utf8.h:23:23: note: shadowed declaration is here
>        23 |         unsigned char c = (unsigned char) p[0];
>           |                       ^
>     mv -f .deps/mbrtoc32.Tpo .deps/mbrtoc32.Po
>     gcc -DHAVE_CONFIG_H -I. -I..  -DGNULIB_STRICT_CHECKING=1   -Wshadow -MT 
> mbrtowc.o -MD -MP -MF .deps/mbrtowc.Tpo -c -o mbrtowc.o mbrtowc.c
>     mbrtowc.c: In function ‘rpl_mbrtowc’:
>     mbrtowc.c:213:23: warning: declaration of ‘c’ shadows a previous local 
> [-Wshadow]
>       213 |         unsigned char c = (unsigned char) p[0];
>           |                       ^
>     In file included from mbrtowc.c:199:
>     mbrtowc-impl-utf8.h:23:23: note: shadowed declaration is here
>        23 |         unsigned char c = (unsigned char) p[0];
>           |                       ^
>     mv -f .deps/mbrtowc.Tpo .deps/mbrtowc.Po
> 
> 
> The code is fine as-is, but I like to avoid shadowing since it can
> sometimes cause confusion.

Yes, -Wshadow=local warnings ought to be fixed. (-Wshadow=global warnings can
stay; it is OK to have local variables named 'index' and such.)

> What do you think? Proposed patch attached.

I find it better to be consistent with the two other places where this file
is #included:


2026-04-06  Bruno Haible  <[email protected]>

        mbrtowc, mbrtoc32: Silence -Wshadow warnings (regr. 2026-04-02).
        Reported by Collin Funk.
        * lib/mbrtowc.c (rpl_mbrtowc): Enclose the #include in a block.
        * lib/mbrtoc32.c (mbrtoc32): Likewise.

diff --git a/lib/mbrtoc32.c b/lib/mbrtoc32.c
index 855902a454..7d691b8b2f 100644
--- a/lib/mbrtoc32.c
+++ b/lib/mbrtoc32.c
@@ -209,9 +209,10 @@ mbrtoc32 (char32_t *pwc, const char *s, size_t n, 
mbstate_t *ps)
       /* Here m > 0.  */
 
       int res;
-
+      {
 #  define FITS_IN_CHAR_TYPE(wc)  1
 #  include "mbrtowc-impl-utf8.h"
+      }
 
      success:
       /* res >= 0 is the corrected return value of
diff --git a/lib/mbrtowc.c b/lib/mbrtowc.c
index 064433163e..59320cd51c 100644
--- a/lib/mbrtowc.c
+++ b/lib/mbrtowc.c
@@ -194,9 +194,10 @@ rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, 
mbstate_t *ps)
       /* Here m > 0.  */
 
       int res;
-
+      {
 #  define FITS_IN_CHAR_TYPE(wc)  ((wc) <= WCHAR_MAX)
 #  include "mbrtowc-impl-utf8.h"
+      }
 
      success:
       /* res >= 0 is the corrected return value of




Reply via email to