Skip to content

Task completion signatures ignore error_types from custom env #2222

Description

@wokron

Hi,

When stdexec::task is given a custom environment with using error_types, the task's completion signatures still report set_error_t(std::exception_ptr) instead of the declared error type (e.g. set_error_t(std::error_code)).

Repro

// task_error_types_repro.cpp
#include <stdexec/execution.hpp>
#include <system_error>
#include <variant>

struct my_env
{
  using error_types = stdexec::completion_signatures<stdexec::set_error_t(std::error_code)>;
};

auto func() noexcept -> stdexec::task<int, my_env>
{
  co_yield stdexec::with_error{std::make_error_code(std::errc::invalid_argument)};
  co_return 1;
}

int main()
{
  auto s = func() | stdexec::upon_error([](auto err) noexcept { return err; })
         | stdexec::into_variant();
  auto [r] = stdexec::sync_wait(std::move(s)).value();
  bool fail = std::holds_alternative<std::tuple<std::error_code>>(r);
  return fail ? 1 : 0;
}

Build

clang++ task_error_types_repro.cpp -std=c++23 -I ./include/

This fails to compile with:

...
/usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/variant:1143:21: error: static assertion failed due to
      requirement '__detail::__variant::__exactly_once<std::tuple<std::error_code>, std::tuple<int>,
      std::tuple<std::__exception_ptr::exception_ptr>>': T must occur exactly once in alternatives
 1143 |       static_assert(__detail::__variant::__exactly_once<_Tp, _Types...>,
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
task_error_types_repro.cpp:21:20: note: in instantiation of function template specialization
      'std::holds_alternative<std::tuple<std::error_code>, std::tuple<int>,
      std::tuple<std::__exception_ptr::exception_ptr>>' requested here
   21 |   bool fail = std::holds_alternative<std::tuple<std::error_code>>(r);
      |                    ^
...

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