[libc-commits] [libc] [libc] Added support for fixed-points in ``is_signed`` and ``is_unsigned``. (PR #133371)

Abhinav Kumar via libc-commits libc-commits at lists.llvm.org
Fri Mar 28 12:18:44 PDT 2025


================
@@ -8,20 +8,98 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_SIGNED_H
 #define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_SIGNED_H
 
+#include "include/llvm-libc-macros/stdfix-macros.h"
 #include "src/__support/CPP/type_traits/bool_constant.h"
 #include "src/__support/CPP/type_traits/is_arithmetic.h"
+#include "src/__support/CPP/type_traits/is_fixed_point.h"
 #include "src/__support/macros/attributes.h"
 #include "src/__support/macros/config.h"
 
 namespace LIBC_NAMESPACE_DECL {
 namespace cpp {
 
-// is_signed
+// Primary template: handles arithmetic and signed fixed-point types
 template <typename T>
 struct is_signed : bool_constant<(is_arithmetic_v<T> && (T(-1) < T(0)))> {
   LIBC_INLINE constexpr operator bool() const { return is_signed::value; }
   LIBC_INLINE constexpr bool operator()() const { return is_signed::value; }
 };
----------------
kr-2003 wrote:

really? i think i am missing out on something, because this is what i get when i try this on my machine:
```bash
/Users/abhinavkumar/Desktop/Coding/CERN_HSF_COMPILER_RESEARCH/llvm-project/libc/src/__support/CPP/type_traits/is_signed.h:23:34: error: non-type template argument is not a constant expression
   23 | struct is_signed : bool_constant<(is_fixed_point_v<T> && T(-0.5) < T(0)) ||
      |                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   24 |                                  (is_arithmetic_v<T> && (T(-1) < T(0)))> {
      |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/abhinavkumar/Desktop/Coding/CERN_HSF_COMPILER_RESEARCH/llvm-project/libc/src/__support/CPP/type_traits/is_signed.h:105:46: note: in instantiation of template class '__llvm_libc_21_0_0_git::cpp::is_signed<unsigned _Fract>' requested here
  105 | LIBC_INLINE_VAR constexpr bool is_signed_v = is_signed<T>::value;
      |                                              ^
/Users/abhinavkumar/Desktop/Coding/CERN_HSF_COMPILER_RESEARCH/llvm-project/libc/test/src/__support/CPP/type_traits_test.cpp:427:17: note: in instantiation of variable template specialization '__llvm_libc_21_0_0_git::cpp::is_signed_v<unsigned _Fract>' requested here
  427 |   EXPECT_FALSE((is_signed_v<unsigned fract>));
/Users/abhinavkumar/Desktop/Coding/CERN_HSF_COMPILER_RESEARCH/llvm-project/libc/src/__support/CPP/type_traits/is_signed.h:23:60: note: value 0.0 is outside the range of representable values of type 'unsigned _Fract'
   23 | struct is_signed : bool_constant<(is_fixed_point_v<T> && T(-0.5) < T(0)) ||
  ```

https://github.com/llvm/llvm-project/pull/133371


More information about the libc-commits mailing list