bug-gnulib
[Top][All Lists]
Advanced

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

wchar: fix compilation error in C++ mode on MSVC


From: Bruno Haible
Subject: wchar: fix compilation error in C++ mode on MSVC
Date: Wed, 11 Dec 2019 11:40:29 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-166-generic; KDE/5.18.0; x86_64; ; )

When building a testdir with C++ tests on MSVC 14, I see these errors:

source='../../gltests/test-wchar-c++2.cc' object='test-wchar-c++2.obj' 
libtool=no \
DEPDIR=.deps depmode=msvc7 /bin/sh ../../build-aux/depcomp \
/home/bruno/msvc/compile cl -nologo -DHAVE_CONFIG_H -DEXEEXT=\".exe\" -I. 
-I../../gltests -I..  -DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. 
-I../../gltests -I.. -I../../gltests/.. -I../gllib -I../../gltests/../gllib 
-D_WIN32_WINNT=_WIN32_WINNT_WINXP -I/usr/local/msvc64/include  -MD -c -o 
test-wchar-c++2.obj `cygpath -w '../../gltests/test-wchar-c++2.cc'`
test-wchar-c++2.cc
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cwchar(16): 
error C2371: '_Mbstatet': redefinition; different basic types
C:\Program Files (x86)\Windows 
Kits\10\Include\10.0.10240.0\ucrt\corecrt.h(470): note: see declaration of 
'_Mbstatet'
make[4]: *** [Makefile:9886: test-wchar-c++2.obj] Error 2

source='../../gltests/test-wchar-c++3.cc' object='test-wchar-c++3.obj' 
libtool=no \
DEPDIR=.deps depmode=msvc7 /bin/sh ../../build-aux/depcomp \
/home/bruno/msvc/compile cl -nologo -DHAVE_CONFIG_H -DEXEEXT=\".exe\" -I. 
-I../../gltests -I..  -DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. 
-I../../gltests -I.. -I../../gltests/.. -I../gllib -I../../gltests/../gllib 
-D_WIN32_WINNT=_WIN32_WINNT_WINXP -I/usr/local/msvc64/include  -MD -c -o 
test-wchar-c++3.obj `cygpath -w '../../gltests/test-wchar-c++3.cc'`
test-wchar-c++3.cc
...
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cwchar(16): 
error C2371: '_Mbstatet': redefinition; different basic types
C:\Program Files (x86)\Windows 
Kits\10\Include\10.0.10240.0\ucrt\corecrt.h(470): note: see declaration of 
'_Mbstatet'
...
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocale(1682): 
error C2664: 'int _Mbrtowc(wchar_t *,const char *,std::size_t,rpl_mbstate_t 
*,const _Cvtvec *)': cannot convert argument 4 from 
'std::codecvt<wchar_t,char,_Mbstatet>::_Statype *' to 'rpl_mbstate_t *'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocale(1682): 
note: Types pointed to are unrelated; conversion requires reinterpret_cast, 
C-style cast or function-style cast
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocale(1718): 
error C2664: 'int _Wcrtomb(char *,wchar_t,rpl_mbstate_t *,const _Cvtvec *)': 
cannot convert argument 3 from 'std::codecvt<wchar_t,char,_Mbstatet>::_Statype 
*' to 'rpl_mbstate_t *'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocale(1718): 
note: Types pointed to are unrelated; conversion requires reinterpret_cast, 
C-style cast or function-style cast
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocale(1728): 
error C2664: 'int _Wcrtomb(char *,wchar_t,rpl_mbstate_t *,const _Cvtvec *)': 
cannot convert argument 3 from 'std::codecvt<wchar_t,char,_Mbstatet>::_Statype 
*' to 'rpl_mbstate_t *'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocale(1728): 
note: Types pointed to are unrelated; conversion requires reinterpret_cast, 
C-style cast or function-style cast
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocale(1754): 
error C2664: 'int _Wcrtomb(char *,wchar_t,rpl_mbstate_t *,const _Cvtvec *)': 
cannot convert argument 3 from 'std::codecvt<wchar_t,char,_Mbstatet>::_Statype 
*' to 'rpl_mbstate_t *'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocale(1754): 
note: Types pointed to are unrelated; conversion requires reinterpret_cast, 
C-style cast or function-style cast
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocale(1784): 
error C2664: 'int _Mbrtowc(wchar_t *,const char *,std::size_t,rpl_mbstate_t 
*,const _Cvtvec *)': cannot convert argument 4 from 
'std::codecvt<wchar_t,char,_Mbstatet>::_Statype *' to 'rpl_mbstate_t *'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocale(1784): 
note: Types pointed to are unrelated; conversion requires reinterpret_cast, 
C-style cast or function-style cast
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocale(1916): 
error C2664: 'int _Mbrtowc(wchar_t *,const char *,std::size_t,rpl_mbstate_t 
*,const _Cvtvec *)': cannot convert argument 4 from 'std::codecvt<unsigned 
short,char,_Mbstatet>::_Statype *' to 'rpl_mbstate_t *'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocale(1916): 
note: Types pointed to are unrelated; conversion requires reinterpret_cast, 
C-style cast or function-style cast
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocale(1952): 
error C2664: 'int _Wcrtomb(char *,wchar_t,rpl_mbstate_t *,const _Cvtvec *)': 
cannot convert argument 3 from 'std::codecvt<unsigned 
short,char,_Mbstatet>::_Statype *' to 'rpl_mbstate_t *'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocale(1952): 
note: Types pointed to are unrelated; conversion requires reinterpret_cast, 
C-style cast or function-style cast
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocale(1962): 
error C2664: 'int _Wcrtomb(char *,wchar_t,rpl_mbstate_t *,const _Cvtvec *)': 
cannot convert argument 3 from 'std::codecvt<unsigned 
short,char,_Mbstatet>::_Statype *' to 'rpl_mbstate_t *'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocale(1962): 
note: Types pointed to are unrelated; conversion requires reinterpret_cast, 
C-style cast or function-style cast
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocale(1988): 
error C2664: 'int _Wcrtomb(char *,wchar_t,rpl_mbstate_t *,const _Cvtvec *)': 
cannot convert argument 3 from 'std::codecvt<unsigned 
short,char,_Mbstatet>::_Statype *' to 'rpl_mbstate_t *'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocale(1988): 
note: Types pointed to are unrelated; conversion requires reinterpret_cast, 
C-style cast or function-style cast
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocale(2018): 
error C2664: 'int _Mbrtowc(wchar_t *,const char *,std::size_t,rpl_mbstate_t 
*,const _Cvtvec *)': cannot convert argument 4 from 'std::codecvt<unsigned 
short,char,_Mbstatet>::_Statype *' to 'rpl_mbstate_t *'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocale(2018): 
note: Types pointed to are unrelated; conversion requires reinterpret_cast, 
C-style cast or function-style cast
make[4]: *** [Makefile:9886: test-wchar-c++3.obj] Error 2

This patch fixes them, simply by not overriding mbstate_t.


2019-12-11  Bruno Haible  <address@hidden>

        wchar: Fix compilation error in C++ mode on MSVC.
        * lib/wchar.in.h (mbstate_t): Don't override on MSVC.

diff --git a/lib/wchar.in.h b/lib/wchar.in.h
index af019e6..6626bd9 100644
--- a/lib/wchar.in.h
+++ b/lib/wchar.in.h
@@ -138,10 +138,10 @@ typedef unsigned int rpl_wint_t;
 /* Override mbstate_t if it is too small.
    On IRIX 6.5, sizeof (mbstate_t) == 1, which is not sufficient for
    implementing mbrtowc for encodings like UTF-8.
-   On AIX, mbrtowc needs to be overridden, but mbstate_t exists and is large
-   enough and overriding it would cause problems in C++ mode.  */
+   On AIX and MSVC, mbrtowc needs to be overridden, but mbstate_t exists and is
+   large enough and overriding it would cause problems in C++ mode.  */
 #if (!(@HAVE_MBSINIT@ && @HAVE_MBRTOWC@) || @REPLACE_MBSTATE_T@) \
-    && !defined _AIX
+    && !(defined _AIX || defined _MSC_VER)
 # if !GNULIB_defined_mbstate_t
 typedef int rpl_mbstate_t;
 #  undef mbstate_t




reply via email to

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