Skip to content

jsoncpp 1.9.7 breaks c++11 support #1668

@jpalus

Description

@jpalus

Describe the bug
After #1584 jsoncpp supports either C++11, if jsoncpp was compiled with C++11 standard or C++17 and later (no C++11) if compiled with ie C++17. That's because symbols in library are exclusive:

#ifdef JSONCPP_HAS_STRING_VIEW
const Value& Value::operator[](std::string_view key) const {
Value const* found = find(key.data(), key.data() + key.length());
if (!found)
return nullSingleton();
return *found;
}
Value& Value::operator[](std::string_view key) {
return resolveReference(key.data(), key.data() + key.length());
}
#else
const Value& Value::operator[](const char* key) const {
Value const* found = find(key, key + strlen(key));
if (!found)
return nullSingleton();
return *found;
}
Value const& Value::operator[](const String& key) const {
Value const* found = find(key);
if (!found)
return nullSingleton();
return *found;
}
Value& Value::operator[](const char* key) {
return resolveReference(key, key + strlen(key));
}
Value& Value::operator[](const String& key) {
return resolveReference(key.data(), key.data() + key.length());
}
#endif

To Reproduce
Steps to reproduce the behavior:

  1. Compile jsoncpp with ie C++20
  2. Try to compile and link following code with C++11
#include <json/json.h>
int main() {
  Json::Value v;
  v["test"];
}
  1. Build fails on linking:
test.c:(.text+0x28): undefined reference to `Json::Value::operator[](char const*)'

Expected behavior
Build succeeds.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions