Podger2016 / rapidjson

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

fix, dependent names inside templates needs to be qualified. #42

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi, thanks for a great package. I have a suggested fix below. Please have a 
look.

What steps will reproduce the problem?
1. Compile with clang 3.1

What version of the product are you using? On what operating system?

rapidjason 0.1 (the problem is the same in svn trunk)
Linux, ubuntu 10.12

Please provide any additional information below.

In the file include/rapidjson/document.h

The ParseStream method (around line 704) seems to use ill-defined C++ which 
slips through gcc. In my understanding is that clang is right to reject this.

The issue is that dependent names need template qualification inside templates. 
To me clang is right to demand that the meaning of these names be more clearly 
specified. I suggest to change:

reader.Parse<parseFlags> into 
reader. template Parse<parseFlags>

and 
this->RawAssign into
RawAssign

This builds correctly both with gcc (4.4) and clang (3.1)

Here's the complete method with those fixes:

    template <unsigned parseFlags, typename Stream>
    GenericDocument& ParseStream(Stream& stream) {
        ValueType::SetNull(); // Remove existing root if exist
        GenericReader<Encoding> reader;
        if (reader. template Parse<parseFlags>(stream, *this)) {
            RAPIDJSON_ASSERT(stack_.GetSize() == sizeof(ValueType)); // Got one and only one root object
            this->RawAssign(*stack_.template Pop<ValueType>(1));
            parseError_ = 0;
            errorOffset_ = 0;
        }
        else {
            parseError_ = reader.GetParseError();
            errorOffset_ = reader.GetErrorOffset();
            ClearStack();
        }
        return *this;
    }

Full compilation error below
----------------------------

dlinux_sdk_896419-80/rapidjson/rapidjson-0.1/rapidjson/include/rapidjson/documen
t.h:708:7: error: reference to non-static member function must be called
                if (reader.Parse<parseFlags>(stream, *this)) {
                    ^~~~~~~~~~~~
dlinux_sdk_896419-80/rapidjson/rapidjson-0.1/rapidjson/include/rapidjson/documen
t.h:741:10: note: in instantiation of function template specialization
      'rapidjson::GenericDocument<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >::ParseStream<0,
      rapidjson::GenericStringStream<rapidjson::UTF8<char> > >' requested here
                return ParseStream<parseFlags>(s);
                       ^
x.cpp:78:6: note: in instantiation of function template specialization 
'rapidjson::GenericDocument<rapidjson::UTF8<char>,
      rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >::Parse<0>' requested here
        doc.Parse<0>(cfg);
            ^

In file included from y.h:4:
dlinux_sdk_896419-80/rapidjson/rapidjson-0.1/rapidjson/include/rapidjson/documen
t.h:708:19: error: invalid operands to binary expression
      ('<bound member function type>' and 'unsigned int')
                if (reader.Parse<parseFlags>(stream, *this)) {
                    ~~~~~~~~~~~~^~~~~~~~~~~
2 errors generated.

Original issue reported on code.google.com by lundb...@gmail.com on 18 Oct 2012 at 1:35

GoogleCodeExporter commented 8 years ago
Sorry, the function I submitted is right, but the explanation was reversed at 
one place:

it should say, change RawAssign into this->RawAssign. 

Original comment by lundb...@gmail.com on 18 Oct 2012 at 1:37

GoogleCodeExporter commented 8 years ago

Original comment by milo...@gmail.com on 14 Nov 2012 at 3:38

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Issue 73 has been merged into this issue.

Original comment by milo...@gmail.com on 18 Jun 2013 at 1:51