Bug 37522 - [4.4 regression] Incorrect vswprintf prototype breaks __to_xstring
Summary: [4.4 regression] Incorrect vswprintf prototype breaks __to_xstring
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.4.0
: P1 major
Target Milestone: 4.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords: build
Depends on:
Blocks: 36216
  Show dependency treegraph
 
Reported: 2008-09-14 23:25 UTC by Aaron W. LaFramboise
Modified: 2015-05-28 16:28 UTC (History)
7 users (show)

See Also:
Host:
Target: *-mingw32
Build:
Known to work: 4.3.2
Known to fail: 4.4.0
Last reconfirmed: 2008-09-14 23:27:34


Attachments
Proposed patch (330 bytes, patch)
2013-03-05 01:28 UTC, Karlson2k
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Aaron W. LaFramboise 2008-09-14 23:25:21 UTC
When attempting a bootstrap including libstdc++-v3, the following error will be encountered.

libtool: compile:  /mingw/src/gccf/./gcc/xgcc -shared-libgcc -B/mingw/src/gccf/./gcc -nostdinc++ -L/mingw/src/gccf/i386-pc-mingw32/libstdc++-v3/src -L/mingw/src/gccf/i386-pc-mingw32/libstdc++-v3/src/.libs -L/mingw/src/gccf/i386-pc-mingw32/winsup/mingw -L/mingw/src/gccf/i386-pc-mingw32/winsup/w32api/lib -isystem /mingw/src/svn/winsup/mingw/include -isystem /mingw/src/svn/winsup/w32api/include -B/mingw/i386-pc-mingw32/bin/ -B/mingw/i386-pc-mingw32/lib/ -isystem /mingw/i386-pc-mingw32/include -isystem /mingw/i386-pc-mingw32/sys-include -I/mingw/src/gccf/i386-pc-mingw32/libstdc++-v3/include/i386-pc-mingw32 -I/mingw/src/gccf/i386-pc-mingw32/libstdc++-v3/include -I/mingw/src/svn/libstdc++-v3/libsupc++ -fno-implicit-templates -Wall -Wextra -Wwrite-strings -Wcast-qual -fdiagnostics-show-location=once -ffunction-sections -fdata-sections -g -O2 -std=gnu++0x -c ../../../../svn/libstdc++-v3/src/functexcept.cc  -DDLL_EXPORT -DPIC -o .libs/functexcept.o
In file included from /mingw/src/gccf/i386-pc-mingw32/libstdc++-v3/include/string:58,
                 from /mingw/src/gccf/i386-pc-mingw32/libstdc++-v3/include/stdexcept:44,
                 from ../../../../svn/libstdc++-v3/src/functexcept.cc:31:
/mingw/src/gccf/i386-pc-mingw32/libstdc++-v3/include/bits/basic_string.h: In function 'std::wstring std::to_wstring(long long int)':
/mingw/src/gccf/i386-pc-mingw32/libstdc++-v3/include/bits/basic_string.h:2675: error: no matching function for call to '__to_xstring(int (*)(wchar_t*, const wchar_t*, char*), unsigned int, const wchar_t [5], long long int&)'
/mingw/src/gccf/i386-pc-mingw32/libstdc++-v3/include/bits/basic_string.h: In function 'std::wstring std::to_wstring(long long unsigned int)':
/mingw/src/gccf/i386-pc-mingw32/libstdc++-v3/include/bits/basic_string.h:2681: error: no matching function for call to '__to_xstring(int (*)(wchar_t*, const wchar_t*, char*), unsigned int, const wchar_t [5], long long unsigned int&)'
/mingw/src/gccf/i386-pc-mingw32/libstdc++-v3/include/bits/basic_string.h: In function 'std::wstring std::to_wstring(long double)':
/mingw/src/gccf/i386-pc-mingw32/libstdc++-v3/include/bits/basic_string.h:2689: error: no matching function for call to '__to_xstring(int (*)(wchar_t*, const wchar_t*, char*), const int&, const wchar_t [4], long double&)'
make[4]: *** [functexcept.lo] Error 1

The problem is that MSVCRT's prototype for vswprintf is incorrect, and differs from the standard C version.  This may not be easy to fix in mingwrt.  However, the _vsnwprintf function has the correct prototype and works with __to_xstring.

I guess the solution is to make libstdc++ use _vsnwprintf instead of vswprintf on *-mingw32.
Comment 1 Danny Smith 2008-09-15 02:57:40 UTC
> 
> I guess the solution is to make libstdc++ use _vsnwprintf instead of vswprintf
> on *-mingw32.
> 

I think that is the most expedient solution.  Would an inline redirection  of vswprintf to _vsnwprintf in config/os/mingw32/os_define.h (later, if it gets fixed in mingw runtime  that could be made conditional on mingw version) work?

Danny
Comment 2 Paolo Carlini 2008-09-15 17:10:48 UTC
I think Danny's solution should work. The inline redirection would live in namespace std, and os_defines.h would also define something like _GLIBCXX_HAVE_BROKEN_VSWPRINTF which would be used in include/*/cwchar to not import the broken function as-is from the global namespace to namespace std.

In principle, this brokeness can be easily detected at configure-time and we could (should!) add a separate check for vswprintf, on the parameters too, in GLIBCXX_ENABLE_WCHAR_T, following a strategy similar to the separate checks we have in GLIBCXX_ENABLE_C99. But then, I'm not sure what do with it, if we use it in include/*/cwchar to not import the broken function as-is in namespace std, then the function will disappear also for targets not providing a replacement, as mingw will do... Opinions about this? Is it likely, bound to be a big problem? Because I'd rather prefer having the configure-time check.
Comment 3 Paolo Carlini 2008-09-15 17:34:57 UTC
Well, in principle the automatic configure-time check could define a _GLIBCXX_HAVE_CONFORMING_VSWPRINTF, checking the parameters too, and then os_defines.h could define a _GLIBCXX_HAVE_REPLACEMENT_VSWPRINTF. Then, include/*/cwchar could guard the import with something like:

#if defined(_GLIBCXX_HAVE_CONFORMING_VSWPRINTF) || !defined(_GLIBCXX_HAVE_REPLACEMENT_VSWPRINTF)
... import
#endif

Anyway, if you can do and test somehow the mingw specific bits in os_defines.h, I can do the rest.
Comment 4 Aaron W. LaFramboise 2008-09-16 00:14:53 UTC
Paolo, I'll give it a try and if I can't get the configury to work for me, I'll let you do that part.
Comment 5 Paolo Carlini 2008-09-16 00:22:23 UTC
Great, the configury should be in fact pretty easy.
Comment 6 Jakub Jelinek 2008-10-27 09:58:43 UTC
Any progress?
Comment 7 Paolo Carlini 2008-10-27 10:09:42 UTC
Ok, I will just implement for now the minimal fix: _GLIBCXX_HAVE_BROKEN_VSWPRINTF defined in config/os/mingw32/os_define.h and used in basic_string.h
Comment 8 paolo@gcc.gnu.org 2008-10-27 15:02:47 UTC
Subject: Bug 37522

Author: paolo
Date: Mon Oct 27 15:01:28 2008
New Revision: 141382

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141382
Log:
2008-10-27  Paolo Carlini  <paolo.carlini@oracle.com>

	PR libstdc++/37522
	* config/os/mingw32/os_defines.h: Define _GLIBCXX_HAVE_BROKEN_VSWPRINTF
	* include/bits/basic_string.h: Guard string conversions with 
	!defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF) too.
	* testsuite/lib/libstdc++.exp (check_v3_target_string_conversions):
	New.
	* testsuite/lib/dg-options.exp (dg-require-string-conversions): New.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stof.cc:
	Use the latter.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stoll.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stoi.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stol.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/
	stoull.cc: Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stold.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stoul.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/
	to_string.cc: Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stod.cc:
	Likewise.

Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/config/os/mingw32/os_defines.h
    trunk/libstdc++-v3/include/bits/basic_string.h
    trunk/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stod.cc
    trunk/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stof.cc
    trunk/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoi.cc
    trunk/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stol.cc
    trunk/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stold.cc
    trunk/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoll.cc
    trunk/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoul.cc
    trunk/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoull.cc
    trunk/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/to_string.cc
    trunk/libstdc++-v3/testsuite/lib/dg-options.exp
    trunk/libstdc++-v3/testsuite/lib/libstdc++.exp

Comment 9 Paolo Carlini 2008-10-27 15:03:13 UTC
Fixed.
Comment 10 ph dunski 2013-01-19 11:34:35 UTC
Hello,

I know this bug is fixed since a long time, but there is the same problem when trying to compile the gcc-4.8-20130106.tar.bz2 tarball for mingw-w64.

Same prolems having, usually same issues, adding the line

// See  libstdc++/37522.
#define _GLIBCXX_HAVE_BROKEN_VSWPRINTF 1
in the libstdc++-v3/config/os/mingw32-w64/os_defines.h file seems to allow the build.

Should i open a new bug, or can you take it in acount from here?
Comment 11 Kai Tietz 2013-01-19 11:38:12 UTC
(In reply to comment #10)
> Hello,
> 
> I know this bug is fixed since a long time, but there is the same problem when
> trying to compile the gcc-4.8-20130106.tar.bz2 tarball for mingw-w64.
> 
> Same prolems having, usually same issues, adding the line
> 
> // See  libstdc++/37522.
> #define _GLIBCXX_HAVE_BROKEN_VSWPRINTF 1
> in the libstdc++-v3/config/os/mingw32-w64/os_defines.h file seems to allow the
> build.
> 
> Should i open a new bug, or can you take it in acount from here?

Don't open an new bug, don't reopen this bug.  I assume you are using none-trunk version of mingw-w64, are you?  If so, please switch to trunk-version.
Comment 12 ph dunski 2013-01-19 11:47:08 UTC
(In reply to comment #11)

> Don't open an new bug, don't reopen this bug.  I assume you are using
> none-trunk version of mingw-w64, are you?  If so, please switch to
> trunk-version.

i'm using the version taken at http://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/mingw-w64-v2.0.7.tar.gz/download .

I think it is the trunk version, isn't it?
Comment 13 Kai Tietz 2013-01-19 11:53:08 UTC
(In reply to comment #12)
> (In reply to comment #11)
> 
> > Don't open an new bug, don't reopen this bug.  I assume you are using
> > none-trunk version of mingw-w64, are you?  If so, please switch to
> > trunk-version.
> 
> i'm using the version taken at
> http://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/mingw-w64-v2.0.7.tar.gz/download
> .
> 
> I think it is the trunk version, isn't it?

No, it isn't.  It is v2.x branch as written even in file-name.  But please stop using gcc-bugreports to get answered your user-questions.  Use mingw-w64's mailing-list instead.
Comment 14 Jason Merrill 2013-01-25 21:36:48 UTC
(In reply to comment #11)
> Don't open an new bug, don't reopen this bug.  I assume you are using
> none-trunk version of mingw-w64, are you?  If so, please switch to
> trunk-version.

When exactly was this fixed on the trunk?  The mingw32-headers package on Fedora 17 (2.0.999-0.8.trunk.20121016) still has this issue.

(In reply to comment #13)
> No, it isn't.  It is v2.x branch as written even in file-name.  But please stop
> using gcc-bugreports to get answered your user-questions.  Use mingw-w64's
> mailing-list instead.

Often GCC works around problems with older versions of other tools; it seems reasonable to me to do the same in this case, especially since there isn't yet a release with this issue fixed.
Comment 15 Kai Tietz 2013-01-25 23:53:37 UTC
Issue was fixed on trunk.  As far as I know should rawhide Fedora have fixed that issue already.  Nevertheless we could define the broken-vsprintf macro based on header-version.
I will come up with a patch for that.
Comment 16 Karlson2k 2013-03-05 01:16:34 UTC
Header version could be detected in _mingw_mac.h for MinGW-w64 or in _mingw.h for MinGW32.
_mingw.h could be used for MinGW-w64 too as it include internally _mingw_mac.h.
Comment 17 Karlson2k 2013-03-05 01:28:06 UTC
Created attachment 29582 [details]
Proposed patch

Possible patch for latest MinGW-w64.
Patched GCC version: 4.7.2
Can be easy edited for trunk version.

--- ./libstdc++-v3/config/os/mingw32-w64/os_defines.h.orig	2011-12-23 21:23:38 +0400
+++ ./libstdc++-v3/config/os/mingw32-w64/os_defines.h	2013-03-05 05:22:07 +0400
@@ -64,7 +64,10 @@
 #define _GLIBCXX_HAVE_DOS_BASED_FILESYSTEM 1
 
 // See  libstdc++/37522.
+#include <_mingw_mac.h>
+#if !defined (__MINGW64_VERSION_MAJOR) || (__MINGW64_VERSION_MAJOR < 3)
 #define _GLIBCXX_HAVE_BROKEN_VSWPRINTF 1
+#endif
 
 // See libstdc++/43738
 // On native windows targets there is no ioctl function. And the existing
Comment 18 Jonathan Wakely 2014-12-22 16:42:12 UTC
Author: redi
Date: Mon Dec 22 16:41:39 2014
New Revision: 219019

URL: https://gcc.gnu.org/viewcvs?rev=219019&root=gcc&view=rev
Log:
	PR libstdc++/37522
	* include/bits/basic_string.h (stod, stof, stoi, stol, stold, stoll,
	stoul, stoull, to_string): Only use _GLIBCXX_HAVE_BROKEN_VSWPRINTF
	to guard definition of to_wstring.
	* testsuite/21_strings/basic_string/numeric_conversions/char/dr1261.cc:
	Do not use dg-require-string-conversions.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stod.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stof.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stoi.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stol.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stold.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stoll.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stoul.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/
	stoull.cc: Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/
	to_string.cc: Likewise.

Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/bits/basic_string.h
    trunk/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/dr1261.cc
    trunk/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stod.cc
    trunk/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stof.cc
    trunk/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoi.cc
    trunk/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stol.cc
    trunk/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stold.cc
    trunk/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoll.cc
    trunk/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoul.cc
    trunk/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoull.cc
    trunk/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/to_string.cc
Comment 19 Jonathan Wakely 2015-05-28 16:28:18 UTC
Author: redi
Date: Thu May 28 16:27:46 2015
New Revision: 223840

URL: https://gcc.gnu.org/viewcvs?rev=223840&root=gcc&view=rev
Log:
Backport from mainline
2014-12-22  Jonathan Wakely  <jwakely@redhat.com>

	PR libstdc++/37522
	* include/bits/basic_string.h (stod, stof, stoi, stol, stold, stoll,
	stoul, stoull, to_string): Only use _GLIBCXX_HAVE_BROKEN_VSWPRINTF
	to guard definition of to_wstring.

Modified:
    branches/gcc-4_9-branch/libstdc++-v3/ChangeLog
    branches/gcc-4_9-branch/libstdc++-v3/include/bits/basic_string.h