]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/shared_ptr/assign/sfinae.cc
1 // Copyright (C) 2016-2019 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-do compile { target c++11 } }
22 template<typename T
, typename From
>
23 constexpr bool can_assign()
24 { return std::is_assignable
<std::shared_ptr
<T
>, From
>::value
; }
27 struct Derived
: Base
{ };
31 static_assert( can_assign
<const void, const std::shared_ptr
<void>&>(),
32 "void* convertible to const void*");
33 static_assert( can_assign
<const void, std::shared_ptr
<void>&&>(),
34 "void* convertible to const void*");
35 static_assert( can_assign
<const int, std::shared_ptr
<int>>(),
36 "int* convertible to const int*");
37 static_assert( can_assign
<Base
, std::shared_ptr
<Derived
>>(),
38 "Derived* convertible to Base*");
39 static_assert( can_assign
<const Base
, std::shared_ptr
<Derived
>>(),
40 "Derived* convertible to const Base*");
44 static_assert( !can_assign
<int, const std::shared_ptr
<void>&>(),
45 "void* not convertible to int*");
46 static_assert( !can_assign
<int, std::shared_ptr
<void>&&>(),
47 "void* not convertible to int*");
49 static_assert( !can_assign
<int, const std::shared_ptr
<const int>&>(),
50 "const int* not convertible to int*");
51 static_assert( !can_assign
<int, std::shared_ptr
<const int>&&>(),
52 "const int* not convertible to int*");
54 static_assert( !can_assign
<int, const std::shared_ptr
<long>&>(),
55 "long* not convertible to int*");
56 static_assert( !can_assign
<int, std::shared_ptr
<long>&&>(),
57 "long* not convertible to int*");
59 static_assert( !can_assign
<int, std::unique_ptr
<long>&&>(),
60 "unique_ptr<long>::pointer not convertible to int*");
62 static_assert( !can_assign
<Derived
, const std::shared_ptr
<Base
>&>(),
63 "Base* not convertible to Derived*");
64 static_assert( !can_assign
<int, std::shared_ptr
<long>&&>(),
65 "Base* not convertible to Derived*");
66 static_assert( !can_assign
<Derived
, std::unique_ptr
<Base
>&&>(),
67 "unique_ptr<Base>::pointer not convertible to Derived*");
70 using pointer
= void*;
71 void operator()(pointer
) const { }
74 static_assert( !can_assign
<Derived
, std::unique_ptr
<Derived
, Deleter
>&&>(),
75 "unique_ptr<Derived, Deleter>::pointer not convertible to Derived*");