[libcxx-commits] [PATCH] D97283: [libcxx][type_traits] is_unsigned is false for enum types

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Mar 5 06:37:44 PST 2021

ldionne added a comment.

In D97283#2605620 <https://reviews.llvm.org/D97283#2605620>, @Mordante wrote:

> It's a clang bug: clang/docs/LanguageExtensions.rst:1024
>   * ``__is_unsigned`` (C++, Embarcadero)
>     Note that this currently returns true for enumeration types if the underlying
>     type is unsigned, in violation of the requirements for ``std::is_unsigned``.
>     This behavior is likely to change in a future version of Clang.
> @zoecarver fixed the signed part in D67897 <https://reviews.llvm.org/D67897>
> I want to look at the Clang site unless somebody beats me to it.

I suggest we add the tests present in this patch, fix Clang, and then make libc++ conditionally use just `__is_unsigned` or a combination of `__is_unsigned && !__is_enum` based on the version of Clang. We'll be able to remove that workaround in ~6 months due to the compiler policy, which makes it more acceptable. So:

  template <class _Tp>
  struct _LIBCPP_TEMPLATE_VIS is_unsigned
      : _BoolConstant<
  #if _LIBCPP_CLANG_VER < whateverversion // Clang prior to <whateverversion> has a bug and treats enumerations as unsigned
      __is_unsigned(_Tp) && !__is_enum(_Tp)
  > {};
  template <class _Tp>
  _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_unsigned_v = is_unsigned<_Tp>::value;

  rG LLVM Github Monorepo



More information about the libcxx-commits mailing list