Index: lib/sanitizer_common/sanitizer_type_traits.h =================================================================== --- /dev/null +++ lib/sanitizer_common/sanitizer_type_traits.h @@ -0,0 +1,44 @@ +//===-- sanitizer_type_traits.h ---------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Implements a subset of C++ type traits. This is so we can avoid depending +// on system C++ headers. +// +//===----------------------------------------------------------------------===// +#ifndef SANITIZER_TYPE_TRAITS_H +#define SANITIZER_TYPE_TRAITS_H + +namespace __sanitizer { + +struct true_type { + static const bool value = true; +}; + +struct false_type { + static const bool value = false; +}; + +// is_same +// +// Type trait to compare if types are the same. +// E.g. +// +// ``` +// is_same::value - True +// is_same::value - False +// ``` +template +struct is_same : public false_type {}; + +template +struct is_same : public true_type {}; + +}; // namespace __sanitizer + +#endif Index: lib/sanitizer_common/tests/CMakeLists.txt =================================================================== --- lib/sanitizer_common/tests/CMakeLists.txt +++ lib/sanitizer_common/tests/CMakeLists.txt @@ -36,6 +36,7 @@ sanitizer_symbolizer_test.cc sanitizer_test_main.cc sanitizer_thread_registry_test.cc + sanitizer_type_traits_test.cc sanitizer_vector_test.cc) set(SANITIZER_TEST_HEADERS Index: lib/sanitizer_common/tests/sanitizer_type_traits_test.cc =================================================================== --- /dev/null +++ lib/sanitizer_common/tests/sanitizer_type_traits_test.cc @@ -0,0 +1,28 @@ +//===-- sanitizer_type_traits_test.cc -------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of ThreadSanitizer/AddressSanitizer runtime. +// +//===----------------------------------------------------------------------===// +#include "sanitizer_common/sanitizer_type_traits.h" +#include "gtest/gtest.h" +#include "sanitizer_common/sanitizer_internal_defs.h" + +using namespace __sanitizer; + +TEST(SanitizerCommon, IsSame) { + ASSERT_TRUE((is_same::value)); + ASSERT_TRUE((is_same::value)); + ASSERT_TRUE((is_same::value)); + ASSERT_TRUE((is_same::value)); + + ASSERT_FALSE((is_same::value)); + ASSERT_FALSE((is_same::value)); + ASSERT_FALSE((is_same::value)); +}