[Boost.LexicalCast] problem with 1.59 in Solaris

Trying to compile file libs/date_time/src/gregorian/greg_month.cpp I get an error related to Boost.LexicalCast. I have reduced the problem to a minimal test case: #include <string> #include <boost/lexical_cast.hpp> void f(const char* s) { std::string s1(boost::lexical_cast<std::string>(s)); } My feeling is that this compiler has problems in the specializations for boost::detail::is_stdstring and boost::detail::is_char_array_to_stdstring. If I remove all those specializations the error goes away. I assume this is not the perfect solution because I guess this will miss some optimization of lexical_cast, but at least I can compile it this way :( Is there a better solution for this? Has this problem been fixed in 1.60? Error message (full instantiation stack available if needed): "/ThirdPartyLibs/boost/1_59_0/boost/lexical_cast/try_lexical_convert.hpp", line 146: Error: Ambiguous partial specialization for boost::detail::is_char_array_to_stdstring<std::string, const char*>, boost::detail::is_char_array_to_stdstring<boost::container::basic_string<boost::detail::CharT, boost::detail::Traits, boost::detail::Alloc>, const boost::detail::CharT*> and boost::detail::is_char_array_to_stdstring<std::basic_string<boost::detail::CharT, boost::detail::Traits, boost::detail::Alloc>, const boost::detail::CharT*>. "/ThirdPartyLibs/boost/1_59_0/boost/lexical_cast.hpp", line 42: Where: While instantiating "boost::conversion::detail::try_lexical_convert<std::string, const char*>(const char*const&, std::string &)". "/ThirdPartyLibs/boost/1_59_0/boost/lexical_cast/try_lexical_convert.hpp", line 134: Error: Ambiguous partial specialization for boost::detail::is_stdstring<std::string>, boost::detail::is_stdstring<boost::container::basic_string<boost::detail::CharT, boost::detail::Traits, boost::detail::Alloc>> and boost::detail::is_stdstring<std::basic_string<boost::detail::CharT, boost::detail::Traits, boost::detail::Alloc>>. "/ThirdPartyLibs/boost/1_59_0/boost/lexical_cast.hpp", line 42: Where: While instantiating "boost::conversion::detail::try_lexical_convert<std::string, const char*>(const char*const&, std::string &)".

Are you using solaris studio 12.3 or older? Before version 12.4 there was a bug where partial specialization for templates with same name but in different namespaces (basic_string in std:: and boost::container:: in this case) was considered ambiguous. A workaround for this problem (I would recommend using solaris studio 12.4) can be found here: https://community.oracle.com/thread/3706125 2015-12-22 19:31 GMT+01:00 <dariomt@gmail.com>:
Trying to compile file libs/date_time/src/gregorian/greg_month.cpp I get an error related to Boost.LexicalCast.
I have reduced the problem to a minimal test case:
#include <string> #include <boost/lexical_cast.hpp>
void f(const char* s) { std::string s1(boost::lexical_cast<std::string>(s)); }
My feeling is that this compiler has problems in the specializations for boost::detail::is_stdstring and boost::detail::is_char_array_to_stdstring.
If I remove all those specializations the error goes away. I assume this is not the perfect solution because I guess this will miss some optimization of lexical_cast, but at least I can compile it this way :(
Is there a better solution for this? Has this problem been fixed in 1.60?
Error message (full instantiation stack available if needed):
"/ThirdPartyLibs/boost/1_59_0/boost/lexical_cast/try_lexical_convert.hpp", line 146: Error: Ambiguous partial specialization for boost::detail::is_char_array_to_stdstring<std::string, const char*>, boost::detail::is_char_array_to_stdstring<boost::container::basic_string<boost::detail::CharT, boost::detail::Traits, boost::detail::Alloc>, const boost::detail::CharT*> and boost::detail::is_char_array_to_stdstring<std::basic_string<boost::detail::CharT, boost::detail::Traits, boost::detail::Alloc>, const boost::detail::CharT*>. "/ThirdPartyLibs/boost/1_59_0/boost/lexical_cast.hpp", line 42: Where: While instantiating "boost::conversion::detail::try_lexical_convert<std::string, const char*>(const char*const&, std::string &)".
"/ThirdPartyLibs/boost/1_59_0/boost/lexical_cast/try_lexical_convert.hpp", line 134: Error: Ambiguous partial specialization for boost::detail::is_stdstring<std::string>, boost::detail::is_stdstring<boost::container::basic_string<boost::detail::CharT, boost::detail::Traits, boost::detail::Alloc>> and boost::detail::is_stdstring<std::basic_string<boost::detail::CharT, boost::detail::Traits, boost::detail::Alloc>>. "/ThirdPartyLibs/boost/1_59_0/boost/lexical_cast.hpp", line 42: Where: While instantiating "boost::conversion::detail::try_lexical_convert<std::string, const char*>(const char*const&, std::string &)".
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Piotr Kowalski <koval.gnu <at> gmail.com> writes:
Are you using solaris studio 12.3 or older?Before version 12.4 there
was a bug where partial specialization for templates with same name but in different namespaces (basic_string in std:: and boost::container:: in this case) was considered ambiguous.
A workaround for this problem (I would recommend using solaris studio 12.4) can be found here: https://community.oracle.com/thread/3706125
Thanks for the info and the link! It seems to be 12.1 $ CC -V CC: Sun C++ 5.10 SunOS_i386 Patch 128229-32 2013/12/04 It's not easy to change the compiler, it might not be possible *at all* for this specific project. For now I'll #ifdef out the specializations for boost::container::basic_string. Is there a way to get this solution into an official boost release?
2015-12-22 19:31 GMT+01:00 <dariomt <at> gmail.com>: Trying to compile file libs/date_time/src/gregorian/greg_month.cpp I
I have reduced the problem to a minimal test case:
#include <string> #include <boost/lexical_cast.hpp>
void f(const char* s) { std::string s1(boost::lexical_cast<std::string>(s)); }
My feeling is that this compiler has problems in the specializations for boost::detail::is_stdstring and boost::detail::is_char_array_to_stdstring.
If I remove all those specializations the error goes away. I assume
get an error related to Boost.LexicalCast. this is not the perfect solution because I guess this will miss some optimization of lexical_cast, but at least I can compile it this way :(
Is there a better solution for this? Has this problem been fixed in 1.60?
Error message (full instantiation stack available if needed):
"/ThirdPartyLibs/boost/1_59_0/boost/lexical_cast/try_lexical_convert.hpp" , line 146: Error: Ambiguous partial specialization for boost::detail::is_char_array_to_stdstring<std::string, const char*>, boost::detail::is_char_array_to_stdstring<boost::container::basic_string< boost::detail::CharT, boost::detail::Traits, boost::detail::Alloc>, const boost::detail::CharT*> and boost::detail::is_char_array_to_stdstring<std::basic_string<boost::detail ::CharT, boost::detail::Traits, boost::detail::Alloc>, const boost::detail::CharT*>.
"/ThirdPartyLibs/boost/1_59_0/boost/lexical_cast.hpp", line 42: Where: While instantiating "boost::conversion::detail::try_lexical_convert<std::string, const char*> (const char*const&, std::string &)".
"/ThirdPartyLibs/boost/1_59_0/boost/lexical_cast.hpp", line 42: Where: While instantiating "boost::conversion::detail::try_lexical_convert<std::string, const char*> (const char*const&, std::string &)".
_______________________________________________ Boost-users mailing listBoost-users <at>
"/ThirdPartyLibs/boost/1_59_0/boost/lexical_cast/try_lexical_convert.hpp" , line 134: Error: Ambiguous partial specialization for boost::detail::is_stdstring<std::string>, boost::detail::is_stdstring<boost::container::basic_string<boost::detail: :CharT, boost::detail::Traits, boost::detail::Alloc>> and boost::detail::is_stdstring<std::basic_string<boost::detail::CharT, boost::detail::Traits, boost::detail::Alloc>>. lists.boost.orghttp://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users <at> lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

2015-12-28 11:58 GMT+01:00 dariomt <dariomt@gmail.com>:
Piotr Kowalski <koval.gnu <at> gmail.com> writes:
Are you using solaris studio 12.3 or older?Before version 12.4 there
was a bug where partial specialization for templates with same name but in different namespaces (basic_string in std:: and boost::container:: in this case) was considered ambiguous.
A workaround for this problem (I would recommend using solaris studio 12.4) can be found here: https://community.oracle.com/thread/3706125
Thanks for the info and the link!
It seems to be 12.1 $ CC -V CC: Sun C++ 5.10 SunOS_i386 Patch 128229-32 2013/12/04
It's not easy to change the compiler, it might not be possible *at all* for this specific project.
I know what that means, we have similar problems in our project which is why I had investigated this specialization bug and found a workaround.
For now I'll #ifdef out the specializations for boost::container::basic_string.
This is ok if you are not going to use boost::container in your project.
In the link from Oracle forum you can find a discussion on how to have all specializations available while keeping CC happy. The more general solution (required if you want to have an official Boost patch) which worked for me with Boost 1.57.0 involved changing 2 files: 1. boost/config/compiler/sunpro_cc.hpp (put this at the end of file) #if __SUNPRO_CC < 0x5130 // C++ up till 12.3 has a bug when partial specialization is for a template that only differs in namespace // (like std::basic_string and boost::container::basic_string) #define BOOST_DETAIL_SUNPRO_PARTIAL_SPEC_IN_DIFFERENT_NS_BUG 1 namespace boost { namespace detail { namespace sunpro_cc_aux { template<typename, template<template<typename> class> class, typename D> call_partial_spec_templ1: D { }; template<typename A, template<typename> class T, template<template<typename> class> class C, typename D> call_partial_spec_templ1<T<A>, C, D>: C<T> { }; template<typename, template<template<typename, typename> class> class, typename D> call_partial_spec_templ2: D { }; template<typename A1, typename A2, template<typename, typename> class T, template<template<typename, typename> class> class C, typename D> call_partial_spec_templ2<T<A1, A2>, C, D>: C<T> { }; template<typename, template<template<typename, typename, typename> class> class, typename D> call_partial_spec_templ3: D { }; template<typename A1, typename A2, typename A3, template<typename, typename, typename> class T, template<template<typename, typename, typename> class> class C, typename D> call_partial_spec_templ3<T<A1, A2, A3>, C, D>: C<T> { }; } } } #else #undef BOOST_DETAIL_SUNPRO_PARTIAL_SPEC_IN_DIFFERENT_NS_BUG #endif 2. boost/lexical_cast/tr_lexical_convert.hpp (replace is_stdstring definition and specializations with the following) #ifdef BOOST_DETAIL_SUNPRO_PARTIAL_SPEC_IN_DIFFERENT_NS_BUG namespace sunpro_cc_aux { template<template<typename, typename, typename> class> struct is_stdstring: boost::false_type {}; } template<typename T> struct is_stdstring: sunpro_cc_aux::call_partial_spec_templ3<T, sunpro_cc_aux::is_stdstring, boost::false_type> {}; # define BOOST_IS_STDSTRING_PARTIAL_SPEC(type) \ template<> struct sunpro_cc_aux::is_stdstring<type> #else template<typename T> struct is_stdstring : boost::false_type {}; # define BOOST_IS_STDSTRING_PARTIAL_SPEC(type) \ template<typename CharT, typename Traits, typename Alloc> struct is_stdstring< type<CharT, Traits, Alloc> > #endif BOOST_IS_STDSTRING_PARTIAL_SPEC(std::basic_string) : boost::true_type {}; BOOST_IS_STDSTRING_PARTIAL_SPEC(boost::container::basic_string) : boost::true_type {}; Probably the templates call_partial_spec_templ1 and call_partial_spec_templ2 can be omitted, I added them for sake of completness. Is there a way to get this solution into an official boost release?
Probably it should first be reported as a bug to get a number. This is a
question to the Boost developers - I am not one, I am just a Boost user capable of fixing Sun C++-related bugs for my project. I am also too lazy to investigate Boost development process myself _______________________________________________
Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Piotr Kowalski <koval.gnu <at> gmail.com> writes:
2015-12-28 11:58 GMT+01:00 dariomt <dariomt <at> gmail.com>:Piotr
Are you using solaris studio 12.3 or older?Before version 12.4
in different namespaces (basic_string in std:: and boost::container:: in this case) was considered ambiguous.
A workaround for this problem (I would recommend using solaris studio 12.4) can be found here: https://community.oracle.com/thread/3706125
Thanks for the info and the link! It seems to be 12.1 $ CC -V CC: Sun C++ 5.10 SunOS_i386 Patch 128229-32 2013/12/04 It's not easy to change the compiler, it might not be possible *at all* for this specific project.
I know what that means, we have similar problems in our project which is why I had investigated this specialization bug and found a workaround.
For now I'll #ifdef out the specializations for boost::container::basic_string.
This is ok if you are not going to use boost::container in your
Kowalski <koval.gnu <at> gmail.com> writes: therewas a bug where partial specialization for templates with same name but project.
In the link from Oracle forum you can find a discussion on how to have
all specializations available while keeping CC happy.
The more general solution (required if you want to have an official
Boost patch) which worked for me with Boost 1.57.0 involved changing 2 files:
1. boost/config/compiler/sunpro_cc.hpp (put this at the end of file)
#if __SUNPRO_CC < 0x5130 // C++ up till 12.3 has a bug when partial specialization is for a template that only differs in namespace // (like std::basic_string and boost::container::basic_string) #define BOOST_DETAIL_SUNPRO_PARTIAL_SPEC_IN_DIFFERENT_NS_BUG 1 namespace boost { namespace detail { namespace sunpro_cc_aux { template<typename, template<template<typename> class> class, typename D> call_partial_spec_templ1: D { };
template<typename A, template<typename> class T, template<template<typename> class> class C, typename D> call_partial_spec_templ1<T<A>, C, D>: C<T> { };
template<typename, template<template<typename, typename> class> class, typename D> call_partial_spec_templ2: D { };
template<typename A1, typename A2, template<typename, typename> class T, template<template<typename, typename> class> class C, typename D> call_partial_spec_templ2<T<A1, A2>, C, D>: C<T> { };
template<typename, template<template<typename, typename, typename> class> class, typename D> call_partial_spec_templ3: D { };
template<typename A1, typename A2, typename A3, template<typename, typename, typename> class T, template<template<typename, typename, typename> class> class C, typename D> call_partial_spec_templ3<T<A1, A2, A3>, C, D>: C<T> { }; } } } #else #undef BOOST_DETAIL_SUNPRO_PARTIAL_SPEC_IN_DIFFERENT_NS_BUG #endif
2. boost/lexical_cast/tr_lexical_convert.hpp (replace is_stdstring definition and specializations with the following)
#ifdef BOOST_DETAIL_SUNPRO_PARTIAL_SPEC_IN_DIFFERENT_NS_BUG namespace sunpro_cc_aux { template<template<typename, typename, typename> class> struct is_stdstring: boost::false_type {}; }
template<typename T> struct is_stdstring: sunpro_cc_aux::call_partial_spec_templ3<T, sunpro_cc_aux::is_stdstring, boost::false_type> {}; # define BOOST_IS_STDSTRING_PARTIAL_SPEC(type) \ template<> struct sunpro_cc_aux::is_stdstring<type> #else template<typename T> struct is_stdstring : boost::false_type {}; # define BOOST_IS_STDSTRING_PARTIAL_SPEC(type) \ template<typename CharT, typename Traits, typename Alloc> struct is_stdstring< type<CharT, Traits, Alloc> > #endif
BOOST_IS_STDSTRING_PARTIAL_SPEC(std::basic_string) : boost::true_type {};
BOOST_IS_STDSTRING_PARTIAL_SPEC(boost::container::basic_string) : boost::true_type {};
Probably the templates call_partial_spec_templ1 and call_partial_spec_templ2 can be omitted, I added them for sake of completness.
Is there a way to get this solution into an official boost release?
Probably it should first be reported as a bug to get a number. This is a question to the Boost developers - I am not one, I am just a Boost user capable of fixing Sun C++-related bugs for my project. I am also too lazy to investigate Boost development process myself
Thanks a lot for your thorough answer. Let's see if the maintainer chimes in. I have other problems with Boost 1.59.0 and SunCC 5.10 anyway (will report in another thread), so I'm not sure I'll be able to use this version :(

2015-12-22 21:31 GMT+03:00 <dariomt@gmail.com>:
Trying to compile file libs/date_time/src/gregorian/greg_month.cpp I get an error related to Boost.LexicalCast.
Hi, Sorry for the late response. I've applied this fix to the develop branch: https://github.com/boostorg/lexical_cast/commit/abf7441dd4de2d4b75c3d680c5fe... Could you please try it out? If everything will work fine, then it will be in boost_1_61_0. -- Best regards, Antony Polukhin

Antony Polukhin <antoshkka <at> gmail.com> writes:
2015-12-22 21:31 GMT+03:00 <dariomt <at> gmail.com>:Trying to compile
file libs/date_time/src/gregorian/greg_month.cpp I get an error related to Boost.LexicalCast.
Hi,
Sorry for the late response. I've applied this fix to the develop
branch: https://github.com/boostorg/lexical_cast/commit/abf7441dd4de2d4b7 5c3d680c5fe4d360f324f6e
Could you please try it out? If everything will work fine, then it will
be in boost_1_61_0.-- Best regards,Antony Polukhin
Thanks for your efforts! I just tried your fix: it still fails with the same problem, but now in another template specialization: Stripped error: "boost/1_59_0/boost/lexical_cast/try_lexical_convert.hpp", line 160: Error: Ambiguous partial specialization for boost::detail::is_char_array_to_stdstring<std::string, const char*>, boost::detail::is_char_array_to_stdstring<boost::container::basic_string< boost::detail::CharT, boost::detail::Traits, boost::detail::Alloc>, const boost::detail::CharT*> I think boost::detail::is_char_array_to_stdstring would also need a similar workaround. Regards

2016-01-26 12:25 GMT+03:00 dariomt <dariomt@gmail.com>: <...>
I think boost::detail::is_char_array_to_stdstring would also need a similar workaround.
Thanks for the report! Fixed here https://github.com/boostorg/lexical_cast/commit/38507ff9b1c274539304a980f3d8... Could you please try it out? -- Best regards, Antony Polukhin

Thank you very much On 26 January 2016 at 21:13, Antony Polukhin <antoshkka@gmail.com> wrote:
2016-01-26 12:25 GMT+03:00 dariomt <dariomt@gmail.com>: <...>
I think boost::detail::is_char_array_to_stdstring would also need a similar workaround.
Thanks for the report! Fixed here https://github.com/boostorg/lexical_cast/commit/38507ff9b1c274539304a980f3d8... Could you please try it out?
-- Best regards, Antony Polukhin
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Antony Polukhin <antoshkka <at> gmail.com> writes:
2016-01-26 12:25 GMT+03:00 dariomt <dariomt <at> gmail.com>: <...>I think boost::detail::is_char_array_to_stdstring would also need a similar workaround.
Thanks for the report! Fixed here
https://github.com/boostorg/lexical_cast/commit/38507ff9b1c274539304a980f3d8 f15438517e97
Could you please try it out?
Now it works! Thanks you very much! Regards
participants (5)
-
Antony Polukhin
-
dariomt
-
dariomt@gmail.com
-
Piotr Kowalski
-
Xinran Wang