Debian Codegraph @

gcc/testsuite/g++.dg/gcov/pr88045.C

raw
1 // PR gcov-profile/88045
2 // { dg-options "-fprofile-arcs -ftest-coverage -std=c++11" }
3 // { dg-do run { target native } }
4 /* { dg-skip-if "requires hosted libstdc++ for vector" { ! hostedlib } } */
5
6 #include <numeric>
7 #include <vector>
8 #include <stdlib.h>
9
10 struct Foo {
11 size_t size() const { return n; };
12 const size_t n;
13 explicit Foo(size_t a_n) : n{a_n} {};
14 };
15
16 template<template<typename...> class C, typename Head, typename... Tail>
17 struct make_with_tail {
18 using type = C<Tail...>;
19 };
20
21 template<template<typename...> class C, typename T, typename Head, typename... Tail>
22 struct make_with_tail_1 {
23 using type = C<T, Tail...>;
24 };
25
26 template<typename Head, typename... Tail>
27 struct head {
28 using type = Head;
29 };
30 template<typename... Ts>
31 struct Tree {
32 using root_type = typename head<Ts...>::type;
33 using branch_type = typename make_with_tail<Tree, Ts...>::type;
34 Tree(root_type a_root, std::vector<branch_type> a_branches) :
35 root{std::move(a_root)},
36 branches{std::move(a_branches)}
37 {
38 }
39
40 explicit Tree(root_type a_root) : root{std::move(a_root)}, branches{root.size()}
41 {
42 }
43
44 root_type root;
45 std::vector<branch_type> branches;
46 };
47
48 template<>
49 struct Tree<> {
50 };
51
52 template<typename... Axes>
53 size_t size(const Tree<Axes...>& tree)
54 {
55 return std::accumulate(
56 tree.branches.begin(),
57 tree.branches.end(),
58 0,
59 [](const size_t& count, const typename make_with_tail<Tree, Axes...>::type& branch) {
60 return count + size(branch);
61 });
62 }
63
64 template<>
65 inline size_t size(const Tree<>& /* empty tree */)
66 {
67 return 1;
68 }
69
70 int main(int argc, char *argv[])
71 {
72 size(Tree<Foo, Foo, Foo>{Foo{4}, {Tree<Foo, Foo>{Foo{2}, {Tree<Foo>{Foo{205}},
73 Tree<Foo>{Foo{261}}}},
74 Tree<Foo, Foo>{Foo{4}, {Tree<Foo>{Foo{875}},
75 Tree<Foo>{Foo{492}},
76 Tree<Foo>{Foo{398}},
77 Tree<Foo>{Foo{302}}}},
78 Tree<Foo, Foo>{Foo{6}, {Tree<Foo>{Foo{111}},
79 Tree<Foo>{Foo{436}},
80 Tree<Foo>{Foo{388}},
81 Tree<Foo>{Foo{879}},
82 Tree<Foo>{Foo{783}},
83 Tree<Foo>{Foo{735}}}},
84 Tree<Foo, Foo>{Foo{3}, {Tree<Foo>{Foo{791}},
85 Tree<Foo>{Foo{ 5}},
86 Tree<Foo>{Foo{841}}}}}});
87
88 return 0;
89 }
90
91 // { dg-final { run-gcov pr88045.C } }