Skip to content

assigning nullptr to std::string #2118

@ghost

Description

Question

According to the document for "JSON for Modern C++", when the variable type is "std::nullptr_t", it returns "null".

It's a silly question, but if assigning "nullptr" to "std::string" like "Example", which one is intended as the specification?

(1) it causes the segmentation fault by undefined behavior of std::string
(2) it returns "null" as same as "std::nullptr_t"

It seems that (1) is the specification: it's undesired to assign "nullptr" to "std::string".
Is it correct about my understanding?

[Example]

#include <iostream>
#include <nlohmann/json.hpp>

int main() {
    nlohmann::json j;
    std::string value = nullptr;
    j[ "value" ] = value;
    std::cout << j << std::endl;

    ...
}

Version

  • JSON for Modern C++ 3.7.3
  • Linux gcc 8.3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions