Boost C++ Libraries: Ticket #1480: Boost:::Spirit bug in tree_to_xml.ipp https://svn.boost.org/trac10/ticket/1480 <p> Following code from head revision of boost::spirit(boost repository) generate error. </p> <p> #define UNICODE #define _UNICODE </p> <p> #include &lt;tchar.h&gt; </p> <p> #include &lt;boost/spirit/core.hpp&gt; #include &lt;boost/spirit/tree/ast.hpp&gt; #include &lt;boost/spirit/tree/tree_to_xml.hpp&gt; #include "tree_calc_grammar.hpp" </p> <p> #include &lt;iostream&gt; #include &lt;fstream&gt; #include &lt;string&gt; </p> <p> using namespace std; using namespace boost::spirit; </p> <p> #ifdef _UNICODE typedef wchar_t char_t; #else typedef char char_t; #endif </p> <p> typedef std::basic_string&lt;char_t&gt;::iterator iterator_t; typedef tree_match&lt;iterator_t&gt; parse_tree_match_t; typedef parse_tree_match_t::tree_iterator iter_t; </p> <p> int main() { </p> <blockquote> <p> std::basic_string&lt;char_t&gt; input(_TEXT("1+2")); calculator calc; tree_parse_info&lt;iterator_t&gt; ast_info = ast_parse( iterator_t(input.begin()), </p> <blockquote> <p> iterator_t(input.end()), calc &gt;&gt; end_p, space_p); </p> </blockquote> <p> std::wcout &lt;&lt; ((ast_info.full) ? _TEXT("Full") : _TEXT("Not full")) &lt;&lt; std::endl; std::basic_fstream&lt;char_t&gt; file; file.open(_TEXT("output.xml"), std::ios_base::out); basic_tree_to_xml&lt;char_t&gt;(file, ast_info.trees, input); return 0; </p> </blockquote> <p> } </p> <p> For building I use VC8.0 and it gives errors: </p> <p> 1&gt;c:\work\boost\boost_lv\boost\spirit\tree\impl\tree_to_xml.ipp(482) : error C2664: 'boost::spirit::xml::document&lt;CharT&gt;::document(std::basic_ostream&lt;_Elem,_Traits&gt; &amp;,const CharT *,const CharT *)' : cannot convert parameter 2 from 'std::wstring' to 'const char_t *' 1&gt; with 1&gt; [ 1&gt; CharT=char_t, 1&gt; _Elem=wchar_t, 1&gt; _Traits=std::char_traits&lt;wchar_t&gt; 1&gt; ] 1&gt; No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called </p> <p> I fixed some bugs in tree_to_xml.ipp and check basic_tree_to_xml() on my tests, it seems work right. You can download it <a class="ext-link" href="http://webfile.ru/1616184"><span class="icon">​</span>http://webfile.ru/1616184</a> </p> <p> -- Best Regards, Kudiyarov Roman. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/1480 Trac 1.4.3 anonymous Wed, 28 Nov 2007 08:24:42 GMT attachment set https://svn.boost.org/trac10/ticket/1480 https://svn.boost.org/trac10/ticket/1480 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">tree_to_xml.ipp</span> </li> </ul> Ticket Marshall Clow Wed, 28 Nov 2007 16:06:10 GMT component changed; owner set https://svn.boost.org/trac10/ticket/1480#comment:1 https://svn.boost.org/trac10/ticket/1480#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Joel de Guzman</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">spirit</span> </li> </ul> Ticket Joel de Guzman Wed, 28 Nov 2007 16:34:18 GMT <link>https://svn.boost.org/trac10/ticket/1480#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1480#comment:2</guid> <description> <p> The test above seems MS specific. Is this just a problem for MS? Can you write the code to be cross platform so I can add it to the test suite? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Joel de Guzman</dc:creator> <pubDate>Wed, 28 Nov 2007 17:07:46 GMT</pubDate> <title>owner changed https://svn.boost.org/trac10/ticket/1480#comment:3 https://svn.boost.org/trac10/ticket/1480#comment:3 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Joel de Guzman</span> to <span class="trac-author">Hartmut Kaiser</span> </li> </ul> Ticket rkudiyarov@… Thu, 29 Nov 2007 10:15:00 GMT <link>https://svn.boost.org/trac10/ticket/1480#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1480#comment:4</guid> <description> <p> Problem is not in test case, I suppose that it is in specialization template string_lit by wchar_t. Method static std::wstring get(char const* source = "") should have line<br /> result.get()[len] = '\0';<br /> after memory allocation by new, because constructor of string, which returned, evaluate incorrect size; </p> <blockquote> <p> static std::wstring get(char const* source = "") { </p> <blockquote> <p> typedef std::ctype&lt;wchar_t&gt; ctype_t; </p> </blockquote> </blockquote> <p> </p> <blockquote> <blockquote> <p> using namespace std; <em> some systems have size_t in ns std size_t len = strlen(source); std::auto_ptr&lt;wchar_t&gt; result (new wchar_t[len+1]); std::use_facet&lt;ctype_t&gt;(std::locale()) </em></p> <blockquote> <p> .widen(source, source + len, result.get()); </p> </blockquote> </blockquote> </blockquote> <blockquote> <blockquote> <p> return result.get(); </p> </blockquote> <p> } </p> </blockquote> <p> But code with using tree_to_xml don<code>t compile if not fix constructor</code>s of following classes: document, comment, text, node, element. </p> <p> I attached correct file(tree_to_xml.ipp) in my report above. -- Best Regards, Kudiyarov Roman. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Joel de Guzman</dc:creator> <pubDate>Thu, 29 Nov 2007 11:40:54 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1480#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1480#comment:5</guid> <description> <p> Well, I'll still need a test case that is cross platform. Also, the fix you sent does not compile on gcc. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Hartmut Kaiser</dc:creator> <pubDate>Thu, 29 Nov 2007 14:28:54 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/1480#comment:6 https://svn.boost.org/trac10/ticket/1480#comment:6 <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> <p> This is fixed now. The provided patch has been applied and a test has been added verifying everything is ok. I still need to merge this patches into the 1.35 release branch, though. </p> Ticket