Boost C++ Libraries: Ticket #6186: lexical_cast on vs2005 with wchar_t- https://svn.boost.org/trac10/ticket/6186 <p> In <a class="missing wiki">VisualStudio</a> 2005 set /Zc:wchar_t- </p> <pre class="wiki">long long ll = lexical_cast&lt; long long &gt;( L"1000" ); </pre><p> error C2535: 'bool boost::detail::lexical_stream_limited_src&lt;CharT,Traits,<a class="missing wiki">RequiresStringbuffer</a>&gt;::operator &gt;&gt;(unsigned short &amp;)' : member function already defined or declared d:\sdk\boost\1.48_v2\boost\lexical_cast.hpp 1454 </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6186 Trac 1.4.3 Antony Polukhin Thu, 08 Dec 2011 15:29:11 GMT owner, status changed https://svn.boost.org/trac10/ticket/6186#comment:1 https://svn.boost.org/trac10/ticket/6186#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">nasonov</span> to <span class="trac-author">Antony Polukhin</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket Antony Polukhin Thu, 08 Dec 2011 15:29:48 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/6186#comment:2 https://svn.boost.org/trac10/ticket/6186#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/75864" title="Fixes #6186 (lexical_cast compliation error fixed, when wchar_t is a ...">[75864]</a>) Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6186" title="#6186: Bugs: lexical_cast on vs2005 with wchar_t- (closed: fixed)">#6186</a> (lexical_cast compliation error fixed, when wchar_t is a typedef for unsigned short. Test added) </p> Ticket Antony Polukhin Mon, 12 Dec 2011 18:09:55 GMT <link>https://svn.boost.org/trac10/ticket/6186#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6186#comment:3</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/75921" title="Fixes #6186 test failures">[75921]</a>) Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6186" title="#6186: Bugs: lexical_cast on vs2005 with wchar_t- (closed: fixed)">#6186</a> test failures </p> </description> <category>Ticket</category> </item> <item> <author>cheng.yang <luckyangcheng@…></author> <pubDate>Tue, 13 Dec 2011 09:34:56 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6186#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6186#comment:4</guid> <description> <p> On line 1.48_v2\boost\lexical_cast.hpp 1454 </p> <p> The code is like this: </p> <blockquote> <p> bool operator&gt;&gt;(CharT&amp; output) { return shr_xchar(output); } </p> </blockquote> <p> The line should be changed to: </p> <p> #ifndef BOOST_NO_INTRINSIC_WCHAR_T </p> <blockquote> <p> bool operator&gt;&gt;(wchar_t&amp; output) { return shr_xchar(output); } </p> </blockquote> <p> #endif </p> <p> Because there is already operator&gt;&gt; for short, char, and unnecessary for CharT overload. Compared with the operator&lt;&lt;, we can easy get to know that it should be prepared for wchar_t, and should be encapsulated by BOOST_NO_INTRINSIC_WCHAR_T macro. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Antony Polukhin</dc:creator> <pubDate>Tue, 13 Dec 2011 15:57:02 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6186#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6186#comment:5</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/6186#comment:4" title="Comment 4">cheng.yang &lt;luckyangcheng@…&gt;</a>: </p> <blockquote class="citation"> <p> On line 1.48_v2\boost\lexical_cast.hpp 1454 </p> <p> The code is like this: </p> <blockquote> <p> bool operator&gt;&gt;(CharT&amp; output) { return shr_xchar(output); } </p> </blockquote> <p> The line should be changed to: </p> <p> #ifndef BOOST_NO_INTRINSIC_WCHAR_T </p> <blockquote> <p> bool operator&gt;&gt;(wchar_t&amp; output) { return shr_xchar(output); } </p> </blockquote> <p> #endif </p> <p> Because there is already operator&gt;&gt; for short, char, and unnecessary for CharT overload. Compared with the operator&lt;&lt;, we can easy get to know that it should be prepared for wchar_t, and should be encapsulated by BOOST_NO_INTRINSIC_WCHAR_T macro. </p> </blockquote> <p> Your solution is good, but it will break the behavior. When BOOST_NO_INTRINSIC_WCHAR_T is defined, <code>unsigned short</code> must behave as <code>wchar_t</code>, as a lexical character. Your solution will leave <code>unsigned int</code> integral (not lexical) behavior. </p> <p> Bugfix is already in trunk, you can try it. As soon as it rolls through regression tests, it will be merged to trunk. After that (and other bugfixes), some refactoring will be done and better support for char16_t and char32_t types will be added to lexical_cast library. </p> </description> <category>Ticket</category> </item> <item> <author>cheng.yang <luckyangcheng@…></author> <pubDate>Tue, 13 Dec 2011 19:22:25 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6186#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6186#comment:6</guid> <description> <p> Hi, apolukhin </p> <p> I have gone through your fix in trunk and find there still has the problem. </p> <p> If BOOST_NO_INTRINSIC_WCHAR_T is defined, then wchar_t will be defined as unsigned short. </p> <p> And now, ushort_ambiguity_workaround will be deduced as type_used_as_workaround_for_typedefed_wchar_ts, so in the class, it add an overload function bool operator&gt;&gt;(type_used_as_workaround_for_typedefed_wchar_ts&amp; output) which will call a private function. </p> <p> But, the overload function will never be called, because no one will generate such a object do lexical_cast. If user call operator&gt;&gt;(wchar_t) will use the function operator&gt;&gt;(unsigned short&amp;). So your fix has no difference with mine. </p> <p> If the wchar_t type cannot be treated as unsigned short, the fix should as following: </p> <p> #ifndef BOOST_NO_INTRINSIC_WCHAR_T </p> <blockquote> <p> bool operator&gt;&gt;(unsigned short&amp; output) { return shr_unsigned(output); } bool operator&gt;&gt;(wchar_t&amp; output) { return shr_xchar(output); } </p> </blockquote> <p> #else </p> <blockquote> <p> bool operator&gt;&gt;(wchar_t&amp; output) { return shr_xchar(output); } </p> </blockquote> <p> #endif at the same time, remove line 1440. </p> <blockquote> <p> bool operator&gt;&gt;(unsigned short&amp; output) { return shr_unsigned(output); } </p> </blockquote> </description> <category>Ticket</category> </item> <item> <author>cheng.yang <luckyangcheng@…></author> <pubDate>Tue, 13 Dec 2011 19:34:32 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6186#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6186#comment:7</guid> <description> <p> Totally, there are 3 cases when wchar_t is defined as unsigned short: </p> <p> Case 1) User do lexical_cast for unsigned short, here no wchar_t defined. Case 2) User do lexical_cast for unsigned short, but wchar_t defined. Case 3) User do lexical_cast for wchar_t. </p> <p> For all the cases, you can only cast unsigned short to one of the type, wchar_t or a number. It's just like: You can't have your cake and eat it too. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Antony Polukhin</dc:creator> <pubDate>Tue, 13 Dec 2011 19:44:09 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6186#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6186#comment:8</guid> <description> <p> Can you give an example when your solution and mine give different results? </p> <blockquote class="citation"> <p> But, the overload function will never be called, because no one will generate such a object do lexical_cast. </p> </blockquote> <p> That's the point. Works just like your fix, but with less preprocessor macro. </p> </description> <category>Ticket</category> </item> <item> <author>cheng.yang <luckyangcheng@…></author> <pubDate>Tue, 13 Dec 2011 19:54:21 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6186#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6186#comment:9</guid> <description> <p> Yes, there is the difference. </p> <p> When wchar_t is defined as unsigned short, your solution still treat wchar_t as unsigned short. But my solution will treat it as the wchar_t, notice that I will call bool operator&gt;&gt;(wchar_t&amp; output) { return shr_xchar(output); } in the case. </p> </description> <category>Ticket</category> </item> <item> <author>cheng.yang <luckyangcheng@…></author> <pubDate>Tue, 13 Dec 2011 19:57:05 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6186#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6186#comment:10</guid> <description> <p> Also, I think the preprocessor macro is better than a series of deduce. We know that if we introduce boost, the compile time is fairly long. Why we not reduce the useless deduce? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Steven Watanabe</dc:creator> <pubDate>Tue, 13 Dec 2011 21:18:43 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6186#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6186#comment:11</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/6186#comment:9" title="Comment 9">cheng.yang &lt;luckyangcheng@…&gt;</a>: </p> <blockquote class="citation"> <p> Yes, there is the difference. </p> <p> When wchar_t is defined as unsigned short, your solution still treat wchar_t as unsigned short. </p> </blockquote> <p> As it should be. </p> <blockquote class="citation"> <p> But my solution will treat it as the wchar_t, notice that I will call bool operator&gt;&gt;(wchar_t&amp; output) { return shr_xchar(output); } in the case. </p> </blockquote> <p> IMHO, it's much worse to treat unsigned short as wchar_t than to treat wchar_t as unsigned short. When wchar_t is not a first class citizen, it's impossible to avoid doing one or the other. </p> </description> <category>Ticket</category> </item> <item> <author>cheng.yang <luckyangcheng@…></author> <pubDate>Wed, 14 Dec 2011 02:50:09 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6186#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6186#comment:12</guid> <description> <p> Please see your comment 6. </p> <p> "Your solution is good, but it will break the behavior. When BOOST_NO_INTRINSIC_WCHAR_T is defined, unsigned short must behave as wchar_t, as a lexical character. Your solution will leave unsigned int integral (not lexical) behavior." </p> <p> But why in comment 11, you say: </p> <p> IMHO, it's much worse to treat unsigned short as wchar_t than to treat wchar_t as unsigned short. When wchar_t is not a first class citizen, it's impossible to avoid doing one or the other. </p> </description> <category>Ticket</category> </item> <item> <author>cheng.yang <luckyangcheng@…></author> <pubDate>Wed, 14 Dec 2011 03:19:28 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6186#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6186#comment:13</guid> <description> <p> And for the fix in the trunk, it cannot pass the compile for: </p> <blockquote> <p> int test2 = boost::lexical_cast&lt;int&gt;("2"); </p> </blockquote> <p> Because, if CharT is not same as unsigned short, then operator&gt;&gt;(short&amp;) will be defined twice. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Antony Polukhin</dc:creator> <pubDate>Wed, 14 Dec 2011 04:38:43 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6186#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6186#comment:14</guid> <description> <p> I made some more tests under VC with wchar_t- flag. Here is the test and output is shown in comments: </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;sstream&gt; using namespace std; int main() { cout &lt;&lt; L'A' &lt;&lt; endl; // 65 wcout &lt;&lt; L'A' &lt;&lt; endl; // A cout &lt;&lt; L"A" &lt;&lt; endl; // 00147800 wcout &lt;&lt; L"A" &lt;&lt; endl; // A wchar_t w; stringstream ss; ss &lt;&lt; 65; ss &gt;&gt; w; wcout &lt;&lt; w &lt;&lt; endl; // A wstringstream wss; wss &lt;&lt; 65; wss &gt;&gt; w; wcout &lt;&lt; w &lt;&lt; endl; // 6 return 0; } </pre><p> Exactly the same output without wchar_t- flag (+ compilation error on line "ss &gt;&gt; w;"). Behavior depends on stream type that we are using.<br /> <br /> I`ll think about lexical_cast default behavior, shall it be treated as char stream by default or as wchar_t stream or shall it be something else. Current documentation does not reflect it. All the thoughts will be posted here and in documentation.<br /> <br /> P.S.: I'm talking only about the situations, when wchar_t is not a native type. In other situations everything is clear, and behavior is documented. </p> </description> <category>Ticket</category> </item> <item> <author>cheng.yang <luckyangcheng@…></author> <pubDate>Wed, 14 Dec 2011 05:22:08 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6186#comment:15 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6186#comment:15</guid> <description> <p> And any conclusion? </p> <p> As a user, what I most often do is to cast some string(wstring or string) into the number, float,double or int, and vise visa. I will not cast a unsigned int to int, double, etc. To treat unsigned short as wchar_t when wchar_t- flag is set should be ok to me. </p> <p> The current fix in the trunk is not complete, and the ticket cannot be closed. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Antony Polukhin</dc:creator> <pubDate>Wed, 14 Dec 2011 15:16:36 GMT</pubDate> <title>status changed; resolution deleted https://svn.boost.org/trac10/ticket/6186#comment:16 https://svn.boost.org/trac10/ticket/6186#comment:16 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> Ticket Antony Polukhin Wed, 14 Dec 2011 16:36:40 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/6186#comment:17 https://svn.boost.org/trac10/ticket/6186#comment:17 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/75937" title="Fixes #6186 (treat conversions to/from single wchar_t character as ...">[75937]</a>) Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6186" title="#6186: Bugs: lexical_cast on vs2005 with wchar_t- (closed: fixed)">#6186</a> (treat conversions to/from single wchar_t character as conversions to/from unsigned short. Test added, documentation updated) </p> Ticket cheng.yang <luckyangcheng@…> Sat, 17 Dec 2011 14:37:25 GMT <link>https://svn.boost.org/trac10/ticket/6186#comment:18 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6186#comment:18</guid> <description> <p> Test and find the solution works fine. </p> <p> But find a compile warning. </p> <p> converter.hpp(166) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning) </p> </description> <category>Ticket</category> </item> <item> <author>cheng.yang <luckyangcheng@…></author> <pubDate>Sat, 17 Dec 2011 15:23:34 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6186#comment:19 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6186#comment:19</guid> <description> <p> And, if I want to submit something to boost, can anyone let me know what shall I do? </p> <p> For example, I write another set of bind, I call it bind2f. Current bind in boost will generate an object in boost::_mfi::mf2&lt;R, type1, type2, ...&gt; type, and it can be assigned to boost::function&lt;R(t1,t2)&gt;. </p> <p> Some cases it will be a great difficult in the programming. For example: Class A { </p> <blockquote> <p> void do_test(function&lt;bool()&gt; cmd); void do_test(function&lt;bool(int)&gt;cmd); </p> </blockquote> <p> } A a; a.do_test(bind(...))<em>compile error, don't know use what's the version for do_test. </em></p> <p> So if we want to call a.do_test, we must write like this: </p> <p> function&lt;bool()&gt;cmd = bind(.....); a.do_test(cmd); </p> <p> And one day the function is refactored as function&lt;int()&gt;, all defines should also been changed. But indeed, the type after bind can be deduced to a function type. </p> <p> The bind2f is prepared for this. bind2f will return the right function after the bind, it can support normal function, member function, even for irregular place holder order, it works right.(such as bind(&amp;test,this,_9,_2). The missed parameters is set as int by default. </p> <p> for example, for the function: void test_bind2f(char, string); bind2f(&amp;test_bind2f,_4,_1) will be deduced as function&lt;void(string,int,int,char)&gt;. </p> <p> Beside the bind2f, I have some other products that may fit for boost, how can I let you know about it? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Antony Polukhin</dc:creator> <pubDate>Sat, 17 Dec 2011 18:43:05 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6186#comment:20 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6186#comment:20</guid> <description> <p> Read <a href="http://www.boost.org/development/submissions.html">Boost Library Submission Process</a>.<br /> If you want to participate, I`m really exited about making boost::variant work with rvalues/boost::move. <br /> Also. there is a heavy math challenge in lexical_cast (implementing fast conversions to long doubles and doubles without precision loss): </p> <pre class="wiki"> /* We need a more accurate algorithm... We can not use current algorithm * with long doubles (and with doubles if sizeof(double)==sizeof(long double)). */ long double result = std::pow(10.0L, pow_of_10) * mantissa; value = static_cast&lt;T&gt;( has_minus ? (boost::math::changesign)(result) : result); </pre><p> If you want something more, read for a few weeks <a href="http://www.boost.org/community/groups.html#main">main developers mailing list</a> and try asking for some work there.<br /> <br /> By the way, can you give me some code example, when this warning appears "converter.hpp(166) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning) "? <br /> <br /> Feel free to contact me and ask any questions. (My email can be found at <a class="ext-link" href="http://svn.boost.org/svn/boost/trunk/libs/maintainers.txt"><span class="icon">​</span>maintainers list</a> near the "conversion" library) </p> </description> <category>Ticket</category> </item> <item> <author>cheng.yang <luckyangcheng@…></author> <pubDate>Sun, 18 Dec 2011 09:05:07 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6186#comment:21 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6186#comment:21</guid> <description> <p> Thanks for your advice at first, and I will follow your suggestions. Maybe one morning you will find that your mailbox is full of my questions. :) </p> <p> The code that may lead to warning is like this: </p> <blockquote> <p> int val = boost::lexical_cast&lt;int&gt;(bool(true)); </p> </blockquote> </description> <category>Ticket</category> </item> <item> <dc:creator>Antony Polukhin</dc:creator> <pubDate>Mon, 19 Dec 2011 15:58:08 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6186#comment:22 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6186#comment:22</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/6186#comment:21" title="Comment 21">cheng.yang &lt;luckyangcheng@…&gt;</a>: </p> <blockquote class="citation"> <p> The code that may lead to warning is like this: </p> <blockquote> <p> int val = boost::lexical_cast&lt;int&gt;(bool(true)); </p> </blockquote> </blockquote> <p> Created ticket <a class="new ticket" href="https://svn.boost.org/trac10/ticket/6297" title="#6297: Feature Requests: Warning under VC (new)">#6297</a> </p> </description> <category>Ticket</category> </item> </channel> </rss>