//===- TypeTraitsTest.cpp -------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/FunctionExtras.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/type_traits.h" #include "gtest/gtest.h" #include namespace { // Compile-time tests using static assert. namespace triviality { // Helper for compile time checking trivially copy constructible and trivially // move constructible type traits. template void TrivialityTester() { static_assert(std::is_trivially_copy_constructible::value == IsTriviallyCopyConstructible, "Mismatch in expected trivial copy construction!"); static_assert(std::is_trivially_move_constructible::value == IsTriviallyMoveConstructible, "Mismatch in expected trivial move construction!"); #if defined(_LIBCPP_VERSION) || defined(_MSC_VER) // On compilers with support for the standard traits, make sure they agree. static_assert(std::is_trivially_copy_constructible::value == IsTriviallyCopyConstructible, "Mismatch in expected trivial copy construction!"); static_assert(std::is_trivially_move_constructible::value == IsTriviallyMoveConstructible, "Mismatch in expected trivial move construction!"); #endif } template void TrivialityTester(); template void TrivialityTester(); template void TrivialityTester(); template void TrivialityTester(); struct X {}; struct Y { Y(const Y &); }; struct Z { Z(const Z &); Z(Z &&); }; struct A { A(const A &) = default; A(A &&); }; struct B { B(const B &); B(B &&) = default; }; template void TrivialityTester(); template void TrivialityTester(); template void TrivialityTester(); template void TrivialityTester(); template void TrivialityTester(); template void TrivialityTester(); template void TrivialityTester(); template void TrivialityTester(); template void TrivialityTester(); template void TrivialityTester(); template void TrivialityTester(); TEST(Triviality, Tester) { TrivialityTester(); TrivialityTester(); TrivialityTester(); TrivialityTester(); TrivialityTester(); TrivialityTester(); TrivialityTester(); TrivialityTester(); TrivialityTester(); TrivialityTester(); TrivialityTester(); TrivialityTester(); TrivialityTester(); TrivialityTester(); TrivialityTester(); } // Test that the following ADT behave as expected wrt. trivially copyable trait // // NB: It is important that this trait behaves the same for (at least) these // types for all supported compilers to prevent ABI issue when llvm is compiled // with compiler A and an other project using llvm is compiled with compiler B. TEST(Triviality, ADT) { TrivialityTester, false, false>(); TrivialityTester, false, false>(); TrivialityTester, false, false>(); #if !defined(__FreeBSD__) TrivialityTester, true, true>(); #endif TrivialityTester, false, false>(); TrivialityTester(); TrivialityTester, true, true>(); TrivialityTester, true, true>(); #if defined(_LIBCPP_VERSION) || \ (defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE >= 8) TrivialityTester, true, true>(); #endif } } // namespace triviality } // end anonymous namespace