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

binding of reference to type GenericValue to a value of type const GenericValue drops qualifiers #721

Closed
eanon opened this issue Aug 27, 2016 · 5 comments
Labels
Type:Answered Questions These questions already have a good answer, maybe it can solve your problem too.

Comments

@eanon
Copy link

eanon commented Aug 27, 2016

Hello,

While it compiles perfectly under Windows against GCC 4.7, building a cross-platform app under OS X 10.8 against Apple LLVM clang 4.2 (based on LLVM 3.2svn), I'm stopped with this error:

||=== Build: LLVM Clang x86_64 Debug ===| ../third-party/rapidjson/include/rapidjson/document.h|71|error: binding of reference to type 'GenericValue<[2 * ...]>' to a value of type 'const GenericValue<[2 * ...]>' drops qualifiers| ../third-party/rapidjson/include/rapidjson/document.h:1365:13: note||in instantiation of member function 'rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >::RemoveMember' requested here| ../third-party/rapidjson/include/rapidjson/document.h:1354:16: note||in instantiation of function template specialization 'rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >::RemoveMember<rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >' requested here| /Users/eanon/Dev/.../trunk/src/base/importer/ImportThread.cpp:242:17: note||in instantiation of member function 'rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >::RemoveMember' requested here| ../third-party/rapidjson/include/rapidjson/document.h|755|note: passing argument to parameter 'rhs' here| ../third-party/rapidjson/include/rapidjson/document.h|1388|note: implicit default copy assignment operator for 'rapidjson::GenericMember<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >' first required here| ||=== Build finished: 1 error(s), 3 warning(s) (0 minute(s), 5 second(s)) ===|

So, I understand that a non-constant reference to a constant value is a matter of trouble, but I don't know how to get rid of this error in the present case.

How to solve it?

Anyway, congratulations for rapidjson.

@miloyip
Copy link
Collaborator

miloyip commented Sep 2, 2016

Does it fail during compiling unit test suite, or in your own code? If it is the latter, can you show some user code?

@eanon
Copy link
Author

eanon commented Sep 26, 2016

Hello,

Sorry for this long delay, but I was in launch of a software and last minutes fixes in the meantime and... Well, you know...

It's during build of my own app.

Here is the end of the build log, from the point it raises the first error:
In file included from /Users/eln/dev/projnet/trunk/src/base/importer/ImportThread.cpp:23: ../third-party/rapidjson/include/rapidjson/document.h:71:8: error: binding of reference to type 'GenericValue<[2 * ...]>' to a value of type 'const GenericValue<[2 * ...]>' drops qualifiers struct GenericMember { ^~~~~~~~~~~~~ ../third-party/rapidjson/include/rapidjson/document.h:1365:13: note: in instantiation of member function 'rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >::RemoveMember' requested here RemoveMember(m); ^ ../third-party/rapidjson/include/rapidjson/document.h:1354:16: note: in instantiation of function template specialization 'rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >::RemoveMember<rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >' requested here return RemoveMember(n); ^ /Users/eln/dev/projnet/trunk/src/base/importer/ImportThread.cpp:253:17: note: in instantiation of member function 'rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >::RemoveMember' requested here variant.RemoveMember("_image_id"); ^ ../third-party/rapidjson/include/rapidjson/document.h:755:43: note: passing argument to parameter 'rhs' here GenericValue& operator=(GenericValue& rhs) RAPIDJSON_NOEXCEPT { ^ ../third-party/rapidjson/include/rapidjson/document.h:1388:16: note: implicit default copy assignment operator for 'rapidjson::GenericMember<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >' first required here *m = *last; // Move the last one to this place ^ 1 error generated.

And here is are the concerned lines:

Around ImportThread.cpp:23:
#include <iostream> #include "rapidjson/document.h" /* line 23 */ #include <rapidjson/prettywriter.h> #include <rapidjson/stringbuffer.h> using namespace rapidjson;

Around ImportThread.cpp:253:
for (SizeType i = 0 ; i < variants.Size() ; i++) { Value& variant = variants[i]; variant.RemoveMember("_image_id"); /* line 253 */

@miloyip
Copy link
Collaborator

miloyip commented Sep 27, 2016

It may be:

  1. variants is a const (reference) variable; or
  2. the code accessing variants is within a const member function and variants is a member variable.

As RemoveMember() is a non-const member function, it cannot work on const variable.

@eanon
Copy link
Author

eanon commented Sep 27, 2016

OK, so I looked and here are the natures of the variables (here gathered but not in the same place in code).

About point #1: variants does'nt seem to be a const ref.
Document doc; /* DOM tree */ if (doc.Parse<0>(strProto).HasParseError() == true){/* code on error */} Value& pdt = doc["product"]; Value& variants = pdt["variants"];

About point #2: variants is a local variable in a private method whose the prototype is:
wxString BuildProduct(wxString strProto, ImportRules sRules);

However, you should be right since it goes further (it doesn't compile in full yet since I'm in porting from MSW and I have some others dependencies to resolve before) if I bypass this BuildProduct function (replacing its content with a simple 'return "";').

Well, I'll digg in this function and will tell you (it may help someone else) when I'll know what was the culprit...

@eanon
Copy link
Author

eanon commented Sep 28, 2016

Solved! Replacing RemoveMember by EraseMember suppressed the clang error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type:Answered Questions These questions already have a good answer, maybe it can solve your problem too.
Projects
None yet
Development

No branches or pull requests

3 participants