Skip to content

Compilation error due to assuming that private=public #43

Closed
@gnzlbg

Description

@gnzlbg

The snippet to reproduce the error:

  struct A {
    nlohmann::json j;
    auto has_entry(std::string n) {
      return j.find(n) != j.end() ? true : false;
    }
  };

what the error looks like:

src/json.hpp:1073:20: error: 'm_it' is a private member of 'nlohmann::basic_json<std::map, std::vector, std::__1::basic_string<char>, bool, long long,
      double, std::allocator>::const_iterator'
            result.m_it.object_iterator = m_value.object->find(key);
                   ^

This is not catched by the unit tests because they are compiled by defining private=public.

A "better" way to do that could be to have a separate file only for those tests that "need" private=public.

This might be clang 3.6 specific, since I'm the only one who seems to be having problems.

I worked around this issue by including the library as follows:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wfloat-equal"
#pragma clang diagnostic ignored "-Wdeprecated"
#define private public
#include <json.hpp>
#define private private
#pragma clang diagnostic pop

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions