You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
main.cpp code found in "Minimal code example" field.
The _json_pointer literal is the only line that compiles correctly.
note: Clang compiler (clang++ v14.0.0) basically reports the same errors.
Reproduction steps
g++ main.cpp --std=c++11
Expected vs. actual results
JSON Pointer creation¶
JSON Pointers can be created from a string: json::json_pointer p = "/nested/one";
Minimal code example
#include <string>#include "json.hpp"
using json = nlohmann::json;
int main()
{
std::string ptrStr = "/nested";
ptrStr += "/one";
json::json_pointer ptr1 = "/nested/one";
auto ptr2 = "/nested/one"_json_pointer;
json::json_pointer ptr3 = ptrStr;
}
Error messages
GNU:
main.cpp: In function‘intmain()’:
main.cpp:11:31: error: conversion from ‘const char [12]’ to non-scalar type ‘nlohmann::json_abi_v3_11_3::basic_json<>::json_pointer’ {aka ‘nlohmann::json_abi_v3_11_3::json_pointer<std::__cxx11::basic_string<char>>’} requested
11 | json::json_pointer ptr1 = "/nested/one";| ^~~~~~~~~~~~~
main.cpp:13:31: error: conversion from ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} to non-scalar type ‘nlohmann::json_abi_v3_11_3::basic_json<>::json_pointer’ {aka ‘nlohmann::json_abi_v3_11_3::json_pointer<std::__cxx11::basic_string<char>>’} requested
13 | json::json_pointer ptr3 = ptrStr;| ^~~~~~
Clang:
main.cpp:11:24: error: no viable conversion from 'const char[12]' to 'json::json_pointer' (aka 'json_pointer<std::basic_string<char>>')
json::json_pointer ptr1 = "/nested/one";
^ ~~~~~~~~~~~~~
./json.hpp:13841:7: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'const char[12]' to 'const nlohmann::json_pointer<std::basic_string<char>> &'for 1st argument
class json_pointer
^
./json.hpp:13841:7: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'const char[12]' to 'nlohmann::json_pointer<std::basic_string<char>> &&'for 1st argument
./json.hpp:13868:14: note: explicit constructor is not a candidate
explicit json_pointer(const string_t& s = "")
^
main.cpp:13:24: error: no viable conversion from 'std::string' (aka 'basic_string<char>') to 'json::json_pointer' (aka 'json_pointer<std::basic_string<char>>')
json::json_pointer ptr3 = ptrStr;
^ ~~~~~~
./json.hpp:13841:7: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'std::string' (aka 'basic_string<char>') to 'const nlohmann::json_pointer<std::basic_string<char>> &'for 1st argument
class json_pointer
^
./json.hpp:13841:7: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'std::string' (aka 'basic_string<char>') to 'nlohmann::json_pointer<std::basic_string<char>> &&'for 1st argument
./json.hpp:13868:14: note: explicit constructor is not a candidate
explicit json_pointer(const string_t& s = "")
^
2 errors generated.
Compiler and operating system
Ubuntu 22.04
Library version
3.11.1 and 3.11.3
Validation
The bug also occurs if the latest version from the develop branch is used.
The compilation errors occur because the constructor of json::json_pointer is marked as explicit.
Removing the explicit keyword allows the code to compile and pass the tests, but i think it might violate the design intentions.
So, I think the better approach is to adjust the example code to use direct initialization.
Description
Gnu C++ does not compile the code example below. GCC 11.4.0, with -std=c++11 option
Example taken from https://json.nlohmann.me/features/json_pointer/#introduction
json::json_pointer p = "/nested/one";
main.cpp code found in "Minimal code example" field.
The _json_pointer literal is the only line that compiles correctly.
note: Clang compiler (clang++ v14.0.0) basically reports the same errors.
Reproduction steps
g++ main.cpp --std=c++11
Expected vs. actual results
JSON Pointer creation¶
JSON Pointers can be created from a string:
json::json_pointer p = "/nested/one";
Minimal code example
Error messages
Compiler and operating system
Ubuntu 22.04
Library version
3.11.1 and 3.11.3
Validation
develop
branch is used.The text was updated successfully, but these errors were encountered: