//===----------------------------------------------------------------------===// // // 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 // //===----------------------------------------------------------------------===// // type_traits // template // struct is_constructible; // UNSUPPORTED: gcc-5, gcc-6, gcc-7, gcc-8, gcc-9 #include #include "test_macros.h" #if TEST_STD_VER >= 11 && defined(_LIBCPP_VERSION) #define LIBCPP11_STATIC_ASSERT(...) static_assert(__VA_ARGS__) #else #define LIBCPP11_STATIC_ASSERT(...) ((void)0) #endif struct A { explicit A(int); A(int, double); A(int, long, double); #if TEST_STD_VER >= 11 private: #endif A(char); }; struct Base {}; struct Derived : public Base {}; class Abstract { virtual void foo() = 0; }; class AbstractDestructor { virtual ~AbstractDestructor() = 0; }; struct PrivateDtor { PrivateDtor(int) {} private: ~PrivateDtor() {} }; struct S { template #if TEST_STD_VER >= 11 explicit #endif operator T () const; }; template struct ImplicitTo { operator To(); }; #if TEST_STD_VER >= 11 template struct ExplicitTo { explicit operator To (); }; #endif template void test_is_constructible() { static_assert( (std::is_constructible::value), ""); #if TEST_STD_VER > 14 static_assert( std::is_constructible_v, ""); #endif } template void test_is_constructible() { static_assert(( std::is_constructible::value), ""); #if TEST_STD_VER > 14 static_assert(( std::is_constructible_v), ""); #endif } template void test_is_constructible() { static_assert(( std::is_constructible::value), ""); #if TEST_STD_VER > 14 static_assert(( std::is_constructible_v), ""); #endif } template void test_is_constructible() { static_assert(( std::is_constructible::value), ""); #if TEST_STD_VER > 14 static_assert(( std::is_constructible_v), ""); #endif } template void test_is_not_constructible() { static_assert((!std::is_constructible::value), ""); #if TEST_STD_VER > 14 static_assert((!std::is_constructible_v), ""); #endif } template void test_is_not_constructible() { static_assert((!std::is_constructible::value), ""); #if TEST_STD_VER > 14 static_assert((!std::is_constructible_v), ""); #endif } int main(int, char**) { typedef Base B; typedef Derived D; test_is_constructible (); test_is_constructible (); test_is_constructible (); test_is_constructible (); test_is_constructible (); test_is_constructible (); test_is_not_constructible (); #if TEST_STD_VER >= 11 test_is_not_constructible (); #else test_is_constructible (); #endif test_is_not_constructible (); test_is_not_constructible(); test_is_not_constructible(); test_is_not_constructible(); test_is_not_constructible(); test_is_not_constructible(); test_is_not_constructible(); test_is_not_constructible(); test_is_not_constructible (); test_is_not_constructible (); // LWG 2738 test_is_not_constructible (); test_is_not_constructible (); test_is_not_constructible (); test_is_not_constructible (); test_is_not_constructible (); test_is_constructible(); test_is_not_constructible(); test_is_constructible(); test_is_constructible(); #if TEST_STD_VER >= 11 test_is_constructible(); test_is_constructible(); test_is_constructible(); #endif #if TEST_STD_VER >= 11 test_is_constructible(); test_is_constructible(); test_is_constructible(); test_is_constructible(); test_is_not_constructible(); test_is_not_constructible(); test_is_not_constructible(); test_is_constructible(); test_is_constructible(); test_is_not_constructible(); test_is_not_constructible(); test_is_constructible(); test_is_constructible(); test_is_not_constructible(); test_is_constructible(); #ifndef TEST_COMPILER_GCC test_is_not_constructible(); test_is_not_constructible(); #endif test_is_constructible(); test_is_constructible(); #ifndef TEST_COMPILER_GCC test_is_not_constructible(); test_is_not_constructible(); #endif // test that T must also be destructible test_is_constructible(); test_is_not_constructible(); test_is_not_constructible(); test_is_not_constructible(); test_is_constructible>(); test_is_constructible>(); test_is_constructible>(); test_is_constructible>(); test_is_not_constructible(); test_is_not_constructible(); test_is_constructible>(); test_is_constructible&>(); test_is_constructible(); test_is_constructible&>(); test_is_constructible>(); test_is_constructible&>(); test_is_constructible>(); test_is_constructible&>(); test_is_constructible>(); // Binding through reference-compatible type is required to perform // direct-initialization as described in [over.match.ref] p. 1 b. 1: // // But the rvalue to lvalue reference binding isn't allowed according to // [over.match.ref] despite Clang accepting it. test_is_constructible>(); #ifndef TEST_COMPILER_GCC test_is_constructible>(); #endif static_assert(std::is_constructible>::value, ""); #ifdef __clang__ // FIXME Clang and GCC disagree on the validity of this expression. test_is_constructible>(); static_assert(std::is_constructible>::value, ""); #else test_is_not_constructible>(); test_is_not_constructible>(); #endif // Binding through temporary behaves like copy-initialization, // see [dcl.init.ref] p. 5, very last sub-bullet: test_is_not_constructible>(); test_is_not_constructible>(); test_is_not_constructible(); test_is_not_constructible (); test_is_not_constructible (); test_is_not_constructible (); test_is_not_constructible (); #endif // TEST_STD_VER >= 11 return 0; }