Paul Eggert wrote on 2026-04-24:
> * lib/uchar.in.h: On GNUish platforms, include <stdint.h>,
> <wchar.h>, <wctype.h> only if needed.
This causes a compilation error in a testdir for the modules
mbrtowc mbsrtowcs mbsnrtowcs mbsrtoc32s mbsnrtoc32s
on a GNU system:
gcc -DHAVE_CONFIG_H -I. -I../../gllib -I.. -DGNULIB_STRICT_CHECKING=1
-I/inst-x86_64-64/include -Wall -g -O2 -MT mbrtoc32.o -MD -MP -MF
.deps/mbrtoc32.Tpo -c -o mbrtoc32.o ../../gllib/mbrtoc32.c
In file included from ../../gllib/mbrtoc32.c:22:
./uchar.h: In function ‘mbsnrtoc32s’:
./uchar.h:1340:10: error: implicit declaration of function ‘mbsnrtowcs’; did
you mean ‘mbsnrtoc32s’? [-Wimplicit-function-declaration]
1340 | mbsnrtowcs ((wchar_t *) dest, srcp, srclen, len, ps);
| ^~~~~~~~~~
| mbsnrtoc32s
./uchar.h:1340:23: error: ‘wchar_t’ undeclared (first use in this function)
1340 | mbsnrtowcs ((wchar_t *) dest, srcp, srclen, len, ps);
| ^~~~~~~
./uchar.h:46:1: note: ‘wchar_t’ is defined in header ‘<stddef.h>’; this is
probably fixable by adding ‘#include <stddef.h>’
45 | # include_next <uchar.h>
+++ |+#include <stddef.h>
46 | #endif
./uchar.h:1340:23: note: each undeclared identifier is reported only once for
each function it appears in
1340 | mbsnrtowcs ((wchar_t *) dest, srcp, srclen, len, ps);
| ^~~~~~~
./uchar.h:1340:32: error: expected expression before ‘)’ token
1340 | mbsnrtowcs ((wchar_t *) dest, srcp, srclen, len, ps);
| ^
./uchar.h: In function ‘mbsrtoc32s’:
./uchar.h:1370:10: error: implicit declaration of function ‘mbsrtowcs’; did you
mean ‘mbsrtoc32s’? [-Wimplicit-function-declaration]
1370 | mbsrtowcs ((wchar_t *) dest, srcp, len, ps);
| ^~~~~~~~~
| mbsrtoc32s
./uchar.h:1370:22: error: ‘wchar_t’ undeclared (first use in this function)
1370 | mbsrtowcs ((wchar_t *) dest, srcp, len, ps);
| ^~~~~~~
./uchar.h:1370:22: note: ‘wchar_t’ is defined in header ‘<stddef.h>’; this is
probably fixable by adding ‘#include <stddef.h>’
./uchar.h:1370:31: error: expected expression before ‘)’ token
1370 | mbsrtowcs ((wchar_t *) dest, srcp, len, ps);
| ^
In file included from ./wchar.h:77,
from ../../gllib/mbrtoc32.c:89:
/usr/include/wchar.h: At top level:
/usr/include/wchar.h:362:15: error: conflicting types for ‘mbsrtowcs’; have
‘size_t(wchar_t * restrict, const char ** restrict, size_t, mbstate_t *
restrict)’ {aka ‘long unsigned int(int * restrict, const char ** restrict,
long unsigned int, mbstate_t * restrict)’}
362 | extern size_t mbsrtowcs (wchar_t *__restrict __dst,
| ^~~~~~~~~
./uchar.h:1370:10: note: previous implicit declaration of ‘mbsrtowcs’ with type
‘int()’
1370 | mbsrtowcs ((wchar_t *) dest, srcp, len, ps);
| ^~~~~~~~~
/usr/include/wchar.h:376:15: error: conflicting types for ‘mbsnrtowcs’; have
‘size_t(wchar_t * restrict, const char ** restrict, size_t, size_t,
mbstate_t * restrict)’ {aka ‘long unsigned int(int * restrict, const char **
restrict, long unsigned int, long unsigned int, mbstate_t * restrict)’}
376 | extern size_t mbsnrtowcs (wchar_t *__restrict __dst,
| ^~~~~~~~~~
./uchar.h:1340:10: note: previous implicit declaration of ‘mbsnrtowcs’ with
type ‘int()’
1340 | mbsnrtowcs ((wchar_t *) dest, srcp, srclen, len, ps);
| ^~~~~~~~~~
make[3]: *** [Makefile:2347: mbrtoc32.o] Error 1
This patch fixes it.
2026-06-02 Bruno Haible <[email protected]>
c32width etc.: Fix compilation error on GNU systems (regr. 2026-04-24).
* lib/uchar.in.h: Do include <wchar.h> when any of the modules c32width,
c32snrtombs, c32srtombs, c32swidth, mbsnrtoc32s, mbsrtoc32s is in use.
diff --git a/lib/uchar.in.h b/lib/uchar.in.h
index ed1f1a88f3..3d9f035e6a 100644
--- a/lib/uchar.in.h
+++ b/lib/uchar.in.h
@@ -72,6 +72,9 @@
defined __cplusplus ? @CXX_HAVE_UCHAR_H@ : @HAVE_UCHAR_H@) \
|| (/* These need wint_t and maybe WEOF and a <wchar.h> function. */ \
@GNULIB_BTOC32@ || @GNULIB_C32TOB@) \
+ || (/* These need a <wchar.h> function. */ \
+ @GNULIB_C32WIDTH@ || @GNULIB_C32SNRTOMBS@ || @GNULIB_C32SRTOMBS@ \
+ || @GNULIB_C32SWIDTH@ || @GNULIB_MBSNRTOC32S@ || @GNULIB_MBSRTOC32S@)
\
|| (/* These need mbszero. */ \
(@GNULIB_C32STOMBS@ || @GNULIB_MBSTOC32S@)))
# include <wchar.h>
@@ -91,8 +94,8 @@
|| @GNULIB_C32ISLOWER@ || @GNULIB_C32ISPRINT@ || @GNULIB_C32ISPUNCT@ \
|| @GNULIB_C32ISSPACE@ || @GNULIB_C32ISUPPER@ || @GNULIB_C32ISXDIGIT@ \
|| @GNULIB_C32TOLOWER@ || @GNULIB_C32TOUPPER@ \
- || @GNULIB_C32_APPLY_MAPPING@ || @GNULIB_C32_APPLY_TYPE_TEST@ \
- || @GNULIB_C32_GET_MAPPING@ || @GNULIB_C32_GET_TYPE_TEST@)
+ || @GNULIB_C32_GET_TYPE_TEST@ || @GNULIB_C32_APPLY_TYPE_TEST@ \
+ || @GNULIB_C32_GET_MAPPING@ || @GNULIB_C32_APPLY_MAPPING@)
# include <wctype.h>
#endif