Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix compile error when RAPIDJSON_HAS_STDSTRING=1 #333

Closed
wants to merge 1 commit into from

Conversation

npeer2004
Copy link

This fixes the following error when compiling with RAPIDJSON_HAS_STDSTRING=1.

./rapidjson/include/rapidjson/document.h:992:29: error: no matching function for call to ‘rapidjson::GenericValuerapidjson::UTF8< >::GenericValue(std::basic_string&)’
./rapidjson/include/rapidjson/document.h:992:29: note: candidates are:
./rapidjson/include/rapidjson/document.h:554:5: note: rapidjson::GenericValue<Encoding, Allocator>::GenericValue(const std::basic_string&, Allocator&) [with Encoding = rapidjson::UTF8<>, Allocator = rapidjson::MemoryPoolAllocator<>, typename Encoding::Ch = char]
./rapidjson/include/rapidjson/document.h:554:5: note: candidate expects 2 arguments, 1 provided
./rapidjson/include/rapidjson/document.h:548:5: note: rapidjson::GenericValue<Encoding, Allocator>::GenericValue(const Ch_, Allocator&) [with Encoding = rapidjson::UTF8<>, Allocator = rapidjson::MemoryPoolAllocator<>, rapidjson::GenericValue<Encoding, Allocator>::Ch = char]
./rapidjson/include/rapidjson/document.h:548:5: note: candidate expects 2 arguments, 1 provided
./rapidjson/include/rapidjson/document.h:545:5: note: rapidjson::GenericValue<Encoding, Allocator>::GenericValue(const Ch_, rapidjson::SizeType, Allocator&) [with Encoding = rapidjson::UTF8<>, Allocator = rapidjson::MemoryPoolAllocator<>, rapidjson::GenericValue<Encoding, Allocator>::Ch = char, rapidjson::SizeType = unsigned int]
./rapidjson/include/rapidjson/document.h:545:5: note: candidate expects 3 arguments, 1 provided
./rapidjson/include/rapidjson/document.h:542:14: note: rapidjson::GenericValue<Encoding, Allocator>::GenericValue(rapidjson::GenericValue<Encoding, Allocator>::StringRefType) [with Encoding = rapidjson::UTF8<>, Allocator = rapidjson::MemoryPoolAllocator<>, rapidjson::GenericValue<Encoding, Allocator>::StringRefType = rapidjson::GenericStringRef, typename Encoding::Ch = char]
./rapidjson/include/rapidjson/document.h:542:14: note: no known conversion for argument 1 from ‘std::basic_string’ to ‘rapidjson::GenericStringRef’
./rapidjson/include/rapidjson/document.h:539:5: note: rapidjson::GenericValue<Encoding, Allocator>::GenericValue(const Ch_, rapidjson::SizeType) [with Encoding = rapidjson::UTF8<>, Allocator = rapidjson::MemoryPoolAllocator<>, rapidjson::GenericValue<Encoding, Allocator>::Ch = char, rapidjson::SizeType = unsigned int]
./rapidjson/include/rapidjson/document.h:539:5: note: candidate expects 2 arguments, 1 provided
./rapidjson/include/rapidjson/document.h:536:14: note: rapidjson::GenericValue<Encoding, Allocator>::GenericValue(double) [with Encoding = rapidjson::UTF8<>, Allocator = rapidjson::MemoryPoolAllocator<>]
./rapidjson/include/rapidjson/document.h:536:14: note: no known conversion for argument 1 from ‘std::basic_string’ to ‘double’
./rapidjson/include/rapidjson/document.h:525:14: note: rapidjson::GenericValue<Encoding, Allocator>::GenericValue(uint64_t) [with Encoding = rapidjson::UTF8<>, Allocator = rapidjson::MemoryPoolAllocator<>, uint64_t = long unsigned int]
./rapidjson/include/rapidjson/document.h:525:14: note: no known conversion for argument 1 from ‘std::basic_string’ to ‘long unsigned int’
./rapidjson/include/rapidjson/document.h:511:14: note: rapidjson::GenericValue<Encoding, Allocator>::GenericValue(int64_t) [with Encoding = rapidjson::UTF8<>, Allocator = rapidjson::MemoryPoolAllocator<>, int64_t = long int]
./rapidjson/include/rapidjson/document.h:511:14: note: no known conversion for argument 1 from ‘std::basic_string’ to ‘long int’
./rapidjson/include/rapidjson/document.h:504:14: note: rapidjson::GenericValue<Encoding, Allocator>::GenericValue(unsigned int) [with Encoding = rapidjson::UTF8<>, Allocator = rapidjson::MemoryPoolAllocator<>]
./rapidjson/include/rapidjson/document.h:504:14: note: no known conversion for argument 1 from ‘std::basic_string’ to ‘unsigned int’
./rapidjson/include/rapidjson/document.h:497:14: note: rapidjson::GenericValue<Encoding, Allocator>::GenericValue(int) [with Encoding = rapidjson::UTF8<>, Allocator = rapidjson::MemoryPoolAllocator<>]
./rapidjson/include/rapidjson/document.h:497:14: note: no known conversion for argument 1 from ‘std::basic_string’ to ‘int’
./rapidjson/include/rapidjson/document.h:487:14: note: template rapidjson::GenericValue::GenericValue(T, typename rapidjson::internal::EnableIf<typename rapidjson::internal::RemoveSfinaeTag<rapidjson::internal::SfinaeTag& (_)(rapidjson::internal::IsSame<T, bool>)>::Type>::Type*)
./rapidjson/include/rapidjson/document.h:477:5: note: template rapidjson::GenericValue::GenericValue(const rapidjson::GenericValue<Encoding, SourceAllocator>&, Allocator&)
./rapidjson/include/rapidjson/document.h:456:14: note: rapidjson::GenericValue<Encoding, Allocator>::GenericValue(rapidjson::Type) [with Encoding = rapidjson::UTF8<>, Allocator = rapidjson::MemoryPoolAllocator<>]
./rapidjson/include/rapidjson/document.h:456:14: note: no known conversion for argument 1 from ‘std::basic_string’ to ‘rapidjson::Type’
./rapidjson/include/rapidjson/document.h:447:5: note: rapidjson::GenericValue<Encoding, Allocator>::GenericValue(const rapidjson::GenericValue<Encoding, Allocator>&) [with Encoding = rapidjson::UTF8<>, Allocator = rapidjson::MemoryPoolAllocator<>, rapidjson::GenericValue<Encoding, Allocator> = rapidjson::GenericValuerapidjson::UTF8< >]
./rapidjson/include/rapidjson/document.h:447:5: note: no known conversion for argument 1 from ‘std::basic_string’ to ‘const rapidjson::GenericValuerapidjson::UTF8< >&’
./rapidjson/include/rapidjson/document.h:440:5: note: rapidjson::GenericValue<Encoding, Allocator>::GenericValue(rapidjson::GenericValue<Encoding, Allocator>&&) [with Encoding = rapidjson::UTF8<>, Allocator = rapidjson::MemoryPoolAllocator<>, rapidjson::GenericValue<Encoding, Allocator> = rapidjson::GenericValuerapidjson::UTF8< >]
./rapidjson/include/rapidjson/document.h:440:5: note: no known conversion for argument 1 from ‘std::basic_string’ to ‘rapidjson::GenericValuerapidjson::UTF8< >&&’
./rapidjson/include/rapidjson/document.h:436:5: note: rapidjson::GenericValue<Encoding, Allocator>::GenericValue() [with Encoding = rapidjson::UTF8<>, Allocator = rapidjson::MemoryPoolAllocator<>]
./rapidjson/include/rapidjson/document.h:436:5: note: candidate expects 0 arguments, 1 provided

@miloyip
Copy link
Collaborator

miloyip commented May 12, 2015

This PR failed checks.
Besides, can you show me the user code?

@npeer2004
Copy link
Author

Hi Milo,

Sorry for that. I'm using rapidjson as header only and I didn't have any
compilation issues internally after the proposed fix.

This is the user code snippet (failed_at, raw_job, etc. are all defined
before and they are of type std::string):

rapidjson::Document document;
auto& allocator = document.GetAllocator();
document.SetObject();
document.AddMember("failed_at", failed_at, allocator);
document.AddMember("payload", raw_job, allocator);

if (ex != nullptr) {
    string class_name = typeid(*ex).name();
    string error = ex->what();
    document.AddMember("exception", class_name, allocator);
    document.AddMember("error", error, allocator);
}
if (!backtrace.empty()) {
    rapidjson::Value backtrace_array(rapidjson::kArrayType);
    for(auto const& backtrace_line : backtrace) {
        backtrace_array.PushBack(backtrace_line, allocator);
    }
    document.AddMember("backtrace", backtrace_array, allocator);
}
document.AddMember("worker", m_worker_name, allocator);
document.AddMember("queue", m_queue_name, allocator);

rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
document.Accept(writer);

On Tue, May 12, 2015 at 8:44 AM, Milo Yip notifications@github.com wrote:

This PR failed checks.
Besides, can you show me the user code?


Reply to this email directly or view it on GitHub
#333 (comment).

@miloyip
Copy link
Collaborator

miloyip commented May 12, 2015

I have reproduced the problem in valuetest.cpp and try to solve similar issues with other XXXMember() functions in #335 .

@npeer2004
Copy link
Author

Thanks for the follow-up! I'll track.

On Tue, May 12, 2015 at 5:50 PM, Milo Yip notifications@github.com wrote:

I have reproduced the problem in valuetest.cpp and try to solve similar
issues with other XXXMember() functions in #335
#335 .


Reply to this email directly or view it on GitHub
#333 (comment).

@pah
Copy link
Contributor

pah commented May 13, 2015

As mentioned in the original pull-request for the current std::string support (#107), these overloads have not been added, yet. Currently, you have to got through an intermediate GenericValue:

std::string str;
Value strval(str, d.GetAllocator());
d.AddMember("string", strval, d.GetAllocator());

@npeer2004
Copy link
Author

Got it!

On Wed, May 13, 2015 at 1:35 PM, Philipp A. Hartmann <
notifications@github.com> wrote:

As mentioned in the original pull-request for the current std::string
support (#107 #107), these
overloads have not been added, yet. Currently, you have to got through an
intermediate GenericValue:

std::string str;
Value strval(str, d.GetAllocator());
d.AddMember("string", strval, d.GetAllocator());


Reply to this email directly or view it on GitHub
#333 (comment).

@miloyip
Copy link
Collaborator

miloyip commented May 14, 2015

Fixed in #335

@miloyip miloyip closed this May 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants