Skip to content

[C++23] Error in json::parse with std::ifstream #5047

@Biraru

Description

@Biraru

Description

When attempting to parse a JSON file directly from a std::ifstream using C++23, the compiler fails during template expansion. It specifically complains that _Is_pointer_address_convertible cannot be initialized by a constant expression.

Reproduction steps

  1. Create a valid JSON file named test.json.
  2. Use the provided minimal C++ code to open and parse the file.
  3. Compile using C++23 standards.

Expected vs. actual results

Expected Result:
The code should compile successfully, and the json object should contain the parsed data from the file.

Actual Result:
The compiler throws a constexpr related error during the template deduction phase of nlohmann::json::parse.

Minimal code example

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

int main() {
    std::ifstream file("test.json");
    // Error at parse : Clangd: In template: constexpr variable '_Is_pointer_address_convertible<nlohmann::basic_json<>, nlohmann::basic_json<>>' must be initialized by a constant expression
    auto j = nlohmann::json::parse(file); 
    return 0;
}

Error messages

Clangd: In template: constexpr variable '_Is_pointer_address_convertible<nlohmann::basic_json<>, nlohmann::basic_json<>>' must be initialized by a constant expression

Compiler and operating system

MSVC, Clang (For CLion Clangd), Windows 11 Pro

Library version

3.12.0#1 installed using vcpkg

Validation

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions