bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Bruno Haible <bruno@clisp.org>
To: Christian Biesinger <cbiesinger@google.com>
Cc: bug-gnulib@gnu.org
Subject: Re: wctype.h compile error on mingw with GNULIB_NAMESPACE
Date: Sun, 17 Nov 2019 04:05:46 +0100	[thread overview]
Message-ID: <1804136.G1HiJvb5N8@omega> (raw)
In-Reply-To: <CAPTJ0XGQW6_mZTdVRvJAs4cXg=-=a9XWgM-BoY5Z=BXNYkA6Sw@mail.gmail.com>

Hello Christian,

> Specifically, this testcase:
> 
> #define GNULIB_NAMESPACE gnulib
> #include "gnulib/config.h"
> #include "wctype.h"
> 
> x86_64-w64-mingw32-g++ -c test.cc -I build/gnulib/import/ -I
> binutils-gdb/gnulib/import/
> 
> Fails with errors like:
> gnulib/import/wctype.h: In member function
> ‘gnulib::_gl_iswalnum_wrapper::operator
> gnulib::_gl_iswalnum_wrapper::type() const’:
> gnulib/import/wctype.h:856:1: error: invalid conversion from ‘int
> (*)(wint_t)’ {aka ‘int (*)(short unsigned int)’} to
> ‘gnulib::_gl_iswalnum_wrapper::type’ {aka ‘int (*)(unsigned int)’}
> [-fpermissive]
>  _GL_CXXALIAS_SYS (iswalnum, int, (wint_t wc));
>  ^~~~~~~~~~~~~~~~
> 
> (and followed by many other is* functions)

Fixed through the following patch.


2019-11-16  Bruno Haible  <bruno@clisp.org>

	wctype-h: When overriding wint_t, override also the related functions.
	Reported by Christian Biesinger <cbiesinger@google.com> in
	<https://lists.gnu.org/archive/html/bug-gnulib/2019-11/msg00027.html>.
	* m4/wctype_h.m4 (gl_WCTYPE_H): When GNULIB_OVERRIDES_WINT_T is 1, set
	REPLACE_ISWCNTRL to 1.
	* lib/wctype.in.h (rpl_iswalnum, rpl_iswalpha, rpl_iswblank,
	rpl_iswcntrl, rpl_iswdigit, rpl_iswgraph, rpl_iswlower, rpl_iswprint,
	rpl_iswpunct, rpl_iswspace, rpl_iswupper, rpl_iswxdigit, rpl_towlower,
	rpl_towupper): New definitions when GNULIB_OVERRIDES_WINT_T is 1.
	* doc/posix-headers/wchar.texi: Mention that wint_t is also overridden
	on mingw.
	* doc/posix-headers/wctype.texi: Likewise.

diff --git a/doc/posix-headers/wchar.texi b/doc/posix-headers/wchar.texi
index 5336d6b..6a94f13 100644
--- a/doc/posix-headers/wchar.texi
+++ b/doc/posix-headers/wchar.texi
@@ -12,7 +12,7 @@ This header file cannot be included on some platforms:
 Linux uClibc built without wide character support.
 @item
 The type @code{wint_t} is incorrect on some platforms:
-MSVC 14.
+mingw, MSVC 14.
 
 @item
 Some platforms provide a @code{NULL} macro that cannot be used in arbitrary
diff --git a/doc/posix-headers/wctype.texi b/doc/posix-headers/wctype.texi
index e288094..b97d491 100644
--- a/doc/posix-headers/wctype.texi
+++ b/doc/posix-headers/wctype.texi
@@ -12,7 +12,7 @@ This header file is missing on some platforms:
 HP-UX 11.00.
 @item
 The type @code{wint_t} is incorrect on some platforms:
-MSVC 14.
+mingw, MSVC 14.
 @item
 The functions @code{isw*} are missing on some platforms:
 FreeBSD 4.11.
diff --git a/lib/wctype.in.h b/lib/wctype.in.h
index 3cd568e..1a04742 100644
--- a/lib/wctype.in.h
+++ b/lib/wctype.in.h
@@ -133,33 +133,113 @@ typedef unsigned int rpl_wint_t;
 
 /* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
    Linux libc5 has <wctype.h> and the functions but they are broken.
+   mingw and MSVC have <wctype.h> and the functions but they take a wchar_t
+   as argument, not an rpl_wint_t.
    Assume all 11 functions (all isw* except iswblank) are implemented the
    same way, or not at all.  */
 # if ! @HAVE_ISWCNTRL@ || @REPLACE_ISWCNTRL@
 
-/* IRIX 5.3 has macros but no functions, its isw* macros refer to an
-   undefined variable _ctmp_ and to <ctype.h> macros like _P, and they
-   refer to system functions like _iswctype that are not in the
-   standard C library.  Rather than try to get ancient buggy
-   implementations like this to work, just disable them.  */
-#  undef iswalnum
-#  undef iswalpha
-#  undef iswblank
-#  undef iswcntrl
-#  undef iswdigit
-#  undef iswgraph
-#  undef iswlower
-#  undef iswprint
-#  undef iswpunct
-#  undef iswspace
-#  undef iswupper
-#  undef iswxdigit
-#  undef towlower
-#  undef towupper
+#  if @GNULIB_OVERRIDES_WINT_T@ /* implies @REPLACE_ISWCNTRL@ */
+
+_GL_WCTYPE_INLINE int
+rpl_iswalnum (wint_t wc)
+{
+  return ((wchar_t) wc == wc ? iswalnum ((wchar_t) wc) : 0);
+}
+
+_GL_WCTYPE_INLINE int
+rpl_iswalpha (wint_t wc)
+{
+  return ((wchar_t) wc == wc ? iswalpha ((wchar_t) wc) : 0);
+}
+
+_GL_WCTYPE_INLINE int
+rpl_iswblank (wint_t wc)
+{
+  return ((wchar_t) wc == wc ? iswblank ((wchar_t) wc) : 0);
+}
+
+_GL_WCTYPE_INLINE int
+rpl_iswcntrl (wint_t wc)
+{
+  return ((wchar_t) wc == wc ? iswcntrl ((wchar_t) wc) : 0);
+}
+
+_GL_WCTYPE_INLINE int
+rpl_iswdigit (wint_t wc)
+{
+  return ((wchar_t) wc == wc ? iswdigit ((wchar_t) wc) : 0);
+}
+
+_GL_WCTYPE_INLINE int
+rpl_iswgraph (wint_t wc)
+{
+  return ((wchar_t) wc == wc ? iswgraph ((wchar_t) wc) : 0);
+}
+
+_GL_WCTYPE_INLINE int
+rpl_iswlower (wint_t wc)
+{
+  return ((wchar_t) wc == wc ? iswlower ((wchar_t) wc) : 0);
+}
+
+_GL_WCTYPE_INLINE int
+rpl_iswprint (wint_t wc)
+{
+  return ((wchar_t) wc == wc ? iswprint ((wchar_t) wc) : 0);
+}
+
+_GL_WCTYPE_INLINE int
+rpl_iswpunct (wint_t wc)
+{
+  return ((wchar_t) wc == wc ? iswpunct ((wchar_t) wc) : 0);
+}
+
+_GL_WCTYPE_INLINE int
+rpl_iswspace (wint_t wc)
+{
+  return ((wchar_t) wc == wc ? iswspace ((wchar_t) wc) : 0);
+}
+
+_GL_WCTYPE_INLINE int
+rpl_iswupper (wint_t wc)
+{
+  return ((wchar_t) wc == wc ? iswupper ((wchar_t) wc) : 0);
+}
+
+_GL_WCTYPE_INLINE int
+rpl_iswxdigit (wint_t wc)
+{
+  return ((wchar_t) wc == wc ? iswxdigit ((wchar_t) wc) : 0);
+}
+
+_GL_WCTYPE_INLINE wint_t
+rpl_towlower (wint_t wc)
+{
+  return ((wchar_t) wc == wc ? (wchar_t) towlower ((wchar_t) wc) : wc);
+}
+
+_GL_WCTYPE_INLINE wint_t
+rpl_towupper (wint_t wc)
+{
+  return ((wchar_t) wc == wc ? (wchar_t) towupper ((wchar_t) wc) : wc);
+}
 
-/* Linux libc5 has <wctype.h> and the functions but they are broken.  */
-#  if @REPLACE_ISWCNTRL@
 #   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#    undef iswalnum
+#    undef iswalpha
+#    undef iswblank
+#    undef iswcntrl
+#    undef iswdigit
+#    undef iswgraph
+#    undef iswlower
+#    undef iswprint
+#    undef iswpunct
+#    undef iswspace
+#    undef iswupper
+#    undef iswxdigit
+#    undef towlower
+#    undef towupper
 #    define iswalnum rpl_iswalnum
 #    define iswalpha rpl_iswalpha
 #    define iswblank rpl_iswblank
@@ -172,21 +252,62 @@ typedef unsigned int rpl_wint_t;
 #    define iswspace rpl_iswspace
 #    define iswupper rpl_iswupper
 #    define iswxdigit rpl_iswxdigit
-#   endif
-#  endif
-#  if @REPLACE_TOWLOWER@
-#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #    define towlower rpl_towlower
 #    define towupper rpl_towupper
 #   endif
-#  endif
+
+#  else
+
+/* IRIX 5.3 has macros but no functions, its isw* macros refer to an
+   undefined variable _ctmp_ and to <ctype.h> macros like _P, and they
+   refer to system functions like _iswctype that are not in the
+   standard C library.  Rather than try to get ancient buggy
+   implementations like this to work, just disable them.  */
+#   undef iswalnum
+#   undef iswalpha
+#   undef iswblank
+#   undef iswcntrl
+#   undef iswdigit
+#   undef iswgraph
+#   undef iswlower
+#   undef iswprint
+#   undef iswpunct
+#   undef iswspace
+#   undef iswupper
+#   undef iswxdigit
+#   undef towlower
+#   undef towupper
+
+/* Linux libc5 has <wctype.h> and the functions but they are broken.  */
+#   if @REPLACE_ISWCNTRL@
+#    if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#     define iswalnum rpl_iswalnum
+#     define iswalpha rpl_iswalpha
+#     define iswblank rpl_iswblank
+#     define iswcntrl rpl_iswcntrl
+#     define iswdigit rpl_iswdigit
+#     define iswgraph rpl_iswgraph
+#     define iswlower rpl_iswlower
+#     define iswprint rpl_iswprint
+#     define iswpunct rpl_iswpunct
+#     define iswspace rpl_iswspace
+#     define iswupper rpl_iswupper
+#     define iswxdigit rpl_iswxdigit
+#    endif
+#   endif
+#   if @REPLACE_TOWLOWER@
+#    if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#     define towlower rpl_towlower
+#     define towupper rpl_towupper
+#    endif
+#   endif
 
 _GL_WCTYPE_INLINE int
-#  if @REPLACE_ISWCNTRL@
+#   if @REPLACE_ISWCNTRL@
 rpl_iswalnum
-#  else
+#   else
 iswalnum
-#  endif
+#   endif
          (wint_t wc)
 {
   return ((wc >= '0' && wc <= '9')
@@ -194,88 +315,88 @@ iswalnum
 }
 
 _GL_WCTYPE_INLINE int
-#  if @REPLACE_ISWCNTRL@
+#   if @REPLACE_ISWCNTRL@
 rpl_iswalpha
-#  else
+#   else
 iswalpha
-#  endif
+#   endif
          (wint_t wc)
 {
   return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z';
 }
 
 _GL_WCTYPE_INLINE int
-#  if @REPLACE_ISWCNTRL@
+#   if @REPLACE_ISWCNTRL@
 rpl_iswblank
-#  else
+#   else
 iswblank
-#  endif
+#   endif
          (wint_t wc)
 {
   return wc == ' ' || wc == '\t';
 }
 
 _GL_WCTYPE_INLINE int
-#  if @REPLACE_ISWCNTRL@
+#   if @REPLACE_ISWCNTRL@
 rpl_iswcntrl
-#  else
+#   else
 iswcntrl
-#  endif
+#   endif
         (wint_t wc)
 {
   return (wc & ~0x1f) == 0 || wc == 0x7f;
 }
 
 _GL_WCTYPE_INLINE int
-#  if @REPLACE_ISWCNTRL@
+#   if @REPLACE_ISWCNTRL@
 rpl_iswdigit
-#  else
+#   else
 iswdigit
-#  endif
+#   endif
          (wint_t wc)
 {
   return wc >= '0' && wc <= '9';
 }
 
 _GL_WCTYPE_INLINE int
-#  if @REPLACE_ISWCNTRL@
+#   if @REPLACE_ISWCNTRL@
 rpl_iswgraph
-#  else
+#   else
 iswgraph
-#  endif
+#   endif
          (wint_t wc)
 {
   return wc >= '!' && wc <= '~';
 }
 
 _GL_WCTYPE_INLINE int
-#  if @REPLACE_ISWCNTRL@
+#   if @REPLACE_ISWCNTRL@
 rpl_iswlower
-#  else
+#   else
 iswlower
-#  endif
+#   endif
          (wint_t wc)
 {
   return wc >= 'a' && wc <= 'z';
 }
 
 _GL_WCTYPE_INLINE int
-#  if @REPLACE_ISWCNTRL@
+#   if @REPLACE_ISWCNTRL@
 rpl_iswprint
-#  else
+#   else
 iswprint
-#  endif
+#   endif
          (wint_t wc)
 {
   return wc >= ' ' && wc <= '~';
 }
 
 _GL_WCTYPE_INLINE int
-#  if @REPLACE_ISWCNTRL@
+#   if @REPLACE_ISWCNTRL@
 rpl_iswpunct
-#  else
+#   else
 iswpunct
-#  endif
+#   endif
          (wint_t wc)
 {
   return (wc >= '!' && wc <= '~'
@@ -284,11 +405,11 @@ iswpunct
 }
 
 _GL_WCTYPE_INLINE int
-#  if @REPLACE_ISWCNTRL@
+#   if @REPLACE_ISWCNTRL@
 rpl_iswspace
-#  else
+#   else
 iswspace
-#  endif
+#   endif
          (wint_t wc)
 {
   return (wc == ' ' || wc == '\t'
@@ -296,22 +417,22 @@ iswspace
 }
 
 _GL_WCTYPE_INLINE int
-#  if @REPLACE_ISWCNTRL@
+#   if @REPLACE_ISWCNTRL@
 rpl_iswupper
-#  else
+#   else
 iswupper
-#  endif
+#   endif
          (wint_t wc)
 {
   return wc >= 'A' && wc <= 'Z';
 }
 
 _GL_WCTYPE_INLINE int
-#  if @REPLACE_ISWCNTRL@
+#   if @REPLACE_ISWCNTRL@
 rpl_iswxdigit
-#  else
+#   else
 iswxdigit
-#  endif
+#   endif
           (wint_t wc)
 {
   return ((wc >= '0' && wc <= '9')
@@ -319,27 +440,29 @@ iswxdigit
 }
 
 _GL_WCTYPE_INLINE wint_t
-#  if @REPLACE_TOWLOWER@
+#   if @REPLACE_TOWLOWER@
 rpl_towlower
-#  else
+#   else
 towlower
-#  endif
+#   endif
          (wint_t wc)
 {
   return (wc >= 'A' && wc <= 'Z' ? wc - 'A' + 'a' : wc);
 }
 
 _GL_WCTYPE_INLINE wint_t
-#  if @REPLACE_TOWLOWER@
+#   if @REPLACE_TOWLOWER@
 rpl_towupper
-#  else
+#   else
 towupper
-#  endif
+#   endif
          (wint_t wc)
 {
   return (wc >= 'a' && wc <= 'z' ? wc - 'a' + 'A' : wc);
 }
 
+#  endif
+
 # elif @GNULIB_ISWBLANK@ && (! @HAVE_ISWBLANK@ || @REPLACE_ISWBLANK@)
 /* Only the iswblank function is missing.  */
 
@@ -354,7 +477,7 @@ _GL_FUNCDECL_SYS (iswblank, int, (wint_t wc));
 
 # endif
 
-# if defined __MINGW32__
+# if defined __MINGW32__ && !@GNULIB_OVERRIDES_WINT_T@
 
 /* On native Windows, wchar_t is uint16_t, and wint_t is uint32_t.
    The functions towlower and towupper are implemented in the MSVCRT library
@@ -387,7 +510,7 @@ rpl_towupper (wint_t wc)
 #   define towupper rpl_towupper
 #  endif
 
-# endif /* __MINGW32__ */
+# endif /* __MINGW32__ && !@GNULIB_OVERRIDES_WINT_T@ */
 
 # define GNULIB_defined_wctype_functions 1
 #endif
diff --git a/m4/wctype_h.m4 b/m4/wctype_h.m4
index 6903d75..d5acb72 100644
--- a/m4/wctype_h.m4
+++ b/m4/wctype_h.m4
@@ -1,4 +1,4 @@
-# wctype_h.m4 serial 21
+# wctype_h.m4 serial 22
 
 dnl A placeholder for ISO C99 <wctype.h>, for platforms that lack it.
 
@@ -69,10 +69,14 @@ AC_DEFUN([gl_WCTYPE_H],
   fi
   AC_SUBST([HAVE_WCTYPE_H])
 
-  case "$gl_cv_func_iswcntrl_works" in
-    *yes) REPLACE_ISWCNTRL=0 ;;
-    *)    REPLACE_ISWCNTRL=1 ;;
-  esac
+  if test $GNULIB_OVERRIDES_WINT_T = 1; then
+    REPLACE_ISWCNTRL=1
+  else
+    case "$gl_cv_func_iswcntrl_works" in
+      *yes) REPLACE_ISWCNTRL=0 ;;
+      *)    REPLACE_ISWCNTRL=1 ;;
+    esac
+  fi
   AC_SUBST([REPLACE_ISWCNTRL])
 
   if test $HAVE_ISWCNTRL = 0 || test $REPLACE_ISWCNTRL = 1; then



  reply	other threads:[~2019-11-17  3:06 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-11 18:56 time_r module does not work on MingW Christian Biesinger
2019-11-11 19:53 ` Paul Eggert
2019-11-11 19:59 ` Bruno Haible
2019-11-11 20:47   ` Christian Biesinger
2019-11-12  2:28     ` Bruno Haible
2019-11-16 12:15       ` Bruno Haible
2019-11-16 22:41         ` wctype.h compile error on mingw with GNULIB_NAMESPACE Christian Biesinger
2019-11-17  3:05           ` Bruno Haible [this message]
2019-11-17  4:40             ` Christian Biesinger
2019-11-24 19:15               ` Bruno Haible
2019-11-25 23:28                 ` Christian Biesinger
2019-11-25 23:53                   ` Bruno Haible
2019-11-24 14:06         ` time_r module does not work on MingW Bruno Haible

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1804136.G1HiJvb5N8@omega \
    --to=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    --cc=cbiesinger@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).