bloomberg / bloomberg/bde

error_code hash bug in tests

Open
#277 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
1.8k
Forks
342
PR merge metrics
No merged PRs in 30d

Description

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:

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

It only hashes the value, not the category.

Contributor guide

Open the contributing guide

Research direction

Start at groups/bsl/bslstl/bslstl_error.t.cpp near line 1359 and inspect the test's assumptions about std::hash. Confirm the behavior on the relevant standard library implementation, then adjust the test expectation so it does not require different categories to produce different hashes and run the test.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
testing
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.