ned14 / outcome

Provides very lightweight outcome<T> and result<T> (non-Boost edition)
https://ned14.github.io/outcome
Other
676 stars 62 forks source link

Code bug in documentation : make_error_code(ConversionErrc e) #241

Closed vjohansen closed 3 years ago

vjohansen commented 3 years ago

I am trying to follow the documentation and am copy/pasting code to get a minimal example with

outcome::result<int> convert(const std::string& str) noexcept

working.

This causes a crash when retrieving some_result.error().message()

The issue is on the page https://ned14.github.io/outcome/motivation/plug_error_code/ return {static_cast<int>(e), ConversionErrc_category()};

If i follow the godbolt link the code is

std::error_code make_error_code(ConversionErrc e)
{
  return std::error_code{static_cast<int>(e), globalConversionErrorCategory};
}

Using a global object made my code example work too

ned14 commented 3 years ago

From that page you mentioned, I copy and pasted the entire snippet into wandbox, and it executes without crash just fine:

https://wandbox.org/permlink/D8Ly4wIKobBAXM8v

I don't see a godbolt link on that page. Can you clarify?

vjohansen commented 3 years ago

Probably here https://ned14.github.io/outcome/tutorial/essential/before/

Here is the first tutorial topic’s source code loaded into Godbolt: https://godbolt.org/z/p-NAho

At the bottom there a links to both godbolt and wandbox

vjohansen commented 3 years ago

Please close this issue.

I looked at my code again and the web page. It turns out I copied only the class ConversionErrc_category which caused a temporary error_category to be created in make_error_code.

This is because I did not copy the

THIS_MODULE_API_DECL const detail::ConversionErrc_category& ConversionErrc_category()
{
  static detail::ConversionErrc_category c;
  return c;
}

Which is a function with the same name as the class