97 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// type_traits10 11// is_polymorphic12 13#include <type_traits>14#include "test_macros.h"15 16template <class T>17void test_is_polymorphic()18{19 static_assert( std::is_polymorphic<T>::value, "");20 static_assert( std::is_polymorphic<const T>::value, "");21 static_assert( std::is_polymorphic<volatile T>::value, "");22 static_assert( std::is_polymorphic<const volatile T>::value, "");23#if TEST_STD_VER > 1424 static_assert( std::is_polymorphic_v<T>, "");25 static_assert( std::is_polymorphic_v<const T>, "");26 static_assert( std::is_polymorphic_v<volatile T>, "");27 static_assert( std::is_polymorphic_v<const volatile T>, "");28#endif29}30 31template <class T>32void test_is_not_polymorphic()33{34 static_assert(!std::is_polymorphic<T>::value, "");35 static_assert(!std::is_polymorphic<const T>::value, "");36 static_assert(!std::is_polymorphic<volatile T>::value, "");37 static_assert(!std::is_polymorphic<const volatile T>::value, "");38#if TEST_STD_VER > 1439 static_assert(!std::is_polymorphic_v<T>, "");40 static_assert(!std::is_polymorphic_v<const T>, "");41 static_assert(!std::is_polymorphic_v<volatile T>, "");42 static_assert(!std::is_polymorphic_v<const volatile T>, "");43#endif44}45 46class Empty47{48};49 50class NotEmpty51{52 virtual ~NotEmpty();53};54 55union Union {};56 57struct bit_zero58{59 int : 0;60};61 62class Abstract63{64 virtual ~Abstract() = 0;65};66 67#if TEST_STD_VER >= 1168class Final final {69};70#else71class Final {72};73#endif74 75int main(int, char**)76{77 test_is_not_polymorphic<void>();78 test_is_not_polymorphic<int&>();79 test_is_not_polymorphic<int>();80 test_is_not_polymorphic<double>();81 test_is_not_polymorphic<int*>();82 test_is_not_polymorphic<const int*>();83 test_is_not_polymorphic<char[3]>();84 test_is_not_polymorphic<char[]>();85 test_is_not_polymorphic<Union>();86 test_is_not_polymorphic<Empty>();87 test_is_not_polymorphic<bit_zero>();88 test_is_not_polymorphic<Final>();89 test_is_not_polymorphic<NotEmpty&>();90 test_is_not_polymorphic<Abstract&>();91 92 test_is_polymorphic<NotEmpty>();93 test_is_polymorphic<Abstract>();94 95 return 0;96}97