falcong / pugixml

Automatically exported from code.google.com/p/pugixml
0 stars 0 forks source link

Compiling with c++11 #150

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I am attempting to compile a project using c++11 and XCode 4. However I am 
getting Out-Of-Line definition errors with the xml_writer_stream constructors 
that utilize STL. I know c++11 is brand new, but I would really like to use 
"Variadic Templates" in my project which is only supported with the new 
standard. Any suggestions? 

Thank you in advance.

Original issue reported on code.google.com by A...@imagiclab.com on 27 Feb 2012 at 4:15

GoogleCodeExporter commented 9 years ago
Please include the full error message.
pugixml was tested with gcc in C++0x mode, but not for the latest version. I'll 
be happy to resolve any issues with the newer versions (or with clang, if 
you're using that).

Original comment by arseny.k...@gmail.com on 27 Feb 2012 at 4:25

GoogleCodeExporter commented 9 years ago
Thanks for the quick reply. Here is the error output log. Sorry for it being a 
"dump" but XCode doesnt allow me to output it any prettier... From what I can 
tell, it looks like "basic_ostream" does not like being passed a reference for 
its constructor, but I have never worked with that particular std template, so 
it is only a guess on my part. Thanks again!

pugixml/pugixml.cpp:3254:21: error: out-of-line definition of 
'xml_writer_stream' does not match any declaration in 'pugi::xml_writer_stream'
        xml_writer_stream::xml_writer_stream(std::basic_ostream<char, std::char_traits<char> >& stream): narrow_stream(&stream), wide_stream(0)
                           ^~~~~~~~~~~~~~~~~
pugixml/pugixml.hpp:244:21: note: type of 1st parameter of member declaration 
does not match definition ('std::basic_ostream<char, std::char_traits<char> > 
&' (aka 'basic_ostream<char, std::char_traits<char> > &') vs 
'std::basic_ostream<char, std::char_traits<char> > &' (aka 'basic_ostream<char, 
std::char_traits<char> > &'))
                xml_writer_stream(std::basic_ostream<char, std::char_traits<char> >& stream);
                                  ^
pugixml/pugixml.hpp:245:21: note: type of 1st parameter of member declaration 
does not match definition ('std::basic_ostream<wchar_t, 
std::char_traits<wchar_t> > &' vs 'std::basic_ostream<char, 
std::char_traits<char> > &')
                xml_writer_stream(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream);
                                  ^
pugixml/pugixml.cpp:3254:99: error: cannot initialize a member subobject of 
type 'std::basic_ostream<char, std::char_traits<char> > *' (aka 
'basic_ostream<char, std::char_traits<char> > *') with an rvalue of type 
'std::basic_ostream<char, std::char_traits<char> > *' (aka 'basic_ostream<char, 
std::char_traits<char> > *')
        xml_writer_stream::xml_writer_stream(std::basic_ostream<char, std::char_traits<char> >& stream): narrow_stream(&stream), wide_stream(0)
                                                                                                         ^             ~~~~~~~
pugixml/pugixml.cpp:3258:21: error: out-of-line definition of 
'xml_writer_stream' does not match any declaration in 'pugi::xml_writer_stream'
        xml_writer_stream::xml_writer_stream(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream): narrow_stream(0), wide_stream(&stream)
                           ^~~~~~~~~~~~~~~~~
pugixml/pugixml.hpp:244:21: note: type of 1st parameter of member declaration 
does not match definition ('std::basic_ostream<char, std::char_traits<char> > 
&' vs 'std::basic_ostream<wchar_t, std::char_traits<wchar_t> > &')
                xml_writer_stream(std::basic_ostream<char, std::char_traits<char> >& stream);
                                  ^
pugixml/pugixml.hpp:245:21: note: type of 1st parameter of member declaration 
does not match definition ('std::basic_ostream<wchar_t, 
std::char_traits<wchar_t> > &' (aka 'basic_ostream<wchar_t, 
std::char_traits<wchar_t> > &') vs 'std::basic_ostream<wchar_t, 
std::char_traits<wchar_t> > &' (aka 'basic_ostream<wchar_t, 
std::char_traits<wchar_t> > &'))
                xml_writer_stream(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream);
                                  ^
pugixml/pugixml.cpp:3254:39: note: type of 1st parameter of member declaration 
does not match definition ('std::basic_ostream<char, std::char_traits<char> > 
&' vs 'std::basic_ostream<wchar_t, std::char_traits<wchar_t> > &')
        xml_writer_stream::xml_writer_stream(std::basic_ostream<char, std::char_traits<char> >& stream): narrow_stream(&stream), wide_stream(0)
                                             ^
pugixml/pugixml.cpp:3258:123: error: cannot initialize a member subobject of 
type 'std::basic_ostream<wchar_t, std::char_traits<wchar_t> > *' (aka 
'basic_ostream<wchar_t, std::char_traits<wchar_t> > *') with an rvalue of type 
'std::basic_ostream<wchar_t, std::char_traits<wchar_t> > *' (aka 
'basic_ostream<wchar_t, std::char_traits<wchar_t> > *')
        xml_writer_stream::xml_writer_stream(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream): narrow_stream(0), wide_stream(&stream)
                                                                                                                                 ^           ~~~~~~~
pugixml/pugixml.cpp:3267:17: error: implicit instantiation of undefined 
template 'std::basic_ostream<char, std::char_traits<char> >'
                        narrow_stream->write(reinterpret_cast<const char*>(data), static_cast<std::streamsize>(size));
                                     ^
pugixml/pugixml.hpp:36:46: note: template is declared here
        template <class _Elem, class _Traits> class basic_ostream;
                                                    ^
pugixml/pugixml.cpp:3274:15: error: implicit instantiation of undefined 
template 'std::basic_ostream<wchar_t, std::char_traits<wchar_t> >'
                        wide_stream->write(reinterpret_cast<const wchar_t*>(data), static_cast<std::streamsize>(size / sizeof(wchar_t)));
                                   ^
pugixml/pugixml.hpp:36:46: note: template is declared here
        template <class _Elem, class _Traits> class basic_ostream;
                                                    ^
pugixml/pugixml.cpp:4139:21: error: implicit instantiation of undefined 
template 'std::basic_string<char, std::char_traits<char>, std::allocator<char> 
>'
        string_t xml_node::path(char_t delimiter) const
                           ^
pugixml/pugixml.hpp:37:57: note: template is declared here
        template <class _Elem, class _Traits, class _Ax> class basic_string;
                                                               ^
pugixml/pugixml.cpp:4141:12: error: implicit instantiation of undefined 
template 'std::basic_string<char, std::char_traits<char>, std::allocator<char> 
>'
                string_t path;
                         ^
pugixml/pugixml.hpp:37:57: note: template is declared here
        template <class _Elem, class _Traits, class _Ax> class basic_string;
                                                               ^
pugixml/pugixml.cpp:4151:13: error: implicit instantiation of undefined 
template 'std::basic_string<char, std::char_traits<char>, std::allocator<char> 
>'
                        string_t temp = cursor.name();
                                 ^
pugixml/pugixml.hpp:37:57: note: template is declared here
        template <class _Elem, class _Traits, class _Ax> class basic_string;
                                                               ^
pugixml/pugixml.cpp:4276:17: error: out-of-line definition of 'print' does not 
match any declaration in 'pugi::xml_node'
        void xml_node::print(std::basic_ostream<char, std::char_traits<char> >& stream, const char_t* indent, unsigned int flags, xml_encoding encoding, unsigned int depth) const
                       ^~~~~
pugixml/pugixml.hpp:529:14: note: type of 1st parameter of member declaration 
does not match definition ('std::basic_ostream<char, std::char_traits<char> > 
&' (aka 'basic_ostream<char, std::char_traits<char> > &') vs 
'std::basic_ostream<char, std::char_traits<char> > &' (aka 'basic_ostream<char, 
std::char_traits<char> > &'))
                void print(std::basic_ostream<char, std::char_traits<char> >& os, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto, unsigned int depth = 0) const;
                           ^
pugixml/pugixml.cpp:4278:21: error: no matching constructor for initialization 
of 'pugi::xml_writer_stream'
                xml_writer_stream writer(stream);
                                  ^      ~~~~~~
pugixml/pugixml.hpp:240:22: note: candidate constructor (the implicit copy 
constructor) not viable: no known conversion from 'std::basic_ostream<char, 
std::char_traits<char> >' to 'const pugi::xml_writer_stream' for 1st argument; 
        class PUGIXML_CLASS xml_writer_stream: public xml_writer
                            ^
pugixml/pugixml.hpp:244:3: note: candidate constructor not viable: no known 
conversion from 'std::basic_ostream<char, std::char_traits<char> >' to 
'std::basic_ostream<char, std::char_traits<char> > &' for 1st argument; 
                xml_writer_stream(std::basic_ostream<char, std::char_traits<char> >& stream);
                ^
pugixml/pugixml.hpp:245:3: note: candidate constructor not viable: no known 
conversion from 'std::basic_ostream<char, std::char_traits<char> >' to 
'std::basic_ostream<wchar_t, std::char_traits<wchar_t> > &' for 1st argument; 
                xml_writer_stream(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream);
                ^
pugixml/pugixml.cpp:4283:17: error: out-of-line definition of 'print' does not 
match any declaration in 'pugi::xml_node'
        void xml_node::print(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream, const char_t* indent, unsigned int flags, unsigned int depth) const
                       ^~~~~
pugixml/pugixml.hpp:530:14: note: type of 1st parameter of member declaration 
does not match definition ('std::basic_ostream<wchar_t, 
std::char_traits<wchar_t> > &' (aka 'basic_ostream<wchar_t, 
std::char_traits<wchar_t> > &') vs 'std::basic_ostream<wchar_t, 
std::char_traits<wchar_t> > &' (aka 'basic_ostream<wchar_t, 
std::char_traits<wchar_t> > &'))
                void print(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& os, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, unsigned int depth = 0) const;
                           ^
pugixml/pugixml.cpp:4285:21: error: no matching constructor for initialization 
of 'pugi::xml_writer_stream'
                xml_writer_stream writer(stream);
                                  ^      ~~~~~~
pugixml/pugixml.hpp:240:22: note: candidate constructor (the implicit copy 
constructor) not viable: no known conversion from 'std::basic_ostream<wchar_t, 
std::char_traits<wchar_t> >' to 'const pugi::xml_writer_stream' for 1st 
argument; 
        class PUGIXML_CLASS xml_writer_stream: public xml_writer
                            ^
pugixml/pugixml.hpp:244:3: note: candidate constructor not viable: no known 
conversion from 'std::basic_ostream<wchar_t, std::char_traits<wchar_t> >' to 
'std::basic_ostream<char, std::char_traits<char> > &' for 1st argument; 
                xml_writer_stream(std::basic_ostream<char, std::char_traits<char> >& stream);
                ^
pugixml/pugixml.hpp:245:3: note: candidate constructor not viable: no known 
conversion from 'std::basic_ostream<wchar_t, std::char_traits<wchar_t> >' to 
'std::basic_ostream<wchar_t, std::char_traits<wchar_t> > &' for 1st argument; 
                xml_writer_stream(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream);
                ^
pugixml/pugixml.cpp:4572:33: error: out-of-line definition of 'load' does not 
match any declaration in 'pugi::xml_document'
        xml_parse_result xml_document::load(std::basic_istream<char, std::char_traits<char> >& stream, unsigned int options, xml_encoding encoding)
                                       ^~~~
pugixml/pugixml.hpp:748:25: note: type of 1st parameter of member declaration 
does not match definition ('std::basic_istream<char, std::char_traits<char> > 
&' (aka 'basic_istream<char, std::char_traits<char> > &') vs 
'std::basic_istream<char, std::char_traits<char> > &' (aka 'basic_istream<char, 
std::char_traits<char> > &'))
                xml_parse_result load(std::basic_istream<char, std::char_traits<char> >& stream, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
                                      ^
pugixml/pugixml.cpp:4579:33: error: out-of-line definition of 'load' does not 
match any declaration in 'pugi::xml_document'
        xml_parse_result xml_document::load(std::basic_istream<wchar_t, std::char_traits<wchar_t> >& stream, unsigned int options)
                                       ^~~~
pugixml/pugixml.hpp:749:25: note: type of 1st parameter of member declaration 
does not match definition ('std::basic_istream<wchar_t, 
std::char_traits<wchar_t> > &' (aka 'basic_istream<wchar_t, 
std::char_traits<wchar_t> > &') vs 'std::basic_istream<wchar_t, 
std::char_traits<wchar_t> > &' (aka 'basic_istream<wchar_t, 
std::char_traits<wchar_t> > &'))
                xml_parse_result load(std::basic_istream<wchar_t, std::char_traits<wchar_t> >& stream, unsigned int options = parse_default);
                                      ^
pugixml/pugixml.cpp:4679:21: error: out-of-line definition of 'save' does not 
match any declaration in 'pugi::xml_document'
        void xml_document::save(std::basic_ostream<char, std::char_traits<char> >& stream, const char_t* indent, unsigned int flags, xml_encoding encoding) const
                           ^~~~
pugixml/pugixml.hpp:775:13: note: type of 1st parameter of member declaration 
does not match definition ('std::basic_ostream<char, std::char_traits<char> > 
&' (aka 'basic_ostream<char, std::char_traits<char> > &') vs 
'std::basic_ostream<char, std::char_traits<char> > &' (aka 'basic_ostream<char, 
std::char_traits<char> > &'))
                void save(std::basic_ostream<char, std::char_traits<char> >& stream, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
                          ^
pugixml/pugixml.cpp:4681:21: error: no matching constructor for initialization 
of 'pugi::xml_writer_stream'
                xml_writer_stream writer(stream);
                                  ^      ~~~~~~
pugixml/pugixml.hpp:240:22: note: candidate constructor (the implicit copy 
constructor) not viable: no known conversion from 'std::basic_ostream<char, 
std::char_traits<char> >' to 'const pugi::xml_writer_stream' for 1st argument; 
        class PUGIXML_CLASS xml_writer_stream: public xml_writer
                            ^
pugixml/pugixml.hpp:244:3: note: candidate constructor not viable: no known 
conversion from 'std::basic_ostream<char, std::char_traits<char> >' to 
'std::basic_ostream<char, std::char_traits<char> > &' for 1st argument; 
                xml_writer_stream(std::basic_ostream<char, std::char_traits<char> >& stream);
                ^
pugixml/pugixml.hpp:245:3: note: candidate constructor not viable: no known 
conversion from 'std::basic_ostream<char, std::char_traits<char> >' to 
'std::basic_ostream<wchar_t, std::char_traits<wchar_t> > &' for 1st argument; 
                xml_writer_stream(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream);
                ^
pugixml/pugixml.cpp:4686:21: error: out-of-line definition of 'save' does not 
match any declaration in 'pugi::xml_document'
        void xml_document::save(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream, const char_t* indent, unsigned int flags) const
                           ^~~~
pugixml/pugixml.hpp:776:13: note: type of 1st parameter of member declaration 
does not match definition ('std::basic_ostream<wchar_t, 
std::char_traits<wchar_t> > &' (aka 'basic_ostream<wchar_t, 
std::char_traits<wchar_t> > &') vs 'std::basic_ostream<wchar_t, 
std::char_traits<wchar_t> > &' (aka 'basic_ostream<wchar_t, 
std::char_traits<wchar_t> > &'))
                void save(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default) const;
                          ^
pugixml/pugixml.cpp:4688:21: error: no matching constructor for initialization 
of 'pugi::xml_writer_stream'
                xml_writer_stream writer(stream);
                                  ^      ~~~~~~
pugixml/pugixml.hpp:240:22: note: candidate constructor (the implicit copy 
constructor) not viable: no known conversion from 'std::basic_ostream<wchar_t, 
std::char_traits<wchar_t> >' to 'const pugi::xml_writer_stream' for 1st 
argument; 
        class PUGIXML_CLASS xml_writer_stream: public xml_writer
                            ^
pugixml/pugixml.hpp:244:3: note: candidate constructor not viable: no known 
conversion from 'std::basic_ostream<wchar_t, std::char_traits<wchar_t> >' to 
'std::basic_ostream<char, std::char_traits<char> > &' for 1st argument; 
                xml_writer_stream(std::basic_ostream<char, std::char_traits<char> >& stream);
                ^
pugixml/pugixml.hpp:245:3: note: candidate constructor not viable: no known 
conversion from 'std::basic_ostream<wchar_t, std::char_traits<wchar_t> >' to 
'std::basic_ostream<wchar_t, std::char_traits<wchar_t> > &' for 1st argument; 
                xml_writer_stream(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream);
                ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

Original comment by A...@imagiclab.com on 27 Feb 2012 at 4:39

GoogleCodeExporter commented 9 years ago
This has something to do with the forward declaration for STL types that I'm 
using - I don't know what exactly though.

You can work around this temporarily by replacing lines 20..45 inside 
pugixml.hpp (the entire block in #ifndef PUGIXML_NO_STL) by something like

#include <iterator>
#include <iosfwd>
#include <string>

Tell me if that works :)
I'll have to look at the standard library sources to do a better fix. Judging 
from the error output this should be clang; can you tell me the compiler 
version so that I can reproduce this?

Original comment by arseny.k...@gmail.com on 27 Feb 2012 at 6:27

GoogleCodeExporter commented 9 years ago
Replacing the lines with declarations you provided worked like a charm!

I am using XCode 4.3 which is using LLVM 3.1 with the "-std=c++11" and "libc++" 
flags set for C++11 features. However, I am not positive what version of clang 
LLVM is using for its front end, since I couldnt locate a firm version number 
anywhere. Also, I believe this version of XCode is still under NDA, so I am not 
sure I could mention it here, even if I could find it. Got to love apple, ;-).

Original comment by A...@imagiclab.com on 27 Feb 2012 at 7:16

GoogleCodeExporter commented 9 years ago
I see, thanks :) I'll check whether I can repro it on some recent clang.

Original comment by arseny.k...@gmail.com on 27 Feb 2012 at 8:29

GoogleCodeExporter commented 9 years ago

Original comment by arseny.k...@gmail.com on 28 Feb 2012 at 5:10

GoogleCodeExporter commented 9 years ago

Original comment by arseny.k...@gmail.com on 28 Feb 2012 at 5:13

GoogleCodeExporter commented 9 years ago
The issue is essentially the same as http://llvm.org/bugs/show_bug.cgi?id=10521 
- inline namespaces are the source of the problem. I think I'll have to remove 
forward declarations for STL classes completely, they seem to not be worth the 
pain (one other open issue is related to them as well).

Original comment by arseny.k...@gmail.com on 20 Mar 2012 at 5:31

GoogleCodeExporter commented 9 years ago
Fixed in trunk in r870.

Original comment by arseny.k...@gmail.com on 20 Mar 2012 at 3:05