boostorg / boostorg/type_traits

-Wconversion warning with is_signed for enums

Open
#171 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
66
Forks
87
PR merge metrics
No merged PRs in 30d

Description

```
..\../boost/type_traits/is_signed.hpp: In instantiation of 'const no_cv_t boost::detail::is_signed_values::minus_one':
..\../boost/type_traits/is_signed.hpp:45:4: required from 'const bool boost::detail::is_signed_helper::value'
..\../boost/type_traits/is_signed.hpp:74:4: required from 'const bool boost::detail::is_signed_impl::value'
..\../boost/type_traits/is_signed.hpp:79:27: required from 'struct boost::is_signed'
..\../boost/container_hash/hash.hpp:178:135: required from 'typename boost::enable_if_::value, long unsigned int>::type boost::hash_value(T) [with T = test::enum1; typename boost::enable_if_::value, long unsigned int>::type = long unsigned int]'
..\../boost/container_hash/hash.hpp:672:30: required from 'std::size_t boost::hash::operator()(const T&) const [with T = test::enum1; std::size_t = long unsigned int]'
test\hash_enum_test.cpp:39:5: required from here
..\../boost/type_traits/is_signed.hpp:37:59: error: the result of the conversion is unspecified because '-1' is outside the range of type 'boost::detail::is_signed_values::no_cv_t' {aka 'test::enum1'} [-Werror=conversion]
37 | static const no_cv_t minus_one = (static_cast(-1));
| ^~
```
The warning is correct, because -1 is not necessarily a valid value for enumeration types, so this is not required to work.

I'm not sure how we can fix this. I tried a few things, but nothing worked.

is_signed is not particularly useful for enums, and in fact `std::is_signed` doesn't support them, so this may seem of low priority; but what I'm actually trying to implement is `underlying_type`, and its C++03 implementation is
```
conditional, make_signed, make_unsigned>::type::type
```
Maybe what we actually need is just `boost::underlying_type`. (Or `boost::underlying_type_`, because Core has already - and incorrectly - claimed `boost::underlying_type` in `boost/core/scoped_enum.hpp`.)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.