Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json_pointer__pop_back.cpp example does not compile #3600

Closed
2 tasks done
nlohmann opened this issue Jul 23, 2022 · 3 comments · Fixed by #3601
Closed
2 tasks done

json_pointer__pop_back.cpp example does not compile #3600

nlohmann opened this issue Jul 23, 2022 · 3 comments · Fixed by #3601
Assignees
Labels
kind: bug release item: 🐛 bug fix solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@nlohmann
Copy link
Owner

Description

Example https://github.com/nlohmann/json/blob/develop/docs/examples/json_pointer__pop_back.cpp does not compile.

It used to compile. Not sure when this broke.

Reproduction steps

Call

make -C docs

Expected vs. actual results

Expected: code compiles

Actual:

GCC:

examples/json_pointer__back.cpp: In function 'int main()':
examples/json_pointer__back.cpp:13:45: error: no match for 'operator<<' (operand types are 'std::basic_ostream<char>' and 'nlohmann::basic_json<>::json_pointer' {aka 'nlohmann::json_pointer<std::__cxx11::basic_string<char> >'})
   13 |     std::cout << "last reference token of " << ptr1 << " is " << ptr1.back() << '\n'
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^~ ~~~~
      |               |                                |
      |               std::basic_ostream<char>         nlohmann::basic_json<>::json_pointer {aka nlohmann::json_pointer<std::__cxx11::basic_string<char> >}

Clang:

examples/json_pointer__back.cpp:13:45: error: invalid operands to binary expression ('basic_ostream<char, std::char_traits<char>>' and 'json::json_pointer' (aka 'json_pointer<std::string>'))
    std::cout << "last reference token of " << ptr1 << " is " << ptr1.back() << '\n'
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~

Minimal code example

No response

Error messages

No response

Compiler and operating system

Apple clang version 13.1.6 (clang-1316.0.21.2.5) and g++-11 (Homebrew GCC 11.3.0_2) 11.3.0

Library version

develop

Validation

@falbrechtskirchinger
Copy link
Contributor

falbrechtskirchinger commented Jul 23, 2022

Checking.

Works with 1deeb43 (before json_pointer refactor).
Broken starting with 616caea.

@falbrechtskirchinger
Copy link
Contributor

falbrechtskirchinger commented Jul 23, 2022

Suggestion:

  • Add friend std::ostream &operator<<(std::ostream &, const json_pointer &).
    • Guard with JSON_NO_IO.
    • Add documentation.
  • Deprecate operator string_t() (we have to_string() for explicit conversion).
    • Update documentation.

@nlohmann
Copy link
Owner Author

I'm fine with both.

@nlohmann nlohmann self-assigned this Jul 28, 2022
@nlohmann nlohmann added solution: proposed fix a fix for the issue has been proposed and waits for confirmation release item: 🐛 bug fix labels Jul 28, 2022
@nlohmann nlohmann added this to the Release 3.11.0 milestone Jul 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug release item: 🐛 bug fix solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants