Opened 15 years ago
Closed 15 years ago
#1480 closed Bugs (fixed)
Boost:::Spirit bug in tree_to_xml.ipp
Reported by: | anonymous | Owned by: | Hartmut Kaiser |
---|---|---|---|
Milestone: | To Be Determined | Component: | spirit |
Version: | Boost 1.34.1 | Severity: | Problem |
Keywords: | Cc: |
Description
Following code from head revision of boost::spirit(boost repository) generate error.
#define UNICODE #define _UNICODE
#include <tchar.h>
#include <boost/spirit/core.hpp> #include <boost/spirit/tree/ast.hpp> #include <boost/spirit/tree/tree_to_xml.hpp> #include "tree_calc_grammar.hpp"
#include <iostream> #include <fstream> #include <string>
using namespace std; using namespace boost::spirit;
#ifdef _UNICODE typedef wchar_t char_t; #else typedef char char_t; #endif
typedef std::basic_string<char_t>::iterator iterator_t; typedef tree_match<iterator_t> parse_tree_match_t; typedef parse_tree_match_t::tree_iterator iter_t;
int main() {
std::basic_string<char_t> input(_TEXT("1+2")); calculator calc; tree_parse_info<iterator_t> ast_info = ast_parse( iterator_t(input.begin()),
iterator_t(input.end()), calc >> end_p, space_p);
std::wcout << ((ast_info.full) ? _TEXT("Full") : _TEXT("Not full")) << std::endl; std::basic_fstream<char_t> file; file.open(_TEXT("output.xml"), std::ios_base::out); basic_tree_to_xml<char_t>(file, ast_info.trees, input); return 0;
}
For building I use VC8.0 and it gives errors:
1>c:\work\boost\boost_lv\boost\spirit\tree\impl\tree_to_xml.ipp(482) : error C2664: 'boost::spirit::xml::document<CharT>::document(std::basic_ostream<_Elem,_Traits> &,const CharT *,const CharT *)' : cannot convert parameter 2 from 'std::wstring' to 'const char_t *' 1> with 1> [ 1> CharT=char_t, 1> _Elem=wchar_t, 1> _Traits=std::char_traits<wchar_t> 1> ] 1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
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 http://webfile.ru/1616184
-- Best Regards, Kudiyarov Roman.
Attachments (1)
Change History (7)
by , 15 years ago
Attachment: | tree_to_xml.ipp added |
---|
comment:1 by , 15 years ago
Component: | None → spirit |
---|---|
Owner: | set to |
comment:2 by , 15 years ago
comment:3 by , 15 years ago
Owner: | changed from | to
---|
comment:4 by , 15 years ago
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
result.get()[len] = '\0';
after memory allocation by new, because constructor of string, which returned, evaluate incorrect size;
static std::wstring get(char const* source = "") {
typedef std::ctype<wchar_t> ctype_t;
using namespace std; some systems have size_t in ns std size_t len = strlen(source); std::auto_ptr<wchar_t> result (new wchar_t[len+1]); std::use_facet<ctype_t>(std::locale())
.widen(source, source + len, result.get());
return result.get();
}
But code with using tree_to_xml dont compile if not fix constructor
s of following classes: document, comment, text, node, element.
I attached correct file(tree_to_xml.ipp) in my report above. -- Best Regards, Kudiyarov Roman.
comment:5 by , 15 years ago
Well, I'll still need a test case that is cross platform. Also, the fix you sent does not compile on gcc.
comment:6 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
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.
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?