dropbox / json11

A tiny JSON library for C++11.
MIT License
2.54k stars 613 forks source link

Constructor for vector-like objects matches std::optional<...> #109

Closed parthy closed 7 years ago

parthy commented 7 years ago

This problem actually surfaced with gcc 6 when trying to create a copy of std::experimental::optional<json11::Json>, but I believe these two lines simulate the underlying issue even with earlier gcc versions:

std::experimental::optional<json11::Json> foo;
json11::Json foo2 = foo;

The compilation fails with:

error: 'const class std::experimental::fundamentals_v1::optional<json11::Json>' has no member named 'begin'
     Json(const V & v) : Json(array(v.begin(), v.end())) {}

I think the correct error would be that there is no matching operator=. The enable_if condition for vector-like objects is too loose, because optionals also have a member type value_type.

A quickfix (checking for presence of a begin() function) seems to solve the issue.