-
Notifications
You must be signed in to change notification settings - Fork 86
Use underlying type for enums in is_signed/is_unsigned. #199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Romain-Geissler-1A
wants to merge
1
commit into
boostorg:develop
Choose a base branch
from
Romain-Geissler-1A:fix-is_signed-with-enum-and-clang-21
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Use underlying type for enums in is_signed/is_unsigned. #199
Romain-Geissler-1A
wants to merge
1
commit into
boostorg:develop
from
Romain-Geissler-1A:fix-is_signed-with-enum-and-clang-21
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was referenced Sep 5, 2025
Author
|
Ping |
1 similar comment
Author
|
Ping |
Collaborator
|
The problem you have here, is that |
With clang >= 21, using is_signed/is_unsigned with "small" enums (having an underlying type smaller than an int) results in strong error, after being reported as warnings for years (see boostorg#171). Since boost::is_signed/is_unsigned differs explicitly from the std one, and can return "true" for enums (contrary to the std one), keep this boost behavior and implement a special check for enums. This allows in particular boost::lexical_cast to keep working when converting non-scoped enums from int to strings with clang >= 21, see boostorg/lexical_cast#87).
aca9782 to
a9baab2
Compare
Author
|
@jzmaddock I changed a bit the definition, to now use underlying_type only for enums. |
|
Ping |
1 similar comment
Author
|
Ping |
freebsd-git
pushed a commit
to freebsd/freebsd-ports
that referenced
this pull request
Jan 1, 2026
Recent versions of clang made -Wenum-constexpr-conversion errors into a
hard error, as was announced several versions ago.
Boost type_traits has two instances where it attempts to convert
out-of-range enum values, leading to errors similar to:
In file included from ../src/lib/dhcpsrv/csv_lease_file6.cc:9:
In file included from ../src/lib/dhcpsrv/dhcpsrv_log.h:11:
In file included from ../src/lib/log/macros.h:10:
In file included from ../src/lib/log/logger.h:19:
In file included from ../src/lib/log/log_formatter.h:19:
In file included from /usr/local/include/boost/lexical_cast.hpp:33:
In file included from /usr/local/include/boost/lexical_cast/try_lexical_convert.hpp:31:
In file included from /usr/local/include/boost/lexical_cast/detail/converter_numeric.hpp:31:
In file included from /usr/local/include/boost/type_traits/make_unsigned.hpp:14:
/usr/local/include/boost/type_traits/is_signed.hpp:37:25: error: in-class initializer for static data member is not a constant expression
37 | static const no_cv_t minus_one = (static_cast<no_cv_t>(-1));
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/boost/type_traits/is_signed.hpp:45:60: note: in instantiation of template class 'boost::detail::is_signed_values<isc::dhcp::Lease::Type>' requested here
45 | BOOST_STATIC_CONSTANT(bool, value = (!(::boost::detail::is_signed_values<T>::minus_one > boost::detail::is_signed_values<T>::zero)));
| ^
/usr/local/include/boost/config/detail/suffix.hpp:410:72: note: expanded from macro 'BOOST_STATIC_CONSTANT'
410 | # define BOOST_STATIC_CONSTANT(type, assignment) static const type assignment
| ^
/usr/local/include/boost/type_traits/is_signed.hpp:74:40: note: in instantiation of template class 'boost::detail::is_signed_helper<isc::dhcp::Lease::Type>' requested here
74 | BOOST_STATIC_CONSTANT(bool, value = type::value);
| ^
/usr/local/include/boost/config/detail/suffix.hpp:410:72: note: expanded from macro 'BOOST_STATIC_CONSTANT'
410 | # define BOOST_STATIC_CONSTANT(type, assignment) static const type assignment
| ^
/usr/local/include/boost/type_traits/is_signed.hpp:79:85: note: in instantiation of template class 'boost::detail::is_signed_impl<isc::dhcp::Lease::Type>' requested here
79 | template <class T> struct is_signed : public integral_constant<bool, boost::detail::is_signed_impl<T>::value> {};
| ^
/usr/local/include/boost/lexical_cast/detail/converter_lexical_streams.hpp:315:44: note: in instantiation of template class 'boost::is_signed<isc::dhcp::Lease::Type>' requested here
315 | typename boost::enable_if_c<boost::is_signed<Type>::value && !boost::is_enum<Type>::value, bool>::type
| ^
/usr/local/include/boost/lexical_cast/detail/converter_lexical.hpp:449:67: note: while substituting deduced template arguments into function template 'stream_in' [with Type = isc::dhcp::Lease::Type]
449 | -> decltype(std::declval<optimized_src_stream&>().stream_in(std::declval<lcast::exact<T>>()), optimized_src_stream{});
| ^
/usr/local/include/boost/lexical_cast/detail/converter_lexical.hpp:454:46: note: while substituting explicitly-specified template arguments into function template 'detect_type'
454 | using from_src_stream = decltype(detect_type<Source>(1));
| ^
/usr/local/include/boost/lexical_cast/try_lexical_convert.hpp:67:20: note: in instantiation of template class 'boost::detail::lexical_converter_impl<std::string, isc::dhcp::Lease::Type>' requested here
67 | return caster_type::try_convert(arg, result);
| ^
/usr/local/include/boost/lexical_cast.hpp:42:41: note: in instantiation of function template specialization 'boost::conversion::detail::try_lexical_convert<std::string, isc::dhcp::Lease::Type>' requested here
42 | if (!boost::conversion::detail::try_lexical_convert(arg, result)) {
| ^
../src/lib/util/csv_file.h:243:34: note: in instantiation of function template specialization 'boost::lexical_cast<std::string, isc::dhcp::Lease::Type>' requested here
243 | values_[at] = boost::lexical_cast<std::string>(value);
| ^
../src/lib/dhcpsrv/csv_lease_file6.cc:54:9: note: in instantiation of function template specialization 'isc::util::CSVRow::writeAt<isc::dhcp::Lease::Type>' requested here
54 | row.writeAt(getColumnIndex("lease_type"), lease.type_);
| ^
/usr/local/include/boost/type_traits/is_signed.hpp:37:38: note: integer value -1 is outside the valid range of values [0, 3] for the enumeration type 'Type'
37 | static const no_cv_t minus_one = (static_cast<no_cv_t>(-1));
| ^
This is while compiling net/kea, but other users of boost type traits
may also have the same issue.
There is an upstream bug report at:
boostorg/type_traits#202
and an outstanding pull request at:
boostorg/type_traits#199
Apply the latter as a diff, to work around the problem. Bump
PORTREVISION to make dependents recompile.
PR: 292071
Approved by: fluffy (maintainer)
MFH: 2025Q4
freebsd-git
pushed a commit
to freebsd/freebsd-ports
that referenced
this pull request
Jan 1, 2026
Recent versions of clang made -Wenum-constexpr-conversion errors into a
hard error, as was announced several versions ago.
Boost type_traits has two instances where it attempts to convert
out-of-range enum values, leading to errors similar to:
In file included from ../src/lib/dhcpsrv/csv_lease_file6.cc:9:
In file included from ../src/lib/dhcpsrv/dhcpsrv_log.h:11:
In file included from ../src/lib/log/macros.h:10:
In file included from ../src/lib/log/logger.h:19:
In file included from ../src/lib/log/log_formatter.h:19:
In file included from /usr/local/include/boost/lexical_cast.hpp:33:
In file included from /usr/local/include/boost/lexical_cast/try_lexical_convert.hpp:31:
In file included from /usr/local/include/boost/lexical_cast/detail/converter_numeric.hpp:31:
In file included from /usr/local/include/boost/type_traits/make_unsigned.hpp:14:
/usr/local/include/boost/type_traits/is_signed.hpp:37:25: error: in-class initializer for static data member is not a constant expression
37 | static const no_cv_t minus_one = (static_cast<no_cv_t>(-1));
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/boost/type_traits/is_signed.hpp:45:60: note: in instantiation of template class 'boost::detail::is_signed_values<isc::dhcp::Lease::Type>' requested here
45 | BOOST_STATIC_CONSTANT(bool, value = (!(::boost::detail::is_signed_values<T>::minus_one > boost::detail::is_signed_values<T>::zero)));
| ^
/usr/local/include/boost/config/detail/suffix.hpp:410:72: note: expanded from macro 'BOOST_STATIC_CONSTANT'
410 | # define BOOST_STATIC_CONSTANT(type, assignment) static const type assignment
| ^
/usr/local/include/boost/type_traits/is_signed.hpp:74:40: note: in instantiation of template class 'boost::detail::is_signed_helper<isc::dhcp::Lease::Type>' requested here
74 | BOOST_STATIC_CONSTANT(bool, value = type::value);
| ^
/usr/local/include/boost/config/detail/suffix.hpp:410:72: note: expanded from macro 'BOOST_STATIC_CONSTANT'
410 | # define BOOST_STATIC_CONSTANT(type, assignment) static const type assignment
| ^
/usr/local/include/boost/type_traits/is_signed.hpp:79:85: note: in instantiation of template class 'boost::detail::is_signed_impl<isc::dhcp::Lease::Type>' requested here
79 | template <class T> struct is_signed : public integral_constant<bool, boost::detail::is_signed_impl<T>::value> {};
| ^
/usr/local/include/boost/lexical_cast/detail/converter_lexical_streams.hpp:315:44: note: in instantiation of template class 'boost::is_signed<isc::dhcp::Lease::Type>' requested here
315 | typename boost::enable_if_c<boost::is_signed<Type>::value && !boost::is_enum<Type>::value, bool>::type
| ^
/usr/local/include/boost/lexical_cast/detail/converter_lexical.hpp:449:67: note: while substituting deduced template arguments into function template 'stream_in' [with Type = isc::dhcp::Lease::Type]
449 | -> decltype(std::declval<optimized_src_stream&>().stream_in(std::declval<lcast::exact<T>>()), optimized_src_stream{});
| ^
/usr/local/include/boost/lexical_cast/detail/converter_lexical.hpp:454:46: note: while substituting explicitly-specified template arguments into function template 'detect_type'
454 | using from_src_stream = decltype(detect_type<Source>(1));
| ^
/usr/local/include/boost/lexical_cast/try_lexical_convert.hpp:67:20: note: in instantiation of template class 'boost::detail::lexical_converter_impl<std::string, isc::dhcp::Lease::Type>' requested here
67 | return caster_type::try_convert(arg, result);
| ^
/usr/local/include/boost/lexical_cast.hpp:42:41: note: in instantiation of function template specialization 'boost::conversion::detail::try_lexical_convert<std::string, isc::dhcp::Lease::Type>' requested here
42 | if (!boost::conversion::detail::try_lexical_convert(arg, result)) {
| ^
../src/lib/util/csv_file.h:243:34: note: in instantiation of function template specialization 'boost::lexical_cast<std::string, isc::dhcp::Lease::Type>' requested here
243 | values_[at] = boost::lexical_cast<std::string>(value);
| ^
../src/lib/dhcpsrv/csv_lease_file6.cc:54:9: note: in instantiation of function template specialization 'isc::util::CSVRow::writeAt<isc::dhcp::Lease::Type>' requested here
54 | row.writeAt(getColumnIndex("lease_type"), lease.type_);
| ^
/usr/local/include/boost/type_traits/is_signed.hpp:37:38: note: integer value -1 is outside the valid range of values [0, 3] for the enumeration type 'Type'
37 | static const no_cv_t minus_one = (static_cast<no_cv_t>(-1));
| ^
This is while compiling net/kea, but other users of boost type traits
may also have the same issue.
There is an upstream bug report at:
boostorg/type_traits#202
and an outstanding pull request at:
boostorg/type_traits#199
Apply the latter as a diff, to work around the problem. Bump
PORTREVISION to make dependents recompile.
PR: 292071
Approved by: fluffy (maintainer)
MFH: 2025Q4
(cherry picked from commit ab93476)
fluffykhv
pushed a commit
to fluffykhv/freebsd-ports-boost
that referenced
this pull request
Jan 1, 2026
Recent versions of clang made -Wenum-constexpr-conversion errors into a
hard error, as was announced several versions ago.
Boost type_traits has two instances where it attempts to convert
out-of-range enum values, leading to errors similar to:
In file included from ../src/lib/dhcpsrv/csv_lease_file6.cc:9:
In file included from ../src/lib/dhcpsrv/dhcpsrv_log.h:11:
In file included from ../src/lib/log/macros.h:10:
In file included from ../src/lib/log/logger.h:19:
In file included from ../src/lib/log/log_formatter.h:19:
In file included from /usr/local/include/boost/lexical_cast.hpp:33:
In file included from /usr/local/include/boost/lexical_cast/try_lexical_convert.hpp:31:
In file included from /usr/local/include/boost/lexical_cast/detail/converter_numeric.hpp:31:
In file included from /usr/local/include/boost/type_traits/make_unsigned.hpp:14:
/usr/local/include/boost/type_traits/is_signed.hpp:37:25: error: in-class initializer for static data member is not a constant expression
37 | static const no_cv_t minus_one = (static_cast<no_cv_t>(-1));
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/boost/type_traits/is_signed.hpp:45:60: note: in instantiation of template class 'boost::detail::is_signed_values<isc::dhcp::Lease::Type>' requested here
45 | BOOST_STATIC_CONSTANT(bool, value = (!(::boost::detail::is_signed_values<T>::minus_one > boost::detail::is_signed_values<T>::zero)));
| ^
/usr/local/include/boost/config/detail/suffix.hpp:410:72: note: expanded from macro 'BOOST_STATIC_CONSTANT'
410 | # define BOOST_STATIC_CONSTANT(type, assignment) static const type assignment
| ^
/usr/local/include/boost/type_traits/is_signed.hpp:74:40: note: in instantiation of template class 'boost::detail::is_signed_helper<isc::dhcp::Lease::Type>' requested here
74 | BOOST_STATIC_CONSTANT(bool, value = type::value);
| ^
/usr/local/include/boost/config/detail/suffix.hpp:410:72: note: expanded from macro 'BOOST_STATIC_CONSTANT'
410 | # define BOOST_STATIC_CONSTANT(type, assignment) static const type assignment
| ^
/usr/local/include/boost/type_traits/is_signed.hpp:79:85: note: in instantiation of template class 'boost::detail::is_signed_impl<isc::dhcp::Lease::Type>' requested here
79 | template <class T> struct is_signed : public integral_constant<bool, boost::detail::is_signed_impl<T>::value> {};
| ^
/usr/local/include/boost/lexical_cast/detail/converter_lexical_streams.hpp:315:44: note: in instantiation of template class 'boost::is_signed<isc::dhcp::Lease::Type>' requested here
315 | typename boost::enable_if_c<boost::is_signed<Type>::value && !boost::is_enum<Type>::value, bool>::type
| ^
/usr/local/include/boost/lexical_cast/detail/converter_lexical.hpp:449:67: note: while substituting deduced template arguments into function template 'stream_in' [with Type = isc::dhcp::Lease::Type]
449 | -> decltype(std::declval<optimized_src_stream&>().stream_in(std::declval<lcast::exact<T>>()), optimized_src_stream{});
| ^
/usr/local/include/boost/lexical_cast/detail/converter_lexical.hpp:454:46: note: while substituting explicitly-specified template arguments into function template 'detect_type'
454 | using from_src_stream = decltype(detect_type<Source>(1));
| ^
/usr/local/include/boost/lexical_cast/try_lexical_convert.hpp:67:20: note: in instantiation of template class 'boost::detail::lexical_converter_impl<std::string, isc::dhcp::Lease::Type>' requested here
67 | return caster_type::try_convert(arg, result);
| ^
/usr/local/include/boost/lexical_cast.hpp:42:41: note: in instantiation of function template specialization 'boost::conversion::detail::try_lexical_convert<std::string, isc::dhcp::Lease::Type>' requested here
42 | if (!boost::conversion::detail::try_lexical_convert(arg, result)) {
| ^
../src/lib/util/csv_file.h:243:34: note: in instantiation of function template specialization 'boost::lexical_cast<std::string, isc::dhcp::Lease::Type>' requested here
243 | values_[at] = boost::lexical_cast<std::string>(value);
| ^
../src/lib/dhcpsrv/csv_lease_file6.cc:54:9: note: in instantiation of function template specialization 'isc::util::CSVRow::writeAt<isc::dhcp::Lease::Type>' requested here
54 | row.writeAt(getColumnIndex("lease_type"), lease.type_);
| ^
/usr/local/include/boost/type_traits/is_signed.hpp:37:38: note: integer value -1 is outside the valid range of values [0, 3] for the enumeration type 'Type'
37 | static const no_cv_t minus_one = (static_cast<no_cv_t>(-1));
| ^
This is while compiling net/kea, but other users of boost type traits
may also have the same issue.
There is an upstream bug report at:
boostorg/type_traits#202
and an outstanding pull request at:
boostorg/type_traits#199
Apply the latter as a diff, to work around the problem. Bump
PORTREVISION to make dependents recompile.
PR: 292071
Approved by: fluffy (maintainer)
MFH: 2025Q4
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With clang >= 21, using is_signed/is_unsigned with "small" enums (having an underlying type smaller than an int) results in strong error, after being reported as warnings for years (see #171).
Since boost::is_signed/is_unsigned differs explicitly from the std one, and can return "true" for enums (contrary to the std one), keep this boost behavior and implement a special check for enums.
This allows in particular boost::lexical_cast to keep working when converting non-scoped enums from int to strings with clang >= 21, see boostorg/lexical_cast#87).