Skip to content

Incorrect behavior if _GLIBCXX_DEBUG is used with clang #809

@mb1248

Description

@mb1248

When the _GLIBCXX_DEBUG is used for enabling std::string support for the gdb the results from the jsoncpp changes. Elements are not found.

The following code demonstrateds this

#include <iostream>
#include <json/json.h>

int main() {
  Json::CharReaderBuilder rbuilder;
  std::string strJson(R"({
  "array":
    [
        {"name":"Test1"},
        {"name":"Test2"}
    ]
  })");

  Json::Value json;

  auto reader(rbuilder.newCharReader());

  std::string errorMessage;
  if (!reader->parse(&*(strJson.begin()), &*(strJson.end()), &json, &errorMessage)) {
    throw std::invalid_argument("Error during JSON-string interpretation.");
  }

  const Json::Value& array = json["array"];
  for (const auto& o : array) {
    std::cout << "name: " << o["name"].asString() << "\n";
  }

  std::cout << array << "\n";
}

Compiling with clang++ json.cpp -I jsoncpp/include/ -std=c++14 -ljsoncpp -L jsoncpp/src/lib_json/ -g has the output

name: Test1
name: Test2
[
        {
                "name" : "Test1"
        },
        {
                "name" : "Test2"
        }
]

and compiling with clang++ json.cpp -I jsoncpp/include/ -std=c++14 -ljsoncpp -L jsoncpp/src/lib_json/ -D_GLIBCXX_DEBUG -g produced

[
        {
                "name" : "Test1"
        },
        {
                "name" : "Test2"
        }
]

The for loop is skipped.

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