-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Open
Labels
Description
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
- Create a valid JSON file named test.json.
- Use the provided minimal C++ code to open and parse the file.
- 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 expressionCompiler and operating system
MSVC, Clang (For CLion Clangd), Windows 11 Pro
Library version
3.12.0#1 installed using vcpkg
Validation
- The bug also occurs if the latest version from the
developbranch is used. - I can successfully compile and run the unit tests.