[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / concepts / concepts.lang / concept.default.init / default_initializable.compile.pass.cpp
blobee1405f1f889d8a0dd6ab46fd09843d6f1f22a03
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-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 // We voluntarily use std::default_initializable on types that have redundant
12 // or ignored cv-qualifiers -- don't warn about it.
13 // ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-ignored-qualifiers
15 // template<class T>
16 // concept default_initializable = constructible_from<T> &&
17 // requires { T{}; } &&
18 // is-default-initializable<T>;
20 #include <array>
21 #include <concepts>
22 #include <deque>
23 #include <forward_list>
24 #include <list>
25 #include <map>
26 #include <memory>
27 #include <queue>
28 #include <set>
29 #include <span>
30 #include <stack>
31 #include <string>
32 #include <string_view>
33 #include <unordered_map>
34 #include <unordered_set>
35 #include <vector>
37 #include "test_macros.h"
39 struct Empty {};
41 struct CtorDefaulted {
42 CtorDefaulted() = default;
44 struct CtorDeleted {
45 CtorDeleted() = delete;
47 struct DtorDefaulted {
48 ~DtorDefaulted() = default;
50 struct DtorDeleted {
51 ~DtorDeleted() = delete;
54 struct Noexcept {
55 ~Noexcept() noexcept;
57 struct NoexceptTrue {
58 ~NoexceptTrue() noexcept(true);
60 struct NoexceptFalse {
61 ~NoexceptFalse() noexcept(false);
64 struct CtorProtected {
65 protected:
66 CtorProtected() = default;
68 struct CtorPrivate {
69 private:
70 CtorPrivate() = default;
72 struct DtorProtected {
73 protected:
74 ~DtorProtected() = default;
76 struct DtorPrivate {
77 private:
78 ~DtorPrivate() = default;
81 template <class T>
82 struct NoexceptDependant {
83 ~NoexceptDependant() noexcept(std::is_same_v<T, int>);
86 struct CtorExplicit {
87 explicit CtorExplicit() = default;
89 struct CtorArgument {
90 CtorArgument(int) {}
92 struct CtorDefaultArgument {
93 CtorDefaultArgument(int = 0) {}
95 struct CtorExplicitDefaultArgument {
96 explicit CtorExplicitDefaultArgument(int = 0) {}
99 struct Derived : public Empty {};
101 class Abstract {
102 virtual void foo() = 0;
105 class AbstractDestructor {
106 virtual ~AbstractDestructor() = 0;
109 class OperatorNewDeleted {
110 void* operator new(std::size_t) = delete;
111 void operator delete(void* ptr) = delete;
114 [[maybe_unused]] auto Lambda = [](const int&, int&&, double){};
116 template<class T>
117 void test_not_const()
119 static_assert( std::default_initializable< T>);
120 static_assert(!std::default_initializable<const T>);
121 static_assert( std::default_initializable< volatile T>);
122 static_assert(!std::default_initializable<const volatile T>);
125 template<class T>
126 void test_true()
128 static_assert( std::default_initializable< T>);
129 static_assert( std::default_initializable<const T>);
130 static_assert( std::default_initializable< volatile T>);
131 static_assert( std::default_initializable<const volatile T>);
134 template<class T>
135 void test_false()
137 static_assert(!std::default_initializable< T>);
138 static_assert(!std::default_initializable<const T>);
139 static_assert(!std::default_initializable< volatile T>);
140 static_assert(!std::default_initializable<const volatile T>);
143 void test()
145 test_not_const<bool>();
146 test_not_const<char>();
147 test_not_const<int>();
148 test_not_const<double>();
150 test_false <void>();
151 test_not_const<void*>();
153 test_not_const<int*>();
154 test_false <int[]>();
155 test_not_const<int[1]>();
156 test_false <int&>();
157 test_false <int&&>();
159 test_true <Empty>();
161 test_true <CtorDefaulted>();
162 test_false <CtorDeleted>();
163 test_true <DtorDefaulted>();
164 test_false <DtorDeleted>();
166 test_true <Noexcept>();
167 test_true <NoexceptTrue>();
168 test_false <NoexceptFalse>();
170 test_false <CtorProtected>();
171 test_false <CtorPrivate>();
172 test_false <DtorProtected>();
173 test_false <DtorPrivate>();
175 test_true <NoexceptDependant<int>>();
176 test_false <NoexceptDependant<double>>();
178 test_true <CtorExplicit>();
179 test_false <CtorArgument>();
180 test_true <CtorDefaultArgument>();
181 test_true <CtorExplicitDefaultArgument>();
183 test_true <Derived>();
184 test_false <Abstract>();
185 test_false <AbstractDestructor>();
187 test_true <OperatorNewDeleted>();
189 test_true <decltype(Lambda)>();
190 test_not_const<void(*)(const int&)>();
191 test_not_const<void(Empty::*)(const int&) >();
192 test_not_const<void(Empty::*)(const int&) const >();
193 test_not_const<void(Empty::*)(const int&) volatile>();
194 test_not_const<void(Empty::*)(const int&) const volatile>();
195 test_not_const<void(Empty::*)(const int&) &>();
196 test_not_const<void(Empty::*)(const int&) &&>();
197 test_not_const<void(Empty::*)(const int&) noexcept>();
198 test_not_const<void(Empty::*)(const int&) noexcept(true)>();
199 test_not_const<void(Empty::*)(const int&) noexcept(false)>();
201 // Sequence containers
202 test_true <std::array< int, 0>>();
203 test_not_const<std::array< int, 1>>();
204 test_false <std::array<const int, 1>>();
205 test_not_const<std::array< volatile int, 1>>();
206 test_false <std::array<const volatile int, 1>>();
207 test_true <std::deque< int>>();
208 #ifdef _LIBCPP_VERSION
209 test_true <std::deque<const int>>();
210 #endif // _LIBCPP_VERSION
211 test_true <std::forward_list<int>>();
212 test_true <std::list<int>>();
213 test_true <std::vector<int>>();
215 // Associative containers
216 test_true <std::set<int>>();
217 test_true <std::map<int, int>>();
218 test_true <std::multiset<int>>();
219 test_true <std::multimap<int, int>>();
221 // Unordered associative containers
222 test_true <std::unordered_set<int>>();
223 test_true <std::unordered_map<int, int>>();
224 test_true <std::unordered_multiset<int>>();
225 test_true <std::unordered_multimap<int, int>>();
227 // Container adaptors
228 test_true <std::stack< int>>();
229 #ifdef _LIBCPP_VERSION
230 test_true <std::stack<const int>>();
231 #endif // _LIBCPP_VERSION
232 test_true <std::queue<int>>();
233 test_true <std::priority_queue<int>>();
235 test_true <std::span< int>>();
236 test_true <std::span<const int>>();
237 test_true <std::span< volatile int>>();
238 test_true <std::span<const volatile int>>();
240 // Strings
241 test_true <std::string>();
242 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
243 test_true <std::wstring>();
244 #endif
245 test_true <std::u8string>();
246 test_true <std::u16string>();
247 test_true <std::u32string>();
249 // String views
250 test_true <std::string_view>();
251 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
252 test_true <std::wstring_view>();
253 #endif
254 test_true <std::u8string_view>();
255 test_true <std::u16string_view>();
256 test_true <std::u32string_view>();
258 // Smart pointers
259 test_true <std::unique_ptr<int>>();
260 test_true <std::shared_ptr<int>>();
261 test_true <std::weak_ptr<int>>();