[libc-commits] [libc] 299baac - [libc] Add support for enum in EXPECT_EQ

Guillaume Chatelet via libc-commits libc-commits at lists.llvm.org
Wed Jun 1 01:42:26 PDT 2022


Author: Guillaume Chatelet
Date: 2022-06-01T08:42:18Z
New Revision: 299baac64da32ed995098c43f99091dfd2694699

URL: https://github.com/llvm/llvm-project/commit/299baac64da32ed995098c43f99091dfd2694699
DIFF: https://github.com/llvm/llvm-project/commit/299baac64da32ed995098c43f99091dfd2694699.diff

LOG: [libc] Add support for enum in EXPECT_EQ

Added: 
    

Modified: 
    libc/src/__support/CPP/TypeTraits.h
    libc/utils/UnitTest/LibcTest.h

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/CPP/TypeTraits.h b/libc/src/__support/CPP/TypeTraits.h
index f37447fdfb39c..e498b549e93f4 100644
--- a/libc/src/__support/CPP/TypeTraits.h
+++ b/libc/src/__support/CPP/TypeTraits.h
@@ -15,7 +15,9 @@ namespace __llvm_libc {
 namespace cpp {
 
 template <bool B, typename T> struct EnableIf;
-template <typename T> struct EnableIf<true, T> { typedef T Type; };
+template <typename T> struct EnableIf<true, T> {
+  typedef T Type;
+};
 
 template <bool B, typename T>
 using EnableIfType = typename EnableIf<B, T>::Type;
@@ -28,7 +30,9 @@ struct FalseValue {
   static constexpr bool Value = false;
 };
 
-template <typename T> struct TypeIdentity { typedef T Type; };
+template <typename T> struct TypeIdentity {
+  typedef T Type;
+};
 
 template <typename T1, typename T2> struct IsSame : public FalseValue {};
 template <typename T> struct IsSame<T, T> : public TrueValue {};
@@ -59,6 +63,10 @@ template <typename Type> struct IsIntegral {
       ;
 };
 
+template <typename Type> struct IsEnum {
+  static constexpr bool Value = __is_enum(Type);
+};
+
 template <typename T> struct IsPointerTypeNoCV : public FalseValue {};
 template <typename T> struct IsPointerTypeNoCV<T *> : public TrueValue {};
 template <typename T> struct IsPointerType {

diff  --git a/libc/utils/UnitTest/LibcTest.h b/libc/utils/UnitTest/LibcTest.h
index e9a18cf84094e..c5bb4296ddc94 100644
--- a/libc/utils/UnitTest/LibcTest.h
+++ b/libc/utils/UnitTest/LibcTest.h
@@ -89,6 +89,14 @@ class Test {
     return internal::test(Ctx, Cond, LHS, RHS, LHSStr, RHSStr, File, Line);
   }
 
+  template <typename ValType,
+            cpp::EnableIfType<cpp::IsEnum<ValType>::Value, int> = 0>
+  bool test(TestCondition Cond, ValType LHS, ValType RHS, const char *LHSStr,
+            const char *RHSStr, const char *File, unsigned long Line) {
+    return internal::test(Ctx, Cond, (long long)LHS, (long long)RHS, LHSStr,
+                          RHSStr, File, Line);
+  }
+
   template <
       typename ValType,
       cpp::EnableIfType<cpp::IsPointerType<ValType>::Value, ValType> = nullptr>


        


More information about the libc-commits mailing list