Fix build with MinGW 5.3 in debug mode

Due to a bug in MinGW (see https://sourceforge.net/p/mingw/bugs/2322/),
_stricmp() and _strnicmp() declarations are not visible when compiling without
optimizations. Work around this by declaring them ourselves.

See #17762.
This commit is contained in:
Vadim Zeitlin
2017-01-13 23:52:13 +01:00
parent 7477e94b2d
commit 7c22e4257b
3 changed files with 30 additions and 14 deletions

View File

@@ -149,26 +149,34 @@
the new C++11 features and not disable the use of POSIX functions, we just
manually declare the functions we need in this case if necessary.
*/
#if defined(__MINGW32_TOOLCHAIN__) && defined(__STRICT_ANSI__)
#define wxNEEDS_STRICT_ANSI_WORKAROUNDS
#ifdef __MINGW32_TOOLCHAIN__
/*
This macro is somewhat unusual as it takes the list of parameters
inside parentheses and includes semicolon inside it as putting the
semicolon outside wouldn't do the right thing when this macro is empty.
*/
#define wxDECL_FOR_STRICT_MINGW32(rettype, func, params) \
#define wxDECL_FOR_MINGW32_ALWAYS(rettype, func, params) \
extern "C" _CRTIMP rettype __cdecl __MINGW_NOTHROW func params ;
/*
There is a bug resulting in a compilation error in MinGW standard
math.h header, see https://sourceforge.net/p/mingw/bugs/2250/, work
around it here because math.h is also included from several other
standard headers (e.g. <algorithm>) and we don't want to duplicate this
hack everywhere this happens.
*/
wxDECL_FOR_STRICT_MINGW32(double, _hypot, (double, double))
#ifdef __STRICT_ANSI__
#define wxNEEDS_STRICT_ANSI_WORKAROUNDS
#define wxDECL_FOR_STRICT_MINGW32(rettype, func, params) \
wxDECL_FOR_MINGW32_ALWAYS(rettype, func, params)
/*
There is a bug resulting in a compilation error in MinGW standard
math.h header, see https://sourceforge.net/p/mingw/bugs/2250/, work
around it here because math.h is also included from several other
standard headers (e.g. <algorithm>) and we don't want to duplicate this
hack everywhere this happens.
*/
wxDECL_FOR_STRICT_MINGW32(double, _hypot, (double, double))
#else
#define wxDECL_FOR_STRICT_MINGW32(rettype, func, params)
#endif
#else
#define wxDECL_FOR_MINGW32_ALWAYS(rettype, func, params)
#define wxDECL_FOR_STRICT_MINGW32(rettype, func, params)
#endif

View File

@@ -358,6 +358,7 @@
# define wxCHECK_W32API_VERSION(maj, min) (0)
# undef wxCHECK_MINGW32_VERSION
# define wxCHECK_MINGW32_VERSION( major, minor ) (0)
# define wxDECL_FOR_MINGW32_ALWAYS(rettype, func, params)
# define wxDECL_FOR_STRICT_MINGW32(rettype, func, params)
#endif

View File

@@ -230,8 +230,15 @@ extern unsigned long android_wcstoul(const wchar_t *nptr, wchar_t **endptr, int
#define wxCRT_StricmpA stricmp
#define wxCRT_StrnicmpA strnicmp
#elif defined(__VISUALC__) || defined(__MINGW32__)
wxDECL_FOR_STRICT_MINGW32(int, _stricmp, (const char*, const char*))
wxDECL_FOR_STRICT_MINGW32(int, _strnicmp, (const char*, const char*, size_t))
/*
Due to MinGW 5.3 bug (https://sourceforge.net/p/mingw/bugs/2322/),
_stricmp() and _strnicmp() are not declared in its standard headers
when compiling without optimizations. Work around this by always
declaring them ourselves (notice that if/when this bug were fixed, we'd
still need to use wxDECL_FOR_STRICT_MINGW32() for them here.
*/
wxDECL_FOR_MINGW32_ALWAYS(int, _stricmp, (const char*, const char*))
wxDECL_FOR_MINGW32_ALWAYS(int, _strnicmp, (const char*, const char*, size_t))
#define wxCRT_StricmpA _stricmp
#define wxCRT_StrnicmpA _strnicmp