Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some compilation problems #1

Open
kobtsev opened this issue Mar 17, 2023 · 0 comments
Open

Some compilation problems #1

kobtsev opened this issue Mar 17, 2023 · 0 comments

Comments

@kobtsev
Copy link

kobtsev commented Mar 17, 2023

std::convertible_to evaluates to false for same types of rd::expected<void, E>

Checked on:
msvc (cl 19.35.32215) /std:c++20
clang (15.0.0) -std=c++20

Some code to explain below:
godbolt clang 15 - issue 1

#include <concepts>
#include <system_error>
#include <rd/expected.hpp>

template <typename T>
using result = rd::expected<T, std::error_code>;

static_assert(std::convertible_to<result<std::size_t>, result<int>>); // successfully, ok
static_assert(std::convertible_to<result<void>, result<void>>); // failure, why? 

Second assertion failed, Why can't identical rd::expected types be converted to each other? Is there a semantic reason for this behavior?

It may be related to another issue:
godbolt clang 15 - issue 2

#include <system_error>
#include <concepts>
#include <span>
#include <variant>
#include <rd/expected.hpp>

template <typename T>
using result = rd::expected<T, std::error_code>;

template <typename T>
using raw_result = std::variant<T, rd::unexpected<std::error_code>>;

struct data_header { 
    std::size_t data_length; 
    static raw_result<data_header> from_buffer(std::span<std::byte> buffer) noexcept; // compile
};

struct tpkt_header { 
    std::size_t length; 
    static result<tpkt_header> from_buffer(std::span<std::byte> buffer) noexcept; // won't compile
};
@kobtsev kobtsev changed the title std::convertible_to evaluates to false for same types of rd::expected Some compilation problems Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant