1 // { dg-do compile }
2 // { dg-options "-g" }
3 
4 typedef unsigned int uint32_t;
5 typedef unsigned long int uint64_t;
6 namespace mpl_ {
7     template< typename T, T N > struct integral_c {
8 	static const T value = N;
9     };
10 }
11 namespace mpl {
12     using namespace mpl_;
13 };
14 template <class T, T val> struct integral_constant : public mpl::integral_c<T, val> {
15     typedef integral_constant<bool,false> type;
16 };
17 template< typename T > struct is_lvalue_reference : public ::integral_constant<bool,false> {
18 };
19 template< typename T > struct is_rvalue_reference : public ::integral_constant<bool,false> {
20 };
21 namespace type_traits {
22     template <bool b1, bool b2, bool b3 = false, bool b4 = false, bool b5 = false, bool b6 = false, bool b7 = false> struct ice_or;
23     template <> struct ice_or<false, false, false, false, false, false, false> {
24 	static const bool value = false;
25     };
26 }
27 template <typename T> struct is_reference_impl {
28     static const bool value = (::type_traits::ice_or< ::is_lvalue_reference<T>::value, ::is_rvalue_reference<T>::value >::value)                  ;
29 };
30 template< typename T > struct is_reference : public ::integral_constant<bool,::is_reference_impl<T>::value> {
31 };
32 struct na {
33 };
34 namespace mpl {
35     template<       bool C     , typename T1     , typename T2     > struct if_c {
36 	typedef T2 type;
37     };
38     template<       typename T1 = na     , typename T2 = na     , typename T3 = na     > struct if_ {
39 	typedef if_c<           static_cast<bool>(T1::value)         , T2         , T3         > almost_type_;
40 	typedef typename almost_type_::type type;
41     };
42 }
43 namespace optional_detail {
44     template<class T> struct types_when_isnt_ref {
45 	typedef T & reference_type ;
46     }
47     ;
48     template<class T> struct types_when_is_ref {
49     }
50     ;
51     struct optional_tag {
52     }
53     ;
54     template<class T> class optional_base : public optional_tag {
55 	typedef types_when_isnt_ref<T> types_when_not_ref ;
56 	typedef types_when_is_ref<T> types_when_ref ;
57     protected :
58 	typedef typename is_reference<T>::type is_reference_predicate ;
59 	typedef typename mpl::if_<is_reference_predicate,types_when_ref,types_when_not_ref>::type types ;
60 	typedef typename types::reference_type reference_type ;
61     }
62     ;
63 }
64 template<class T> class optional : public optional_detail::optional_base<T> {
65     typedef optional_detail::optional_base<T> base ;
66 public :
67     typedef typename base::reference_type reference_type ;
68     reference_type operator *() {
69     }
70 };
71 namespace noncopyable_ {
72     class noncopyable   {
73     };
74 }
75 typedef noncopyable_::noncopyable noncopyable;
76 template<class T> class shared_ptr {
77 public:
78     T * operator-> () const     {
79     }
80 };
81 typedef uint64_t block_address;
82 class transaction_manager : noncopyable {
83 public:
84     typedef shared_ptr<transaction_manager> ptr;
85 };
86 template <typename ValueType>  class NoOpRefCounter {
87 };
88 struct uint64_traits {
89 };
90 namespace btree_detail {
91     class shadow_spine : private noncopyable {
92     public:
93 	shadow_spine(transaction_manager::ptr tm)     : tm_(tm) {
94 	}
95 	transaction_manager::ptr tm_;
96     };
97 }
98 template <unsigned Levels, typename ValueTraits>  class btree {
99 public:
100     typedef shared_ptr<btree<Levels, ValueTraits> > ptr;
101     typedef uint64_t key[Levels];
102     typedef typename ValueTraits::value_type value_type;
103     typedef optional<value_type> maybe_value;
104     btree(typename transaction_manager::ptr tm,         typename ValueTraits::ref_counter rc);
105     maybe_value lookup(key const &key) const;
106     void insert(key const &key, typename ValueTraits::value_type const &value);
107     template <typename ValueTraits2>   bool   insert_location(btree_detail::shadow_spine &spine,     block_address block,     uint64_t key,     int *index);
108     typename transaction_manager::ptr tm_;
109     block_address root_;
110     typename ValueTraits::ref_counter rc_;
111 };
112 template <unsigned Levels, typename ValueTraits> void btree<Levels, ValueTraits>:: insert(key const &key,        typename ValueTraits::value_type const &value) {
113     using namespace btree_detail;
114     block_address block = root_;
115     int index = 0;
116     shadow_spine spine(tm_);
117     for (unsigned level = 0;
118 	 level < Levels - 1;
119 	 ++level) {
120 	bool need_insert = insert_location<uint64_traits>(spine, block, key[level], &index);
121 	if (need_insert) {
122 	    btree<Levels - 1, ValueTraits> new_tree(tm_, rc_);
123 	}
124     }
125 }
126 struct device_details_disk {
127 }
128 __attribute__ ((packed));
129 struct device_details {
130 };
131 struct device_details_traits {
132     typedef device_details value_type;
133     typedef NoOpRefCounter<device_details> ref_counter;
134 };
135 typedef uint32_t thin_dev_t;
136 typedef btree<1, device_details_traits> detail_tree;
137 struct metadata {
138     typedef shared_ptr<metadata> ptr;
139     detail_tree::ptr details_;
140 };
141 class thin_pool;
142 class thin {
143     void set_snapshot_time(uint32_t time);
144     thin_dev_t dev_;
145     thin_pool *pool_;
146 };
147 class thin_pool {
148 public:
149     metadata::ptr md_;
150 };
151 void thin::set_snapshot_time(uint32_t time) {
152     uint64_t key[1] = {
153 	dev_ };
154     optional<device_details> mdetail = pool_->md_->details_->lookup(key);
155     pool_->md_->details_->insert(key, *mdetail);
156 }
157