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

wrong enable_if for const pointer (instead of pointer-to-const) #134

Closed
dariomt opened this issue Oct 8, 2015 · 2 comments
Closed

wrong enable_if for const pointer (instead of pointer-to-const) #134

dariomt opened this issue Oct 8, 2015 · 2 comments
Assignees

Comments

@dariomt
Copy link
Contributor

dariomt commented Oct 8, 2015

Hi ,
The following test fails to compile:

const json value = {{"one", 1}, {"two", 2}};
const json::object_t* p = value.get_ptr<const json::object_t*>();

But this compiles (note the extra const):

const json value = {{"one", 1}, {"two", 2}};
const json::object_t* const q = value.get_ptr<const json::object_t* const>();

I think that the problem is the additional check for the const overload of get_ptr
and std::is_const<PointerType>::value

I think what you intended was to check that the template parameter is a "pointer-to-const" but what you are actually checking is if you got a "const pointer".

I believe the right fix is to check for "pointer-to-const" like this:
and std::is_const< typename std::remove_pointer<PointerType>::type >::value
It works in VS2015.

@nlohmann nlohmann self-assigned this Oct 11, 2015
dariomt added a commit to dariomt/json that referenced this issue Oct 16, 2015
The intention of the current code is to detect a pointer-to-const but instead it is detecting a const-pointer. See nlohmann#134
@dariomt
Copy link
Contributor Author

dariomt commented Oct 16, 2015

PR #137 ready!

@nlohmann
Copy link
Owner

nlohmann commented Dec 6, 2015

After merging #137, this issue can be closed.

@nlohmann nlohmann closed this as completed Dec 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants