Debian Codegraph @

gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const25.C

raw
1 // PR c++/94772
2 // { dg-do compile { target c++14 } }
3
4 template<int>
5 struct base
6 {
7 int y{};
8
9 base() = default;
10
11 constexpr base(int a) : base{}
12 { y = a; }
13 };
14
15 struct foo : base<1>, base<2>
16 {
17 int x{};
18
19 constexpr foo() : base<2>{}
20 {
21 ++x; --x;
22 ++base<1>::y;
23 ++base<2>::y;
24 }
25
26 constexpr foo(int a) : base<2>{a}
27 {
28 x = -base<2>::y;
29 ++base<1>::y;
30 ++base<2>::y;
31 }
32
33 constexpr foo(int a, int b) : foo{a}
34 {
35 x += a + b;
36 ++base<1>::y;
37 ++base<2>::y;
38 }
39
40 constexpr foo(int a, int b, int c) : base<1>{a}
41 {
42 x += a + b + c;
43 ++base<1>::y;
44 ++base<2>::y;
45 }
46 };
47
48 #define SA(X) static_assert(X, #X)
49
50 int main()
51 {
52 constexpr foo bar1{1, 2};
53 SA( bar1.x == 2 );
54 SA( bar1.base<1>::y == 2 );
55 SA( bar1.base<2>::y == 3 );
56
57 constexpr foo bar2{1, 2, 3};
58 SA( bar2.x == 6 );
59 SA( bar2.base<1>::y == 2 );
60 SA( bar2.base<2>::y == 1 );
61
62 constexpr foo bar3{};
63 SA( bar3.x == 0 );
64 SA( bar3.base<1>::y == 1 );
65 SA( bar3.base<2>::y == 1 );
66 }