GNOME Bugzilla – Bug 599340
MSVS 2005: Glib::ustring::format does not work with std::fixed or std::setfill
Last modified: 2010-04-12 17:20:25 UTC
For std::setfill I see the following error with MSVC: 1>c:\msys\home\armin\gnome\glibmm\glib\glibmm\ustring.h(1052) : error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'const std::_Fillobj<_Elem>' (or there is no acceptable conversion) For std::fixed, it is (there are many, but I think this is the relevant one): 1>c:\msys\home\armin\gnome\glibmm\examples\compose\main.cc(40) : error C2784: 'Glib::ustring Glib::ustring::format(const T1 &,const T2 &,const T3 &)' : could not deduce template argument for 'overloaded function type' from 'overloaded function type' To reproduce, simply try to compile the compose example from the glibmm tarball. I have no actual idea how to tackle this... I assume the latter means that std::fixed is overloaded in MSVC's STL. If that's allowed by the standard then we should maybe at least offer an alternative way of setting std::fixed with Glib::ustring::format.
Is glibmm on Windows now compiled with wide stream support, as discussed a while ago on the mailing list?
I am going to do this for gtkmm 2.20 and MSVC. It does not solve this problem though.
Thanks, Armin, if that doesn't fix this, please show us the latest compile error here.
Oh, the first time I didn't realize this is a different error, but it is: 1>..\..\..\..\..\..\..\msys\home\Armin\gnome\glibmm\examples\compose\main.cc(40) : error C2780: 'Glib::ustring Glib::ustring::format(const T1 &,const T2 &,const T3 &,const T4 &,const T5 &,const T6 &,const T7 &,const T8 &)' : expects 8 arguments - 3 provided 1> C:\gtkmm\include\glibmm-2.4\glibmm/ustring.h(796) : see declaration of 'Glib::ustring::format' 1>..\..\..\..\..\..\..\msys\home\Armin\gnome\glibmm\examples\compose\main.cc(40) : error C2780: 'Glib::ustring Glib::ustring::format(const T1 &,const T2 &,const T3 &,const T4 &,const T5 &,const T6 &,const T7 &)' : expects 7 arguments - 3 provided The same message appears for all the other overloads except for the one with 3 arguments. Also the same error appears for ustring::compose for all the overloads: 1>..\..\..\..\..\..\..\msys\home\Armin\gnome\glibmm\examples\compose\main.cc(40) : error C2780: 'Glib::ustring Glib::ustring::compose(const Glib::ustring &,const T1 &,const T2 &,const T3 &,const T4 &,const T5 &,const T6 &,const T7 &,const T8 &,const T9 &)' : expects 10 arguments - 4 provided 1> C:\gtkmm\include\glibmm-2.4\glibmm/ustring.h(698) : see declaration of 'Glib::ustring::compose' 1>..\..\..\..\..\..\..\msys\home\Armin\gnome\glibmm\examples\compose\main.cc(40) : error C2780: 'Glib::ustring Glib::ustring::compose(const Glib::ustring &,const T1 &,const T2 &,const T3 &,const T4 &,const T5 &,const T6 &,const T7 &,const T8 &)' : expects 9 arguments - 4 provided 1> C:\gtkmm\include\glibmm-2.4\glibmm/ustring.h(687) : see declaration of 'Glib::ustring::compose' Another thing I just checked is that this error happens only with VC8 (MSVC 2005) but it compiles OK with VC9 (MSVC 2008). It seems to be only due to the std::fixed; if I remove it then it also compiles with MSVC 2005.
Just for the record: When casting it to the correct type then it compiles also with MSVC 2005: ustring::format(static_cast<std::ios_base&(*)(std::ios_base&)>(std::fixed), std::setprecision(1), a / b * 100.0)) Maybe this is because it's (incorrectly?) overloaded. I can't seem to be able to find out how/with what though.
> Another thing I just checked is that this error happens only with VC8 (MSVC > 2005) but it compiles OK with VC9 (MSVC 2008). Then it's probably not worth worrying about much, particularly as it's only in an example, so you can still build glibmm for MSVS 2005, but people just can't use that (new) API. Of course I'd welcome a patch to fix it on that old compiler, but I wouldn't waste time creating that patch personally,
I take it that the std::setfill() example compiles fine now? About fixing it: Let's not do that horrible cast. At most, I would exclude the line using std::fixed from the build on MSVC 2005. But given that, if I remember correctly, the examples are only built on "make check", we may as well leave it as it is.
Yes, std::setfill seems to work since wide streams were enabled. I normally add the examples to the MSVC solution file so I can easily verify they keep working. If we decide to leave things as they are then I can simply add this one only to the MSVC2008 project.
Well, if it would make your life easier, feel free to conditionally disable the std::fixed bit for MSVC 2005. The decision is yours.
OK. I have added a check for MSVC 2008 or above and added the file to both projects.