bde icon indicating copy to clipboard operation
bde copied to clipboard

error_code hash bug in tests

Open seanbaxter opened this issue 3 years ago • 0 comments

https://github.com/bloomberg/bde/blob/master/groups/bsl/bslstl/bslstl_error.t.cpp#L1359

There's no guarantee that the std::hash of an std::error_code differ if the error code categories are different. Indeed, on libc++, this is the case:

template <>
struct _LIBCPP_TEMPLATE_VIS hash<error_code>
    : public unary_function<error_code, size_t>
{
    _LIBCPP_INLINE_VISIBILITY
    size_t operator()(const error_code& __ec) const _NOEXCEPT
    {
        return static_cast<size_t>(__ec.value());
    }
};

It only hashes the value, not the category.

seanbaxter avatar Feb 01 '22 22:02 seanbaxter