Revert "[sanitizer] Add a few of type_traits tools"

Does not work with GCC

This reverts commit a82ee2be9c.
This commit is contained in:
Vitaly Buka 2021-11-17 15:45:45 -08:00
parent 1f7827e6aa
commit 22e66a97cb
2 changed files with 1 additions and 101 deletions

View File

@ -13,8 +13,6 @@
#ifndef SANITIZER_TYPE_TRAITS_H
#define SANITIZER_TYPE_TRAITS_H
#include "sanitizer_common/sanitizer_internal_defs.h"
namespace __sanitizer {
struct true_type {
@ -59,53 +57,6 @@ struct conditional<false, T, F> {
using type = F;
};
template <class T>
struct remove_reference {
using type = T;
};
template <class T>
struct remove_reference<T&> {
using type = T;
};
template <class T>
struct remove_reference<T&&> {
using type = T;
};
template <class T>
WARN_UNUSED_RESULT inline typename remove_reference<T>::type&& move(T&& t) {
return static_cast<typename remove_reference<T>::type&&>(t);
}
template <class T>
WARN_UNUSED_RESULT inline constexpr T&& forward(
typename remove_reference<T>::type& t) {
return static_cast<T&&>(t);
}
template <class T>
WARN_UNUSED_RESULT inline constexpr T&& forward(
typename remove_reference<T>::type&& t) {
return static_cast<T&&>(t);
}
template <class T, T v>
struct integral_constant {
static constexpr const T value = v;
typedef T value_type;
typedef integral_constant type;
constexpr operator value_type() const { return value; }
constexpr value_type operator()() const { return value; }
};
template <class T>
struct is_trivially_destructible
: public integral_constant<bool, __is_trivially_destructible(T)> {};
template <class T>
struct is_trivially_copyable
: public integral_constant<bool, __is_trivially_copyable(T)> {};
} // namespace __sanitizer
#endif

View File

@ -10,13 +10,10 @@
//
//===----------------------------------------------------------------------===//
#include "sanitizer_common/sanitizer_type_traits.h"
#include <vector>
#include "gtest/gtest.h"
#include "sanitizer_common/sanitizer_internal_defs.h"
namespace __sanitizer {
using namespace __sanitizer;
TEST(SanitizerCommon, IsSame) {
ASSERT_TRUE((is_same<unsigned, unsigned>::value));
@ -33,51 +30,3 @@ TEST(SanitizerCommon, Conditional) {
ASSERT_TRUE((is_same<int, conditional<true, int, double>::type>::value));
ASSERT_TRUE((is_same<double, conditional<false, int, double>::type>::value));
}
TEST(SanitizerCommon, RemoveReference) {
ASSERT_TRUE((is_same<int, remove_reference<int>::type>::value));
ASSERT_TRUE((is_same<const int, remove_reference<const int>::type>::value));
ASSERT_TRUE((is_same<int, remove_reference<int&>::type>::value));
ASSERT_TRUE((is_same<const int, remove_reference<const int&>::type>::value));
ASSERT_TRUE((is_same<int, remove_reference<int&&>::type>::value));
}
TEST(SanitizerCommon, Move) {
std::vector<int> v = {1, 2, 3};
auto v2 = __sanitizer::move(v);
EXPECT_EQ(3u, v2.size());
EXPECT_TRUE(v.empty());
}
TEST(SanitizerCommon, Forward) {
std::vector<int> v = {1, 2, 3};
auto v2 = __sanitizer::forward<std::vector<int>>(v);
EXPECT_EQ(3u, v2.size());
EXPECT_TRUE(v.empty());
}
TEST(SanitizerCommon, ForwardConst) {
const std::vector<int> v = {1, 2, 3};
auto v2 = __sanitizer::forward<const std::vector<int>&>(v);
EXPECT_EQ(3u, v2.size());
EXPECT_EQ(3u, v.size());
}
struct TestStruct {
int a;
float b;
};
TEST(SanitizerCommon, IsTriviallyDestructible) {
ASSERT_TRUE((is_trivially_destructible<int>::value));
ASSERT_TRUE((is_trivially_destructible<TestStruct>::value));
ASSERT_FALSE((is_trivially_destructible<std::vector<int>>::value));
}
TEST(SanitizerCommon, IsTriviallyCopyable) {
ASSERT_TRUE((is_trivially_copyable<int>::value));
ASSERT_TRUE((is_trivially_copyable<TestStruct>::value));
ASSERT_FALSE((is_trivially_copyable<std::vector<int>>::value));
}
} // namespace __sanitizer