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

boost::system::errc enum is accepted as a value into result<int> #74

Closed
ytimenkov opened this issue Dec 9, 2021 · 1 comment
Closed

Comments

@ytimenkov
Copy link

ytimenkov commented Dec 9, 2021

Boost version 1.78.0

The shortest reproduction is:

#include <boost/system/result.hpp>

static_assert(boost::system::result<int>{boost::system::errc::invalid_argument}.has_error());
<source>:511:90: error: static assertion failed
  511 | static_assert(boost::system::result<int>{boost::system::errc::invalid_argument}.has_error());
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
Compiler returned: 1

I use similar pattern extensively in the code with outcome and std::error_code , something like:

result<int> do_something(int count)
{
    if (count < 0)
        return std::errc::invalid_argument;
}

The fact that errc enum converts to value implicitly is really surprising (won't be surprised if it just didn't convert).

@pdimov
Copy link
Member

pdimov commented Dec 10, 2021

A better fix for this would be making errc_t a scoped enum (#75), but for now, I'll disable the conversions to int on the result side.

@pdimov pdimov closed this as completed in 01ce081 Dec 11, 2021
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

2 participants