Skip to content

.value() with optional default value fails to compile #3859

@audaki

Description

@audaki

Description

We upgraded from 3.10.5 to 3.11.2

Since the Upgrade we can't compile value() with optional fallback value anymore

Reproduction steps

Try to compile value with std::optional<std::string>{} as fallback. Is this still possible at all, was I using a non-supported edge-case before?

Expected vs. actual results

Compiles vs not

Minimal code example

Beforehand we said:

std::optional<std::string> customer_id;
customer_id = json.value("customer_id", std::optional<std::string>{});

This no longer compiles. Even without the assignment and I tried different versions, all fail to compile:

json.value("customer_id", std::optional<std::string>{});
json.value<std::optional<std::string>>("customer_id", std::optional<std::string>{});


### Error messages

_No response_

### Compiler and operating system

Ubuntu 22.04, Clang 14

### Library version

3.11.2

### Validation

- (haven't tested this) [ ] The bug also occurs if the latest version from the [`develop`](https://github.com/nlohmann/json/tree/develop) branch is used.
- [X] I can successfully [compile and run the unit tests](https://github.com/nlohmann/json#execute-unit-tests). **All passed**

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions