// PR gcov-profile/88045 // { dg-options "-fprofile-arcs -ftest-coverage -std=c++11" } // { dg-do run { target native } } #include #include #include struct Foo { size_t size() const { return n; }; const size_t n; explicit Foo(size_t a_n) : n{a_n} {}; }; template class C, typename Head, typename... Tail> struct make_with_tail { using type = C; }; template class C, typename T, typename Head, typename... Tail> struct make_with_tail_1 { using type = C; }; template struct head { using type = Head; }; template struct Tree { using root_type = typename head::type; using branch_type = typename make_with_tail::type; Tree(root_type a_root, std::vector a_branches) : root{std::move(a_root)}, branches{std::move(a_branches)} { } explicit Tree(root_type a_root) : root{std::move(a_root)}, branches{root.size()} { } root_type root; std::vector branches; }; template<> struct Tree<> { }; template size_t size(const Tree& tree) { return std::accumulate( tree.branches.begin(), tree.branches.end(), 0, [](const size_t& count, const typename make_with_tail::type& branch) { return count + size(branch); }); } template<> inline size_t size(const Tree<>& /* empty tree */) { return 1; } int main(int argc, char *argv[]) { size(Tree{Foo{4}, {Tree{Foo{2}, {Tree{Foo{205}}, Tree{Foo{261}}}}, Tree{Foo{4}, {Tree{Foo{875}}, Tree{Foo{492}}, Tree{Foo{398}}, Tree{Foo{302}}}}, Tree{Foo{6}, {Tree{Foo{111}}, Tree{Foo{436}}, Tree{Foo{388}}, Tree{Foo{879}}, Tree{Foo{783}}, Tree{Foo{735}}}}, Tree{Foo{3}, {Tree{Foo{791}}, Tree{Foo{ 5}}, Tree{Foo{841}}}}}}); return 0; } // { dg-final { run-gcov pr88045.C } }