1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
12 // concept default_initializable = constructible_from<T> &&
13 // requires { T{}; } &&
14 // is-default-initializable<T>;
19 #include "test_macros.h"
22 concept brace_initializable
= requires
{ T
{}; };
26 // Changed the concept from constructible_from<T>
27 // to constructible_from<T> &&
28 // requires { T{}; } && is-default-initializable <T>
29 struct S0
{ explicit S0() = default; };
32 static_assert(std::constructible_from
<S0
>);
33 static_assert(brace_initializable
<S0
>);
34 LIBCPP_STATIC_ASSERT(std::__default_initializable
<S0
>);
35 static_assert(std::default_initializable
<S0
>);
37 struct S1
{ S0 x
; }; // Note: aggregate
39 S1 y1
{}; // expected-error {{chosen constructor is explicit in copy-initialization}}
40 static_assert(std::constructible_from
<S1
>);
41 static_assert(!brace_initializable
<S1
>);
42 LIBCPP_STATIC_ASSERT(std::__default_initializable
<S1
>);
43 static_assert(!std::default_initializable
<S1
>);
45 const int x2
; // expected-error {{default initialization of an object of const type 'const int'}}
48 static_assert(std::constructible_from
<const int>);
49 static_assert(brace_initializable
<const int>);
50 LIBCPP_STATIC_ASSERT(!std::__default_initializable
<const int>);
51 static_assert(!std::default_initializable
<const int>);
53 const int x3
[1]; // expected-error-re {{default initialization of an object of const type 'const int{{[ ]*}}[1]'}}
55 static_assert(std::constructible_from
<const int[1]>);
56 static_assert(brace_initializable
<const int[1]>);
57 LIBCPP_STATIC_ASSERT(!std::__default_initializable
<const int[1]>);
58 static_assert(!std::default_initializable
<const int[1]>);
60 // Zero-length array extension
61 const int x4
[]; // expected-error {{definition of variable with array type needs an explicit size or an initializer}}
63 static_assert(!std::constructible_from
<const int[]>);
64 static_assert(brace_initializable
<const int[]>);
65 LIBCPP_STATIC_ASSERT(!std::__default_initializable
<const int[]>);
66 static_assert(!std::default_initializable
<const int[]>);