//===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // type_traits // is_convertible #include #include "test_macros.h" template void test_is_convertible() { static_assert((std::is_convertible::value), ""); static_assert((std::is_convertible::value), ""); static_assert((std::is_convertible::value), ""); static_assert((std::is_convertible::value), ""); #if TEST_STD_VER > 14 static_assert((std::is_convertible_v), ""); static_assert((std::is_convertible_v), ""); static_assert((std::is_convertible_v), ""); static_assert((std::is_convertible_v), ""); #endif } template void test_is_not_convertible() { static_assert((!std::is_convertible::value), ""); static_assert((!std::is_convertible::value), ""); static_assert((!std::is_convertible::value), ""); static_assert((!std::is_convertible::value), ""); #if TEST_STD_VER > 14 static_assert((!std::is_convertible_v), ""); static_assert((!std::is_convertible_v), ""); static_assert((!std::is_convertible_v), ""); static_assert((!std::is_convertible_v), ""); #endif } typedef void Function(); typedef void ConstFunction() const; typedef char Array[1]; struct StringType { StringType(const char*) {} }; class NonCopyable { NonCopyable(NonCopyable&); }; template class CannotInstantiate { enum { X = T::ThisExpressionWillBlowUp }; }; int main() { // void test_is_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible(); // Function test_is_not_convertible (); test_is_not_convertible (); test_is_convertible (); test_is_convertible (); test_is_convertible (); #if TEST_STD_VER >= 11 static_assert(( std::is_convertible::value), ""); #endif test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); // Function& test_is_not_convertible (); test_is_not_convertible (); test_is_convertible (); test_is_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); // Function* test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); // Non-referencable function type static_assert((!std::is_convertible::value), ""); static_assert((!std::is_convertible::value), ""); static_assert((!std::is_convertible::value), ""); #if TEST_STD_VER >= 11 static_assert((!std::is_convertible::value), ""); #endif static_assert((!std::is_convertible::value), ""); static_assert((!std::is_convertible::value), ""); static_assert((!std::is_convertible::value), ""); static_assert((!std::is_convertible::value), ""); // Array test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); static_assert((!std::is_convertible::value), ""); static_assert(( std::is_convertible::value), ""); static_assert((!std::is_convertible::value), ""); static_assert((!std::is_convertible::value), ""); static_assert(( std::is_convertible::value), ""); static_assert((!std::is_convertible::value), ""); static_assert((!std::is_convertible::value), ""); #if TEST_STD_VER >= 11 static_assert(( std::is_convertible::value), ""); static_assert(( std::is_convertible::value), ""); static_assert(( std::is_convertible::value), ""); static_assert(( std::is_convertible::value), ""); static_assert(( std::is_convertible::value), ""); static_assert((!std::is_convertible::value), ""); static_assert((!std::is_convertible::value), ""); #endif test_is_not_convertible (); test_is_not_convertible (); static_assert(( std::is_convertible::value), ""); static_assert(( std::is_convertible::value), ""); static_assert(( std::is_convertible::value), ""); static_assert(( std::is_convertible::value), ""); static_assert((!std::is_convertible::value), ""); static_assert(( std::is_convertible::value), ""); static_assert((!std::is_convertible::value), ""); static_assert((!std::is_convertible::value), ""); // Array& test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); static_assert(( std::is_convertible::value), ""); static_assert(( std::is_convertible::value), ""); static_assert((!std::is_convertible::value), ""); static_assert(( std::is_convertible::value), ""); test_is_not_convertible (); test_is_not_convertible (); static_assert(( std::is_convertible::value), ""); static_assert(( std::is_convertible::value), ""); static_assert((!std::is_convertible::value), ""); static_assert(( std::is_convertible::value), ""); static_assert((std::is_convertible::value), ""); static_assert((std::is_convertible::value), ""); // char test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_convertible (); static_assert((!std::is_convertible::value), ""); static_assert(( std::is_convertible::value), ""); static_assert((!std::is_convertible::value), ""); static_assert(( std::is_convertible::value), ""); test_is_not_convertible (); // char& test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_convertible (); static_assert(( std::is_convertible::value), ""); static_assert(( std::is_convertible::value), ""); static_assert((!std::is_convertible::value), ""); static_assert(( std::is_convertible::value), ""); test_is_not_convertible (); // char* test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); test_is_not_convertible (); static_assert(( std::is_convertible::value), ""); static_assert(( std::is_convertible::value), ""); static_assert((!std::is_convertible::value), ""); static_assert(( std::is_convertible::value), ""); // NonCopyable static_assert((std::is_convertible::value), ""); static_assert((std::is_convertible::value), ""); static_assert((std::is_convertible::value), ""); static_assert((std::is_convertible::value), ""); static_assert((std::is_convertible::value), ""); static_assert((std::is_convertible::value), ""); static_assert((std::is_convertible::value), ""); static_assert((std::is_convertible::value), ""); static_assert((!std::is_convertible::value), ""); // This test requires Access control SFINAE which we only have in C++11 or when // we are using the compiler builtin for is_convertible. #if TEST_STD_VER >= 11 || !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK) test_is_not_convertible(); #endif // Ensure that CannotInstantiate is not instantiated by is_convertible when it is not needed. // For example CannotInstantiate is instatiated as a part of ADL lookup for arguments of type CannotInstantiate*. static_assert((std::is_convertible*, CannotInstantiate*>::value), ""); }