Skip to content

utils::expected implementation does not take into account valueless_by_exception #1205

Description

@ddvamp

bool expected<S, E>::has_value() const noexcept {
return std::holds_alternative<S>(data_);

E& expected<S, E>::error() USERVER_IMPL_LIFETIME_BOUND {
auto* result = std::get_if<unexpected<E>>(&data_);
if (result == nullptr) {
throw bad_expected_access("Trying to get undefined error value from utils::expected");

Текущая реализация has_value() фактически проверяет, что объект находится в одном конкретном состоянии из трёх. Можно построить исполнение, в котором вызов error() выбросит исключение при has_value() == false.

Необходимо либо добавить метод has_error(), либо иным образом добавить возможность различать все состояния.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions