]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/ext/new_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 } }
20 #include <ext/new_allocator.h>
22 #include <type_traits>
24 using __gnu_cxx::new_allocator
;
25 using AT
= std::allocator_traits
<new_allocator
<int>>;
27 template<typename
...> using void_t
= void;
29 template<typename T
, typename U
, typename
= void>
34 template<typename T
, typename U
>
35 struct has_construct
<T
, U
,
36 void_t
<decltype(std::declval
<T
&>().construct(std::declval
<U
*>()))>>
40 template<typename T
, typename U
, typename
= void>
45 template<typename T
, typename U
>
46 struct has_destroy
<T
, U
,
47 void_t
<decltype(std::declval
<T
&>().destroy(std::declval
<U
*>()))>>
51 template<typename T
, typename U
, typename
= void>
52 struct has_traits_construct
56 template<typename T
, typename U
>
57 struct has_traits_construct
<T
, U
,
58 void_t
<decltype(AT::construct(std::declval
<T
&>(), std::declval
<U
*>()))>>
62 template<typename T
, typename U
, typename
= void>
63 struct has_traits_destroy
67 template<typename T
, typename U
>
68 struct has_traits_destroy
<T
, U
,
69 void_t
<decltype(AT::destroy(std::declval
<T
&>(), std::declval
<U
*>()))>>
73 struct NoDefault
{ NoDefault(int); };
74 struct NoDest
{ private: ~NoDest(); };
76 // Whether true or false, these should not give errors:
77 constexpr bool c
= has_construct
<new_allocator
<NoDefault
>, NoDefault
>::value
;
78 constexpr bool c2
= has_traits_construct
<new_allocator
<int>, NoDefault
>::value
;
79 constexpr bool d
= has_destroy
<new_allocator
<NoDest
>, NoDest
>::value
;
80 constexpr bool d2
= has_traits_destroy
<new_allocator
<int>, NoDest
>::value
;
85 #if __cplusplus <= 201703L
86 static_assert( noexcept(a
.construct(lp
)), "" );
87 static_assert( noexcept(a
.construct(lp
, 1L)), "" );
88 static_assert( noexcept(a
.construct(lp
, 2)), "" );
89 static_assert( noexcept(a
.construct(lp
, 2U)), "" );
90 static_assert( noexcept(a
.destroy(lp
)), "" );
92 static_assert( noexcept(AT::construct(a
, lp
)), "" );
93 static_assert( noexcept(AT::construct(a
, lp
, 1L)), "" );
94 static_assert( noexcept(AT::construct(a
, lp
, 2)), "" );
95 static_assert( noexcept(AT::construct(a
, lp
, 2U)), "" );
96 static_assert( noexcept(AT::destroy(a
, lp
)), "" );
106 #if __cplusplus <= 201703L
107 static_assert( noexcept(a
.construct(xp
)), "" );
108 static_assert( noexcept(a
.construct(xp
, 1)), "" );
109 static_assert( noexcept(a
.destroy(xp
)), "" );
111 static_assert( noexcept(AT::construct(a
, xp
)), "" );
112 static_assert( noexcept(AT::construct(a
, xp
, 1)), "" );
113 static_assert( noexcept(AT::destroy(a
, xp
)), "" );
118 Y(int) noexcept(false);
123 #if __cplusplus <= 201703L
124 static_assert( noexcept(a
.construct(yp
)), "" );
125 static_assert( ! noexcept(a
.construct(yp
, 1)), "" );
126 static_assert( noexcept(a
.destroy(yp
)), "" );
128 static_assert( noexcept(AT::construct(a
, yp
)), "" );
129 static_assert( ! noexcept(AT::construct(a
, yp
, 1)), "" );
130 static_assert( noexcept(AT::destroy(a
, yp
)), "" );
136 ~Z() noexcept(false);
140 // These construct calls should be noexcept, but they are false because
141 // they use is_nothrow_constructible which depends on is_nothrow_destructible.
142 #if __cplusplus <= 201703L
143 static_assert( ! noexcept(a
.construct(zp
)), "wrong" );
144 static_assert( ! noexcept(a
.construct(zp
, 1)), "wrong" );
145 static_assert( ! noexcept(a
.destroy(zp
)), "" );
147 static_assert( ! noexcept(AT::construct(a
, zp
)), "" );
148 static_assert( ! noexcept(AT::construct(a
, zp
, 1)), "" );
149 static_assert( ! noexcept(AT::destroy(a
, zp
)), "" );