Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/nontype-class70.C

raw
1 // PR c++/113800
2 // P2308R1 - Template parameter initialization
3 // { dg-do compile { target c++20 } }
4
5 struct S {
6 int a = 0;
7 int b = 42;
8 };
9
10 template <S t>
11 struct A {
12 static constexpr auto a = t.a;
13 static constexpr auto b = t.b;
14 };
15
16 static_assert(A<{}>::a == 0);
17 static_assert(A<{}>::b == 42);
18 static_assert(A<{.a = 3}>::a == 3);
19 static_assert(A<{.b = 4}>::b == 4);
20
21 template<S = {}>
22 struct D1 {};
23
24 template<S = {1, 2}>
25 struct D2 {};
26
27 template <S = {.b = 5}>
28 struct D3 {};
29
30 struct E {};
31
32 struct I {
33 constexpr I(E) {};
34 };
35
36 template<typename T, T>
37 struct W {};
38
39 void
40 g ()
41 {
42 D1<> d1;
43 D2<> d2;
44 D3<> d3;
45
46 W<I, {E{}}> w;
47 }