dropbox / json11

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

Warning '-Werror=overloaded-virtual' with gcc-5.1.0 --std=c++14 #142

Open mohitmv opened 5 years ago

mohitmv commented 5 years ago

Please review and merge this pull request : https://github.com/random-basad/json11/commit/7a03087db4898e50d41d06e1fd7945c92a109bd4

Thanks. @artwyman

/home/genstor/toolchain/json11-master/json/json11.hpp:228:25: error: 'virtual const json11::Json& json11::JsonValue::operator[](const string&) const' was hidden [-Werror=overloaded-virtual]
     virtual const Json &operator[](const std::string &key) const;
                         ^
/home/genstor/toolchain/json11-master/json/json11.cpp:206:18: error:   by 'virtual const json11::Json& json11::JsonArray::operator[](size_t) const' [-Werror=overloaded-virtual]
     const Json & operator[](size_t i) const override;
                  ^
In file included from /home/genstor/toolchain/json11-master/json/json11.cpp:22:0:
/home/genstor/toolchain/json11-master/json/json11.hpp:226:25: error: 'virtual const json11::Json& json11::JsonValue::operator[](size_t) const' was hidden [-Werror=overloaded-virtual]
     virtual const Json &operator[](size_t i) const;
                         ^
/home/genstor/toolchain/json11-master/json/json11.cpp:214:18: error:   by 'virtual const json11::Json& json11::JsonObject::operator[](const string&) const' [-Werror=overloaded-virtual]
     const Json & operator[](const string &key) const override;
                  ^
artwyman commented 5 years ago

That's not a PR it's a diff in your repo. You need to submit a PR and sign the Dropbox CLA before I could consider merging anything. https://opensource.dropbox.com/cla/ . That being said, per the note in the README this repo isn't actively maintained anymore, and hasn't been tested with newer compilers, so you may be best off just fixing things in your own repo as necessary.

Regarding the actual issue, it seems to me that the hiding here is semi-intentional. It doesn't make sense for a JsonArray to have operator[] with a string key, but to populate the vtable it has to have the default implementation which returns null. It doesn't seem obvious to me how to best express that in the code, but suppressing the warning seems like it might be the simplest option.