]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/allocator/89510.cc
1 // Copyright (C) 2020-2022 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 } }
19 // { dg-require-effective-target hosted }
23 using AT
= std::allocator_traits
<std::allocator
<int>>;
25 template<typename
...> using void_t
= void;
27 template<typename T
, typename U
, typename
= void>
32 template<typename T
, typename U
>
33 struct has_construct
<T
, U
,
34 void_t
<decltype(std::declval
<T
&>().construct(std::declval
<U
*>()))>>
38 template<typename T
, typename U
, typename
= void>
43 template<typename T
, typename U
>
44 struct has_destroy
<T
, U
,
45 void_t
<decltype(std::declval
<T
&>().destroy(std::declval
<U
*>()))>>
49 template<typename T
, typename U
, typename
= void>
50 struct has_traits_construct
54 template<typename T
, typename U
>
55 struct has_traits_construct
<T
, U
,
56 void_t
<decltype(AT::construct(std::declval
<T
&>(), std::declval
<U
*>()))>>
60 template<typename T
, typename U
, typename
= void>
61 struct has_traits_destroy
65 template<typename T
, typename U
>
66 struct has_traits_destroy
<T
, U
,
67 void_t
<decltype(AT::destroy(std::declval
<T
&>(), std::declval
<U
*>()))>>
71 struct NoDefault
{ NoDefault(int); };
72 struct NoDest
{ private: ~NoDest(); };
74 // Whether true or false, this should not give an error:
75 constexpr bool c
= has_construct
<std::allocator
<NoDefault
>, NoDefault
>::value
;
76 constexpr bool cv
= has_construct
<std::allocator
<void>, NoDefault
>::value
;
77 constexpr bool c2
= has_traits_construct
<std::allocator
<int>, NoDefault
>::value
;
78 constexpr bool d
= has_destroy
<std::allocator
<NoDest
>, NoDest
>::value
;
79 constexpr bool d2
= has_traits_destroy
<std::allocator
<int>, NoDest
>::value
;
81 std::allocator
<int> a
;
84 #if __cplusplus <= 201703L
85 static_assert( noexcept(a
.construct(lp
)), "" );
86 static_assert( noexcept(a
.construct(lp
, 1L)), "" );
87 static_assert( noexcept(a
.construct(lp
, 2)), "" );
88 static_assert( noexcept(a
.construct(lp
, 2U)), "" );
89 static_assert( noexcept(a
.destroy(lp
)), "" );
91 static_assert( noexcept(AT::construct(a
, lp
)), "" );
92 static_assert( noexcept(AT::construct(a
, lp
, 1L)), "" );
93 static_assert( noexcept(AT::construct(a
, lp
, 2)), "" );
94 static_assert( noexcept(AT::construct(a
, lp
, 2U)), "" );
95 static_assert( noexcept(AT::destroy(a
, lp
)), "" );
105 #if __cplusplus <= 201703L
106 static_assert( noexcept(a
.construct(xp
)), "" );
107 static_assert( noexcept(a
.construct(xp
, 1)), "" );
108 static_assert( noexcept(a
.destroy(xp
)), "" );
110 static_assert( noexcept(AT::construct(a
, xp
)), "" );
111 static_assert( noexcept(AT::construct(a
, xp
, 1)), "" );
112 static_assert( noexcept(AT::destroy(a
, xp
)), "" );
117 Y(int) noexcept(false);
122 #if __cplusplus <= 201703L
123 static_assert( noexcept(a
.construct(yp
)), "" );
124 static_assert( ! noexcept(a
.construct(yp
, 1)), "" );
125 static_assert( noexcept(a
.destroy(yp
)), "" );
127 static_assert( noexcept(AT::construct(a
, yp
)), "" );
128 static_assert( ! noexcept(AT::construct(a
, yp
, 1)), "" );
129 static_assert( noexcept(AT::destroy(a
, yp
)), "" );
135 ~Z() noexcept(false);
139 // These construct calls should be noexcept, but they are false because
140 // they use is_nothrow_constructible which depends on is_nothrow_destructible.
141 #if __cplusplus <= 201703L
142 static_assert( ! noexcept(a
.construct(zp
)), "wrong" );
143 static_assert( ! noexcept(a
.construct(zp
, 1)), "wrong" );
144 static_assert( ! noexcept(a
.destroy(zp
)), "" );
146 static_assert( ! noexcept(AT::construct(a
, zp
)), "" );
147 static_assert( ! noexcept(AT::construct(a
, zp
, 1)), "" );
148 static_assert( ! noexcept(AT::destroy(a
, zp
)), "" );