> Cc: bug-gnulib@gnu.org > From: Paul Eggert <egg...@cs.ucla.edu> > Date: Sun, 9 Oct 2016 11:07:46 -0700 > > Eli Zaretskii wrote: > > But because string.h was included, __STRING_H_SOURCED__ is defined, > > and MinGW's wchar.h doesn't define mbstate_t. Gnulib's wchar.h > > I suggest adding a __STRING_H_SOURCED__ check to Gnulib's lib/wchar.in.h's > complicated test for the special invocation convention.
Thanks for the guidance. Indeed, the two patches below fix both issues for me. Please consider this for inclusion in Gnulib. 2016-10-08 Eli Zaretskii <e...@gnu.org> Fix wchar.h and wctype.h for MinGW 3.22.2 * lib/wchar.in.h [__MINGW32__]: Add one more condition for special invocation, to fix issues with MinGW 3.22.2 wchar.h when included from <string.h>. * lib/wctype.in.h [__MINGW32__]: Add special invocation convention for MinGW 3.22.2, to solve issues with their wctype.h when included from <ctype.h>. --- lib/wchar.in.h~0 2016-08-01 18:50:20.000000000 +0300 +++ lib/wchar.in.h 2016-10-10 15:44:45.178750000 +0300 @@ -35,6 +35,7 @@ || (defined __hpux \ && ((defined _INTTYPES_INCLUDED && !defined strtoimax) \ || defined _GL_JUST_INCLUDE_SYSTEM_WCHAR_H)) \ + || (defined __MINGW32__ && defined __STRING_H_SOURCED__) \ || defined _GL_ALREADY_INCLUDING_WCHAR_H) /* Special invocation convention: - Inside glibc and uClibc header files, but not MinGW. @@ -44,6 +45,8 @@ and once directly. In both situations 'wint_t' is not yet defined, therefore we cannot provide the function overrides; instead include only the system's <wchar.h>. + - With MinGW 3.22, when <string.h> includes <wchar.h>, only some part of + <wchar.h> is actually processed, and that doesn't include 'mbstate_t'. - On IRIX 6.5, similarly, we have an include <wchar.h> -> <wctype.h>, and the latter includes <wchar.h>. But here, we have no way to detect whether <wctype.h> is completely included or is still being included. */ --- lib/wctype.in.h~0 2016-08-01 18:50:20.000000000 +0300 +++ lib/wctype.in.h 2016-10-10 15:55:32.350625000 +0300 @@ -25,13 +25,25 @@ * wctrans_t, and wctype_t are not yet implemented. */ -#ifndef _@GUARD_PREFIX@_WCTYPE_H - #if __GNUC__ >= 3 @PRAGMA_SYSTEM_HEADER@ #endif @PRAGMA_COLUMNS@ +#if (defined __MINGW32__ && defined __CTYPE_H_SOURCED__) + +/* Special invocation convention: + - With MinGW 3.22, when <ctype.h> includes <wctype.h>, only some part of + <wctype.h> is being processed, which doesn't include the idempotency + guard. */ + +#@INCLUDE_NEXT@ @NEXT_WCTYPE_H@ + +#else +/* Normal invocation convention. */ + +#ifndef _@GUARD_PREFIX@_WCTYPE_H + #if @HAVE_WINT_T@ /* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>. Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before @@ -512,3 +524,4 @@ #endif /* _@GUARD_PREFIX@_WCTYPE_H */ #endif /* _@GUARD_PREFIX@_WCTYPE_H */ +#endif