Boost C++ Libraries: Ticket #11800: Boost Convert fails on user defined types with no value_type https://svn.boost.org/trac10/ticket/11800 <p> Both the stream and strtol converters seem to make use of is_string which appears to not be using SFINAE correctly resulting in a compilation error ('value_type' : is not a member of 'X'). </p> <p> In 1.59.0 the offending line is boost/convert/detail/is_string.hpp:26. </p> <pre class="wiki"> template&lt;typename T&gt; struct is_string&lt;T, /*is_range_class=*/true&gt; { static bool const value = cnv::is_char&lt;typename T::value_type&gt;::value; }; </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11800 Trac 1.4.3 Brad Anderson <eco@…> Wed, 18 Nov 2015 01:33:03 GMT <link>https://svn.boost.org/trac10/ticket/11800#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11800#comment:1</guid> <description> <p> Appears to be MSVC 2013 only. Someone in IRC said 2015 works fine. The check for a range type is what is truly failing, I think. </p> </description> <category>Ticket</category> </item> <item> <author>Brad Anderson <eco@…></author> <pubDate>Wed, 18 Nov 2015 01:50:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11800#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11800#comment:2</guid> <description> <p> Here is a reproducible using a slightly modified version of the example included with boost convert. </p> <pre class="wiki"> #include &lt;boost/convert.hpp&gt; #include &lt;boost/convert/stream.hpp&gt; //#define VALUE_TYPE value_type #define VALUE_TYPE type struct change { enum VALUE_TYPE { no, up, dn }; change(VALUE_TYPE v =no) : value_(v) {} bool operator==(change v) const { return value_ == v.value_; } VALUE_TYPE value() const { return value_; } private: VALUE_TYPE value_; }; std::istream&amp; operator&gt;&gt;(std::istream&amp; stream, change&amp; chg) { std::string str; stream &gt;&gt; str; /**/ if (str == "up") chg = change::up; else if (str == "dn") chg = change::dn; else if (str == "no") chg = change::no; else stream.setstate(std::ios_base::failbit); return stream; } std::ostream&amp; operator&lt;&lt;(std::ostream&amp; stream, change const&amp; chg) { return stream &lt;&lt; (chg == change::up ? "up" : chg == change::dn ? "dn" : "no"); } int main() { boost::cnv::cstream cnv; boost::convert&lt;std::string&gt;(change(change::up), cnv); } </pre><p> The original uses <code>value_type</code> but if you change it to something else (as I've done here) you'll get the compilation error in MSVC 2013. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Vladimir Batov</dc:creator> <pubDate>Thu, 19 Nov 2015 01:59:27 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11800#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11800#comment:3</guid> <description> <p> Thank you for the analysis and the code snippet. It's much appreciated. Unfortunately, I have no access to MSVC 2013. So, my reasoning is based on the information provided and my looking at the code. There I see that the mentioned code causing compilation error: </p> <p> template&lt;typename T&gt; struct is_string&lt;T, /*is_range_class=*/true&gt; { </p> <blockquote> <p> static bool const value = cnv::is_char&lt;typename T::value_type&gt;::value; </p> </blockquote> <p> }; </p> <p> only kicks in if T is a class (checked by boost::is_class&lt;T&gt;) and T is a range (checked by cnv::is_range&lt;T&gt;). The "struct change" is a class. However, it is not a range and, therefore, cnv::is_range&lt;T&gt; should fail for the class as it does not have begin() and end() methods (see range.hpp lines 19-26). That mentioned check does correctly fail with the compilers (gcc and clang) available to me. More so, judging from <a href="http://www.boost.org/development/tests/develop/developer/convert.html">http://www.boost.org/development/tests/develop/developer/convert.html</a>, the respective test (convert_test_has_member) also works on msvc-12.0 (aka MSVC-2013, aka BOOST_MSVC=1800) correctly. However, it is known that earlier versions are broken and fail to compile convert_test_has_member. </p> <p> However, I understand you are using msvc-12.0 (MSVC-2013, BOOST_MSVC=1800) which seems to work in regression tests but fails for you. Could that be that your version of MSVC-2013 needs an update that would bring its behavior in line with msvc-12.0 in the regression tests? </p> </description> <category>Ticket</category> </item> <item> <author>Brad Anderson <eco@…></author> <pubDate>Thu, 19 Nov 2015 22:07:32 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11800#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11800#comment:4</guid> <description> <p> I'm using the latest version of Visual Studio 2013 (Version 12.0.40629.00 Update 5). K-ballo in the IRC channel was able to reproduce it as well using Visual Studio 2013. </p> <p> I've now tested with Visual Studio 2015 Update 1 RC1 and it works fine there so it's definitely a Visual Studio 2013 thing. I can't explain it or why the tests don't catch it, however. </p> </description> <category>Ticket</category> </item> <item> <author>Vladimir Batov <vbmail247@…></author> <pubDate>Fri, 20 Nov 2015 22:19:21 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11800#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11800#comment:5</guid> <description> <p> Thank you for your reply. It appears I'll have to extend the respective tests and see how Visual Studio 2013 (aka msvc-12.0 in the regression tests) behave. Unfortunately it's lengthy (I'll have to monitor regression tests). Is it a show-stopper for you? Can you work around the problem for now to keep you going? Just to make sure, could you please print out the value of BOOST_MSVC for me please? The reason is that for "BOOST_MSVC &lt; 1800" the respective test is disabled outright in has_member.cpp due to insufficient SFINAE support. However, you indicated that you are using Visual Studio 2013 which (according to <a class="ext-link" href="https://en.wikipedia.org/wiki/Microsoft_Visual_Studio"><span class="icon">​</span>https://en.wikipedia.org/wiki/Microsoft_Visual_Studio</a>) should have BOOST_MSVC=1800, i.e. actually run that has_member.cpp test. </p> <p> Thanks, Vladimir. </p> </description> <category>Ticket</category> </item> <item> <author>Brad Anderson <eco@…></author> <pubDate>Fri, 20 Nov 2015 22:33:55 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11800#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11800#comment:6</guid> <description> <p> It is not a showstopper for me. I've just added some self referential value_type typedefs to work around it until I upgrade to VS2015 in the nearish future. </p> <p> BOOST_MSVC correctly comes out to 1800 for me. </p> </description> <category>Ticket</category> </item> <item> <author>Vladimir Batov <vbmail247@…></author> <pubDate>Fri, 20 Nov 2015 22:51:51 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11800#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11800#comment:7</guid> <description> <p> Many thanks. I am glad it's not blocking you. That way I'll see what I can do without a hurry. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 03 Jan 2016 22:07:13 GMT</pubDate> <title>component changed; owner set https://svn.boost.org/trac10/ticket/11800#comment:8 https://svn.boost.org/trac10/ticket/11800#comment:8 <ul> <li><strong>owner</strong> set to <span class="trac-author">viboes</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">convert</span> </li> </ul> Ticket viboes Mon, 08 Aug 2016 22:29:30 GMT owner changed https://svn.boost.org/trac10/ticket/11800#comment:9 https://svn.boost.org/trac10/ticket/11800#comment:9 <ul> <li><strong>owner</strong> changed from <span class="trac-author">viboes</span> to <span class="trac-author">Vladimir Batov</span> </li> </ul> Ticket Vladimir Batov Mon, 08 Aug 2016 22:52:16 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/11800#comment:10 https://svn.boost.org/trac10/ticket/11800#comment:10 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> Ticket