Debian Codegraph @

libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.defaultinitializable/lwg3149.cc

raw
1 // Copyright (C) 2019-2025 Free Software Foundation, Inc.
2 //
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)
7 // any later version.
8
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.
13
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/>.
17
18 // { dg-do compile { target c++20 } }
19
20 #include <concepts>
21
22 // Default-initialization of const T is only valid for class types that are
23 // const-default-constructible.
24 static_assert( !std::default_initializable<const int> );
25 static_assert( !std::default_initializable<const int[1]> );
26 struct A { int i; };
27 static_assert( !std::default_initializable<const A> );
28 static_assert( !std::default_initializable<const A[1]> );
29 struct B { int i; long l; };
30 static_assert( !std::default_initializable<const B> );
31 static_assert( !std::default_initializable<const B[1]> );
32 struct C : A { };
33 static_assert( !std::default_initializable<const C> );
34 static_assert( !std::default_initializable<const C[1]> );
35 struct D { A a; };
36 static_assert( !std::default_initializable<const D> );
37 static_assert( !std::default_initializable<const D[1]> );
38
39 struct S0 { explicit S0() = default; };
40 struct S1 { S0 x; }; // Note: aggregate
41 // S1{} would be ill-formed, due to copy-list-initialization of S1::x from {}
42 static_assert( !std::default_initializable<S1> );