124dd2d2fSChristopher Di Bella //===----------------------------------------------------------------------===// 224dd2d2fSChristopher Di Bella // 324dd2d2fSChristopher Di Bella // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 424dd2d2fSChristopher Di Bella // See https://llvm.org/LICENSE.txt for license information. 524dd2d2fSChristopher Di Bella // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 624dd2d2fSChristopher Di Bella // 724dd2d2fSChristopher Di Bella //===----------------------------------------------------------------------===// 824dd2d2fSChristopher Di Bella 924dd2d2fSChristopher Di Bella // UNSUPPORTED: c++03, c++11, c++14, c++17 1024dd2d2fSChristopher Di Bella 1124dd2d2fSChristopher Di Bella // template<class T> 1224dd2d2fSChristopher Di Bella // concept default_initializable = constructible_from<T> && 1324dd2d2fSChristopher Di Bella // requires { T{}; } && 1424dd2d2fSChristopher Di Bella // is-default-initializable<T>; 1524dd2d2fSChristopher Di Bella 1624dd2d2fSChristopher Di Bella #include <concepts> 1724dd2d2fSChristopher Di Bella #include <cassert> 1824dd2d2fSChristopher Di Bella 1924dd2d2fSChristopher Di Bella #include "test_macros.h" 2024dd2d2fSChristopher Di Bella 2124dd2d2fSChristopher Di Bella template<class T> 2224dd2d2fSChristopher Di Bella concept brace_initializable = requires { T{}; }; 2324dd2d2fSChristopher Di Bella test()2424dd2d2fSChristopher Di Bellavoid test() { 2524dd2d2fSChristopher Di Bella // LWG3149 2624dd2d2fSChristopher Di Bella // Changed the concept from constructible_from<T> 2724dd2d2fSChristopher Di Bella // to constructible_from<T> && 2824dd2d2fSChristopher Di Bella // requires { T{}; } && is-default-initializable <T> 2924dd2d2fSChristopher Di Bella struct S0 { explicit S0() = default; }; 3024dd2d2fSChristopher Di Bella S0 x0; 3124dd2d2fSChristopher Di Bella S0 y0{}; 3224dd2d2fSChristopher Di Bella static_assert(std::constructible_from<S0>); 3324dd2d2fSChristopher Di Bella static_assert(brace_initializable<S0>); 3424dd2d2fSChristopher Di Bella LIBCPP_STATIC_ASSERT(std::__default_initializable<S0>); 3524dd2d2fSChristopher Di Bella static_assert(std::default_initializable<S0>); 3624dd2d2fSChristopher Di Bella 3724dd2d2fSChristopher Di Bella struct S1 { S0 x; }; // Note: aggregate 3824dd2d2fSChristopher Di Bella S1 x1; 3924dd2d2fSChristopher Di Bella S1 y1{}; // expected-error {{chosen constructor is explicit in copy-initialization}} 4024dd2d2fSChristopher Di Bella static_assert(std::constructible_from<S1>); 4124dd2d2fSChristopher Di Bella static_assert(!brace_initializable<S1>); 4224dd2d2fSChristopher Di Bella LIBCPP_STATIC_ASSERT(std::__default_initializable<S1>); 4324dd2d2fSChristopher Di Bella static_assert(!std::default_initializable<S1>); 4424dd2d2fSChristopher Di Bella 4524dd2d2fSChristopher Di Bella const int x2; // expected-error {{default initialization of an object of const type 'const int'}} 4624dd2d2fSChristopher Di Bella const int y2{}; 4724dd2d2fSChristopher Di Bella 4824dd2d2fSChristopher Di Bella static_assert(std::constructible_from<const int>); 4924dd2d2fSChristopher Di Bella static_assert(brace_initializable<const int>); 5024dd2d2fSChristopher Di Bella LIBCPP_STATIC_ASSERT(!std::__default_initializable<const int>); 5124dd2d2fSChristopher Di Bella static_assert(!std::default_initializable<const int>); 5224dd2d2fSChristopher Di Bella 53*7ea5409eSLouis Dionne const int x3[1]; // expected-error-re {{default initialization of an object of const type 'const int{{[ ]*}}[1]'}} 5424dd2d2fSChristopher Di Bella const int y3[1]{}; 5524dd2d2fSChristopher Di Bella static_assert(std::constructible_from<const int[1]>); 5624dd2d2fSChristopher Di Bella static_assert(brace_initializable<const int[1]>); 5724dd2d2fSChristopher Di Bella LIBCPP_STATIC_ASSERT(!std::__default_initializable<const int[1]>); 5824dd2d2fSChristopher Di Bella static_assert(!std::default_initializable<const int[1]>); 5924dd2d2fSChristopher Di Bella 6024dd2d2fSChristopher Di Bella // Zero-length array extension 6124dd2d2fSChristopher Di Bella const int x4[]; // expected-error {{definition of variable with array type needs an explicit size or an initializer}} 6224dd2d2fSChristopher Di Bella const int y4[]{}; 6324dd2d2fSChristopher Di Bella static_assert(!std::constructible_from<const int[]>); 6424dd2d2fSChristopher Di Bella static_assert(brace_initializable<const int[]>); 6524dd2d2fSChristopher Di Bella LIBCPP_STATIC_ASSERT(!std::__default_initializable<const int[]>); 6624dd2d2fSChristopher Di Bella static_assert(!std::default_initializable<const int[]>); 6724dd2d2fSChristopher Di Bella } 68