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

Unit conversion test error: conversion from 'nlohmann::json' to non-scalar type 'std::string_view' requested #1634

Closed
taylorhoward92 opened this issue Jun 12, 2019 · 4 comments
Assignees
Labels
kind: bug release item: 🔨 further change solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Milestone

Comments

@taylorhoward92
Copy link

  • What is the issue you have?

When building v3.6.0 or v3.6.1 I get the following error from a unit-conversion test. The error is not present when building v3.5.0.

[ 46%] Building CXX object _deps/nlohmann_json-build/test/CMakeFiles/test-conversions.dir/src/unit-conversions.cpp.o
/tmp/tmp.KVk3RBpMpy/cmake-build-debug/_deps/nlohmann_json-src/test/src/unit-conversions.cpp: In function 'void ____C_A_T_C_H____T_E_S_T____0()':
/tmp/tmp.KVk3RBpMpy/cmake-build-debug/_deps/nlohmann_json-src/test/src/unit-conversions.cpp:483:34: error: conversion from 'nlohmann::json' {aka 'nlohmann::basic_json<>'} to non-scalar type 'std::string_view' {aka 'std::basic_string_view<char>'} requested
             std::string_view s = j;
  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?

Include nlohmann_json in a Cmake project using FetchContent:

FetchContent_Declare(
        nlohmann_json
        GIT_REPOSITORY https://github.com/nlohmann/json.git
        GIT_TAG v3.6.1
)

FetchContent_MakeAvailable(nlohmann_json)

include_directories(${nlohmann_json_SOURCE_DIR}/single_include)
  • What is the expected behavior?

Tests pass without errors.

  • And what is the actual behavior instead?

The above error occurs.

Ubuntu 18.04 with GCC 8.3.0.
Using C++17.

  • Did you use a released version of the library or the version from the develop branch?

The test error occurs with v3.6.0 and v3.6.1. It does not occur with v3.5.0. I haven't tested any other versions.

See above.

@nickaein
Copy link
Contributor

Thanks for reporting the issue. I have reproduced here (for 3.6.1 on gcc 8.3): https://godbolt.org/z/pl6XlF

This seems to be an oversight in fixing this unit-test on 3.6.1 which uses implicit conversion and is discouraged. It seems to be fixed on develop branch by replacing it with an explicit conversion.

Nevertheless, you should be able to use the library without building unit tests, if you want. Even more, I you can skip downloading the whole repository by replace the git URL with the following direct HTTP link to single header release 3.6.1:

https://github.com/nlohmann/json/releases/download/v3.6.1/json.hpp

The single library header is usually enough for using this library as a third-party in other applications.

@taylorhoward92
Copy link
Author

Thanks for taking a look. It is fixed on the line you pointed out but not on this line.

@nlohmann
Copy link
Owner

Would you like to make a pull request with the fix?

@nlohmann
Copy link
Owner

Closed by merging #1639.

@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Jun 22, 2019
@nlohmann nlohmann self-assigned this Jun 22, 2019
@nlohmann nlohmann added this to the Release 3.6.2 milestone Jun 22, 2019
@nlohmann nlohmann modified the milestones: Release 3.6.2, Release 3.7.0 Jul 9, 2019
@nlohmann nlohmann added this to the Release 3.7.0 milestone Jul 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug release item: 🔨 further change solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

3 participants