118 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_default_constructible12 13#include <type_traits>14#include "test_macros.h"15 16template <class T>17void test_is_default_constructible()18{19 static_assert( std::is_default_constructible<T>::value, "");20 static_assert( std::is_default_constructible<const T>::value, "");21 static_assert( std::is_default_constructible<volatile T>::value, "");22 static_assert( std::is_default_constructible<const volatile T>::value, "");23#if TEST_STD_VER > 1424 static_assert( std::is_default_constructible_v<T>, "");25 static_assert( std::is_default_constructible_v<const T>, "");26 static_assert( std::is_default_constructible_v<volatile T>, "");27 static_assert( std::is_default_constructible_v<const volatile T>, "");28#endif29}30 31template <class T>32void test_is_not_default_constructible()33{34 static_assert(!std::is_default_constructible<T>::value, "");35 static_assert(!std::is_default_constructible<const T>::value, "");36 static_assert(!std::is_default_constructible<volatile T>::value, "");37 static_assert(!std::is_default_constructible<const volatile T>::value, "");38#if TEST_STD_VER > 1439 static_assert(!std::is_default_constructible_v<T>, "");40 static_assert(!std::is_default_constructible_v<const T>, "");41 static_assert(!std::is_default_constructible_v<volatile T>, "");42 static_assert(!std::is_default_constructible_v<const volatile T>, "");43#endif44}45 46class Empty47{48};49 50class NoDefaultConstructor51{52 NoDefaultConstructor(int) {}53};54 55class NotEmpty56{57public:58 virtual ~NotEmpty();59};60 61union Union {};62 63struct bit_zero64{65 int : 0;66};67 68class Abstract69{70public:71 virtual ~Abstract() = 0;72};73 74struct A75{76 A();77};78 79class B80{81 B();82};83 84int main(int, char**)85{86 test_is_default_constructible<A>();87 test_is_default_constructible<Union>();88 test_is_default_constructible<Empty>();89 test_is_default_constructible<int>();90 test_is_default_constructible<double>();91 test_is_default_constructible<int*>();92 test_is_default_constructible<const int*>();93 test_is_default_constructible<char[3]>();94 test_is_default_constructible<char[5][3]>();95 96 test_is_default_constructible<NotEmpty>();97 test_is_default_constructible<bit_zero>();98 99 test_is_not_default_constructible<void>();100 test_is_not_default_constructible<int&>();101 test_is_not_default_constructible<char[]>();102 test_is_not_default_constructible<char[][3]>();103 104 test_is_not_default_constructible<Abstract>();105 test_is_not_default_constructible<NoDefaultConstructor>();106#if TEST_STD_VER >= 11107 test_is_not_default_constructible<B>();108 test_is_not_default_constructible<int&&>();109 test_is_not_default_constructible<void()>();110 test_is_not_default_constructible<void() const> ();111 test_is_not_default_constructible<void() volatile> ();112 test_is_not_default_constructible<void() &> ();113 test_is_not_default_constructible<void() &&> ();114#endif115 116 return 0;117}118