enum ssl_errors
{
// Error numbers are those produced by openssl.
};
inline boost::system::error_code make_error_code(ssl_errors e);
I get that errors belonging to this category are really OpenSSL error codes.
Now, I wrote something like this in my unit tests:
error_code ec {static_cast<asio::error::ssl_errors>(1623)}; // 1623 simulates an OpenSSL error
While this builds, this is flagged as undefined behavior by ubsan, as 1623 is not a valid enumerator. This wouldn't happen if ssl_errors would have been an enum class, instead.
Since ssl_errors doesn't have any enumerator, it looks like any such casts is a recipe for UB. I think the right thing to do would be converting the type to an enum class.
Another viable solution is to explicitly state the underlying type of the enumeration, as in enum ssl_errors : unsigned {}
(or whatever int type openssl uses)
The enumeration type is defined as:
I get that errors belonging to this category are really OpenSSL error codes.
Now, I wrote something like this in my unit tests:
While this builds, this is flagged as undefined behavior by ubsan, as 1623 is not a valid enumerator. This wouldn't happen if
ssl_errors
would have been anenum class
, instead.Since
ssl_errors
doesn't have any enumerator, it looks like any such casts is a recipe for UB. I think the right thing to do would be converting the type to anenum class
.