annotate gcc/testsuite/g++.dg/cpp0x/variadic-alias2.C @ 19:2b5abeee2509 default tip

update gcc11
author anatofuz
date Mon, 25 May 2020 07:50:57 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
1 // PR c++/91966
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
2 // { dg-do compile { target c++11 } }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
3
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
4 // Reduced to this include-free example. Further reduction is hard: Either
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
5 // the bug(?) disappears, or the program becomes meaningless.
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
6
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
7 template<class...>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
8 struct list {};
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
9
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
10 struct nil;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
11
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
12 ////////////////////////////////////////////////////////////////////////////////
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
13
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
14 template<int n>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
15 struct number {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
16 constexpr /*implicit*/ operator int() const { return n; }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
17 using type = number<n>;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
18 };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
19
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
20 using false_ = number<0>;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
21 using true_ = number<1>;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
22
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
23 static_assert(!false_{}, "");
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
24 static_assert(true_{}, "");
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
25
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
26 template<int... ns> using numbers = list<number<ns>...>;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
27
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
28 ////////////////////////////////////////////////////////////////////////////////
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
29
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
30 template<class lhs, class rhs>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
31 struct less_impl;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
32
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
33 template<int lhs, int rhs>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
34 struct less_impl<number<lhs>, number<rhs>>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
35 : number<(lhs < rhs)> {};
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
36
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
37 template<class lhs, class rhs> using less = typename less_impl<lhs, rhs>::type;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
38
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
39 ////////////////////////////////////////////////////////////////////////////////
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
40
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
41 template<class v0, class... vs>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
42 struct sum_impl {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
43 static_assert(sizeof...(vs) == 0, "see specialization");
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
44 using type = v0;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
45 };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
46
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
47 template<int v0, int v1, class... vs>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
48 struct sum_impl<number<v0>, number<v1>, vs...>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
49 : sum_impl<number<v0 + v1>, vs...> {};
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
50
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
51 template<class... nums> using sum = typename sum_impl<nums...>::type;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
52
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
53 ////////////////////////////////////////////////////////////////////////////////
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
54
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
55 template<class num>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
56 struct conditional_impl {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
57 static_assert(num{}, "see specialization");
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
58
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
59 template<class T, class F>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
60 using type = T;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
61 };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
62
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
63 template<>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
64 struct conditional_impl<false_> {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
65 template<class T, class F>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
66 using type = F;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
67 };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
68
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
69 template<class num, class T, class F>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
70 using conditional = typename conditional_impl<num>::template type<T, F>;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
71
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
72 ////////////////////////////////////////////////////////////////////////////////
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
73
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
74 template<class seq>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
75 struct min_filter_impl;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
76
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
77 template<class... nums>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
78 struct min_filter_impl<list<nums...>> {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
79 template<class num>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
80 using count_better_mins = sum<less<nums, num>...>;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
81
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
82 using type = list<conditional<count_better_mins<nums>, nil, nums>...>;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
83
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
84 //using debug = list<conditional<count_better_mins<nums>, nil, void>...>;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
85
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
86 // error: expansion pattern 'conditional<typename sum_impl<less<nums, nums>...>::type, nil, void>' contains no parameter packs
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
87
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
88 };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
89
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
90 template<class seq> using min_filter = typename min_filter_impl<seq>::type;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
91
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
92 ////////////////////////////////////////////////////////////////////////////////
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
93
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
94 void test_min_filter() {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
95 using computed = min_filter<numbers<2, 7, 2>>;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
96 using expected = list<number<2>, nil, number<2>>;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
97 (void)(computed{} = expected{});// compiles for identical types
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
98
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
99 // error: no match for 'operator=' (operand types are 'computed' {aka 'list<number<2>, number<7>, number<2> >'} and 'expected' {aka 'list<number<2>, nil, number<2> >'})
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
100
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
101 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
102
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
103 int main() {}