| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-Wuninitialized -O2" } */ |
| 3 |
|
| 4 |
namespace std { |
| 5 |
typedef __SIZE_TYPE__ size_t; |
| 6 |
} |
| 7 |
extern "C++" { |
| 8 |
inline void* operator new(std::size_t, void* __p) throw() { |
| 9 |
return __p; |
| 10 |
} |
| 11 |
} |
| 12 |
namespace boost{ |
| 13 |
__extension__ typedef long long long_long_type; |
| 14 |
} |
| 15 |
namespace mpl_ { |
| 16 |
namespace aux { |
| 17 |
} |
| 18 |
} |
| 19 |
namespace boost { |
| 20 |
namespace mpl { |
| 21 |
using namespace mpl_; |
| 22 |
} |
| 23 |
} |
| 24 |
namespace mpl_ { |
| 25 |
struct integral_c_tag { |
| 26 |
}; |
| 27 |
template< int N > struct int_ { |
| 28 |
}; |
| 29 |
} |
| 30 |
namespace boost { |
| 31 |
namespace mpl { |
| 32 |
} |
| 33 |
} |
| 34 |
namespace mpl_ { |
| 35 |
template< bool C_ > struct bool_; |
| 36 |
typedef bool_<true> true_; |
| 37 |
typedef bool_<false> false_; |
| 38 |
} |
| 39 |
namespace mpl_ { |
| 40 |
template< bool C_ > struct bool_ { |
| 41 |
static const bool value = C_; |
| 42 |
}; |
| 43 |
template< typename T, T N > struct integral_c { |
| 44 |
static const T value = N; |
| 45 |
}; |
| 46 |
} |
| 47 |
namespace boost{ |
| 48 |
template <class T, T val> struct integral_constant : public mpl::integral_c<T, val> { |
| 49 |
}; |
| 50 |
template<> struct integral_constant<bool,false> : public mpl::false_ { |
| 51 |
typedef integral_constant<bool,false> type; |
| 52 |
}; |
| 53 |
template< typename T > struct is_lvalue_reference : ::boost::integral_constant<bool,false> { |
| 54 |
}; |
| 55 |
template< typename T > struct is_rvalue_reference : ::boost::integral_constant<bool,false> { |
| 56 |
}; |
| 57 |
namespace type_traits { |
| 58 |
template <bool b1, bool b2, bool b3 = false, bool b4 = false, bool b5 = false, bool b6 = false, bool b7 = false> struct ice_or; |
| 59 |
template <> struct ice_or<false, false, false, false, false, false, false> { |
| 60 |
static const bool value = false; |
| 61 |
}; |
| 62 |
} |
| 63 |
} |
| 64 |
namespace boost { |
| 65 |
namespace detail { |
| 66 |
template <typename T> struct is_reference_impl { |
| 67 |
static const bool value = (::boost::type_traits::ice_or< ::boost::is_lvalue_reference<T>::value, ::boost::is_rvalue_reference<T>::value >::value) ; |
| 68 |
}; |
| 69 |
} |
| 70 |
template< typename T > struct is_reference : ::boost::integral_constant<bool,::boost::detail::is_reference_impl<T>::value> { |
| 71 |
}; |
| 72 |
namespace detail { |
| 73 |
template< typename T > struct alignment_of_impl { |
| 74 |
static const std::size_t value = __alignof__(T); |
| 75 |
}; |
| 76 |
} |
| 77 |
template< typename T > struct alignment_of : ::boost::integral_constant<std::size_t,::boost::detail::alignment_of_impl<T>::value> { |
| 78 |
}; |
| 79 |
} |
| 80 |
namespace mpl_ { |
| 81 |
struct na { |
| 82 |
}; |
| 83 |
} |
| 84 |
namespace boost { |
| 85 |
namespace mpl { |
| 86 |
} |
| 87 |
} |
| 88 |
namespace boost { |
| 89 |
namespace mpl { |
| 90 |
template< bool C , typename T1 , typename T2 > struct if_c { |
| 91 |
typedef T1 type; |
| 92 |
}; |
| 93 |
template< typename T1 , typename T2 > struct if_c<false,T1,T2> { |
| 94 |
typedef T2 type; |
| 95 |
}; |
| 96 |
template< typename T1 = na , typename T2 = na , typename T3 = na > struct if_ { |
| 97 |
private: typedef if_c< static_cast<bool>(T1::value) , T2 , T3 > almost_type_; |
| 98 |
public: typedef typename almost_type_::type type; |
| 99 |
}; |
| 100 |
} |
| 101 |
} |
| 102 |
namespace boost{ |
| 103 |
template <bool x> struct STATIC_ASSERTION_FAILURE; |
| 104 |
template <> struct STATIC_ASSERTION_FAILURE<true> { |
| 105 |
}; |
| 106 |
template<int x> struct static_assert_test{ |
| 107 |
}; |
| 108 |
namespace detail { |
| 109 |
class alignment_dummy; |
| 110 |
typedef void (*function_ptr)(); |
| 111 |
typedef int (alignment_dummy::*member_ptr); |
| 112 |
typedef int (alignment_dummy::*member_function_ptr)(); |
| 113 |
template <bool found, std::size_t target, class TestType> struct lower_alignment_helper { |
| 114 |
typedef char type; |
| 115 |
enum { value = true }; |
| 116 |
}; |
| 117 |
template <std::size_t target, class TestType> struct lower_alignment_helper<false,target,TestType> { |
| 118 |
enum { value = (alignment_of<TestType>::value == target) }; |
| 119 |
typedef typename mpl::if_c<value, TestType, char>::type type; |
| 120 |
}; |
| 121 |
template <typename T> struct has_one_T { |
| 122 |
T data; |
| 123 |
}; |
| 124 |
template <std::size_t target> union lower_alignment { |
| 125 |
enum { found0 = false }; |
| 126 |
typename lower_alignment_helper< found0,target,char >::type t0; |
| 127 |
enum { found1 = lower_alignment_helper<found0,target,char >::value }; |
| 128 |
typename lower_alignment_helper< found1,target,short >::type t1; |
| 129 |
enum { found2 = lower_alignment_helper<found1,target,short >::value }; |
| 130 |
typename lower_alignment_helper< found2,target,int >::type t2; |
| 131 |
enum { found3 = lower_alignment_helper<found2,target,int >::value }; |
| 132 |
typename lower_alignment_helper< found3,target,long >::type t3; |
| 133 |
enum { found4 = lower_alignment_helper<found3,target,long >::value }; |
| 134 |
typename lower_alignment_helper< found4,target,::boost::long_long_type >::type t4; |
| 135 |
enum { found5 = lower_alignment_helper<found4,target,::boost::long_long_type >::value }; |
| 136 |
typename lower_alignment_helper< found5,target,float >::type t5; |
| 137 |
enum { found6 = lower_alignment_helper<found5,target,float >::value }; |
| 138 |
typename lower_alignment_helper< found6,target,double >::type t6; |
| 139 |
enum { found7 = lower_alignment_helper<found6,target,double >::value }; |
| 140 |
typename lower_alignment_helper< found7,target,long double >::type t7; |
| 141 |
enum { found8 = lower_alignment_helper<found7,target,long double >::value }; |
| 142 |
typename lower_alignment_helper< found8,target,void* >::type t8; |
| 143 |
enum { found9 = lower_alignment_helper<found8,target,void* >::value }; |
| 144 |
typename lower_alignment_helper< found9,target,function_ptr >::type t9; |
| 145 |
enum { found10 = lower_alignment_helper<found9,target,function_ptr >::value }; |
| 146 |
typename lower_alignment_helper< found10,target,member_ptr >::type t10; |
| 147 |
enum { found11 = lower_alignment_helper<found10,target,member_ptr >::value }; |
| 148 |
typename lower_alignment_helper< found11,target,member_function_ptr >::type t11; |
| 149 |
enum { found12 = lower_alignment_helper<found11,target,member_function_ptr >::value }; |
| 150 |
typename lower_alignment_helper< found12,target,boost::detail::has_one_T< char > >::type t12; |
| 151 |
enum { found13 = lower_alignment_helper<found12,target,boost::detail::has_one_T< char > >::value }; |
| 152 |
typename lower_alignment_helper< found13,target,boost::detail::has_one_T< short > >::type t13; |
| 153 |
enum { found14 = lower_alignment_helper<found13,target,boost::detail::has_one_T< short > >::value }; |
| 154 |
typename lower_alignment_helper< found14,target,boost::detail::has_one_T< int > >::type t14; |
| 155 |
enum { found15 = lower_alignment_helper<found14,target,boost::detail::has_one_T< int > >::value }; |
| 156 |
typename lower_alignment_helper< found15,target,boost::detail::has_one_T< long > >::type t15; |
| 157 |
enum { found16 = lower_alignment_helper<found15,target,boost::detail::has_one_T< long > >::value }; |
| 158 |
typename lower_alignment_helper< found16,target,boost::detail::has_one_T< ::boost::long_long_type > >::type t16; |
| 159 |
enum { found17 = lower_alignment_helper<found16,target,boost::detail::has_one_T< ::boost::long_long_type > >::value }; |
| 160 |
typename lower_alignment_helper< found17,target,boost::detail::has_one_T< float > >::type t17; |
| 161 |
enum { found18 = lower_alignment_helper<found17,target,boost::detail::has_one_T< float > >::value }; |
| 162 |
typename lower_alignment_helper< found18,target,boost::detail::has_one_T< double > >::type t18; |
| 163 |
enum { found19 = lower_alignment_helper<found18,target,boost::detail::has_one_T< double > >::value }; |
| 164 |
typename lower_alignment_helper< found19,target,boost::detail::has_one_T< long double > >::type t19; |
| 165 |
enum { found20 = lower_alignment_helper<found19,target,boost::detail::has_one_T< long double > >::value }; |
| 166 |
typename lower_alignment_helper< found20,target,boost::detail::has_one_T< void* > >::type t20; |
| 167 |
enum { found21 = lower_alignment_helper<found20,target,boost::detail::has_one_T< void* > >::value }; |
| 168 |
typename lower_alignment_helper< found21,target,boost::detail::has_one_T< function_ptr > >::type t21; |
| 169 |
enum { found22 = lower_alignment_helper<found21,target,boost::detail::has_one_T< function_ptr > >::value }; |
| 170 |
typename lower_alignment_helper< found22,target,boost::detail::has_one_T< member_ptr > >::type t22; |
| 171 |
enum { found23 = lower_alignment_helper<found22,target,boost::detail::has_one_T< member_ptr > >::value }; |
| 172 |
typename lower_alignment_helper< found23,target,boost::detail::has_one_T< member_function_ptr > >::type t23; |
| 173 |
enum { found24 = lower_alignment_helper<found23,target,boost::detail::has_one_T< member_function_ptr > >::value }; |
| 174 |
}; |
| 175 |
union max_align { |
| 176 |
}; |
| 177 |
template<std::size_t TAlign, std::size_t Align> struct is_aligned { |
| 178 |
static const bool value = (TAlign >= Align) & (TAlign % Align == 0) ; |
| 179 |
}; |
| 180 |
template <std::size_t Align> class type_with_alignment_imp { |
| 181 |
typedef ::boost::detail::lower_alignment<Align> t1; |
| 182 |
typedef typename mpl::if_c< ::boost::detail::is_aligned< ::boost::alignment_of<t1>::value,Align >::value , t1 , ::boost::detail::max_align >::type align_t; |
| 183 |
static const std::size_t found = alignment_of<align_t>::value; |
| 184 |
typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< ((found >= Align) == 0 ? false : true) >)> boost_static_assert_typedef_206; |
| 185 |
typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< ((found % Align == 0) == 0 ? false : true) >)> boost_static_assert_typedef_207; |
| 186 |
public: typedef align_t type; |
| 187 |
}; |
| 188 |
} |
| 189 |
template <std::size_t Align> class type_with_alignment : public ::boost::detail::type_with_alignment_imp<Align> { |
| 190 |
}; |
| 191 |
} |
| 192 |
namespace boost { |
| 193 |
namespace detail{ |
| 194 |
} |
| 195 |
template< typename T > struct remove_reference { |
| 196 |
}; |
| 197 |
} |
| 198 |
namespace boost { |
| 199 |
namespace mpl { |
| 200 |
namespace aux { |
| 201 |
template< typename T > struct nested_type_wknd : T::type { }; |
| 202 |
} |
| 203 |
} |
| 204 |
namespace mpl { |
| 205 |
namespace aux { |
| 206 |
template< long C_ > struct not_impl : bool_<!C_> { }; |
| 207 |
} |
| 208 |
template< typename T = na > struct not_ : aux::not_impl< ::boost::mpl::aux::nested_type_wknd<T>::value > { |
| 209 |
}; |
| 210 |
} |
| 211 |
namespace detail { |
| 212 |
template <typename T> struct make_reference_content { |
| 213 |
typedef T type; |
| 214 |
}; |
| 215 |
} |
| 216 |
namespace detail { |
| 217 |
struct none_helper{ |
| 218 |
}; |
| 219 |
} |
| 220 |
typedef int detail::none_helper::*none_t ; |
| 221 |
} |
| 222 |
namespace boost_optional_detail { |
| 223 |
template <class T, class Factory> inline void construct(Factory const& factory, void* address) { |
| 224 |
} |
| 225 |
} |
| 226 |
namespace boost { |
| 227 |
class in_place_factory_base ; |
| 228 |
class typed_in_place_factory_base ; |
| 229 |
namespace optional_detail { |
| 230 |
template <class T> class aligned_storage { |
| 231 |
union __attribute__((may_alias)) dummy_u { char data[ sizeof(T) ]; typename type_with_alignment< ::boost::alignment_of<T>::value >::type aligner_; } |
| 232 |
dummy_ ; |
| 233 |
public: void const* address() const { return &dummy_; } |
| 234 |
void * address() { return &dummy_; } |
| 235 |
} |
| 236 |
; |
| 237 |
template<class T> struct types_when_isnt_ref { |
| 238 |
typedef T const& reference_const_type ; |
| 239 |
typedef T & reference_type ; |
| 240 |
typedef T const* pointer_const_type ; |
| 241 |
typedef T * pointer_type ; |
| 242 |
typedef T const& argument_type ; |
| 243 |
} |
| 244 |
; |
| 245 |
template<class T> struct types_when_is_ref { |
| 246 |
typedef typename remove_reference<T>::type raw_type ; |
| 247 |
typedef raw_type& reference_const_type ; |
| 248 |
typedef raw_type& argument_type ; |
| 249 |
} |
| 250 |
; |
| 251 |
struct optional_tag { |
| 252 |
} |
| 253 |
; |
| 254 |
template<class T> struct optional_base : public optional_tag { |
| 255 |
typedef typename ::boost::detail::make_reference_content<T>::type internal_type ; |
| 256 |
typedef aligned_storage<internal_type> storage_type ; |
| 257 |
typedef types_when_isnt_ref<T> types_when_not_ref ; |
| 258 |
typedef types_when_is_ref<T> types_when_ref ; |
| 259 |
typedef optional_base<T> this_type ; |
| 260 |
typedef T value_type ; |
| 261 |
typedef mpl::true_ is_reference_tag ; |
| 262 |
typedef mpl::false_ is_not_reference_tag ; |
| 263 |
typedef typename is_reference<T>::type is_reference_predicate ; |
| 264 |
typedef typename mpl::if_<is_reference_predicate,types_when_ref,types_when_not_ref>::type types ; |
| 265 |
typedef bool (this_type::*unspecified_bool_type)() const; |
| 266 |
typedef typename types::reference_type reference_type ; |
| 267 |
typedef typename types::reference_const_type reference_const_type ; |
| 268 |
typedef typename types::pointer_type pointer_type ; |
| 269 |
typedef typename types::pointer_const_type pointer_const_type ; |
| 270 |
typedef typename types::argument_type argument_type ; |
| 271 |
optional_base() : m_initialized(false) {} |
| 272 |
optional_base ( argument_type val ) : m_initialized(false) { construct(val); } |
| 273 |
optional_base ( bool cond, argument_type val ) : m_initialized(false) { if ( cond ) construct(val); } |
| 274 |
optional_base ( optional_base const& rhs ) : m_initialized(false) { if ( rhs.is_initialized() ) construct(rhs.get_impl()); } |
| 275 |
pointer_const_type get_ptr() const { return m_initialized ? get_ptr_impl() : 0 ; } |
| 276 |
pointer_type get_ptr() { return m_initialized ? get_ptr_impl() : 0 ; } |
| 277 |
bool is_initialized() const { return m_initialized ; } |
| 278 |
void construct ( argument_type val ) { new (m_storage.address()) internal_type(val) ; m_initialized = true ; } |
| 279 |
template<class Expr> void construct ( Expr const& factory, in_place_factory_base const* ) { typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< ((::boost::mpl::not_<is_reference_predicate>::value) == 0 ? false : true) >)> boost_static_assert_typedef_355 ; boost_optional_detail::construct<value_type>(factory, m_storage.address()); m_initialized = true ; } |
| 280 |
template<class Expr> void construct ( Expr const& factory, typed_in_place_factory_base const* ) { typedef ::boost::static_assert_test< sizeof(::boost::STATIC_ASSERTION_FAILURE< ((::boost::mpl::not_<is_reference_predicate>::value) == 0 ? false : true) >)> boost_static_assert_typedef_364 ; factory.apply(m_storage.address()) ; m_initialized = true ; } |
| 281 |
void destroy() { } |
| 282 |
unspecified_bool_type safe_bool() const { return m_initialized ? &this_type::is_initialized : 0 ; } |
| 283 |
reference_const_type get_impl() const { return dereference(get_object(), is_reference_predicate() ) ; } |
| 284 |
reference_type get_impl() { return dereference(get_object(), is_reference_predicate() ) ; } |
| 285 |
pointer_const_type get_ptr_impl() const { return cast_ptr(get_object(), is_reference_predicate() ) ; } |
| 286 |
pointer_type get_ptr_impl() { return cast_ptr(get_object(), is_reference_predicate() ) ; } |
| 287 |
internal_type const* get_object() const { union { void const* ap_pvoid; internal_type const* as_ptype; } caster = { m_storage.address() }; return caster.as_ptype; } |
| 288 |
internal_type * get_object() { union { void* ap_pvoid; internal_type* as_ptype; } caster = { m_storage.address() }; return caster.as_ptype; } |
| 289 |
reference_const_type dereference( internal_type const* p, is_not_reference_tag ) const { return *p ; } |
| 290 |
pointer_type cast_ptr( internal_type * p, is_reference_tag ) { return &p->get() ; } |
| 291 |
bool m_initialized ; |
| 292 |
storage_type m_storage ; |
| 293 |
} |
| 294 |
; |
| 295 |
} |
| 296 |
template<class T> class optional : public optional_detail::optional_base<T> { |
| 297 |
typedef optional_detail::optional_base<T> base ; |
| 298 |
public : typedef optional<T> this_type ; |
| 299 |
typedef typename base::reference_const_type reference_const_type ; |
| 300 |
reference_const_type get() const { |
| 301 |
(static_cast<void> (0)) ; |
| 302 |
return this->get_impl(); |
| 303 |
} |
| 304 |
reference_const_type operator *() const { |
| 305 |
return this->get() ; |
| 306 |
} |
| 307 |
bool operator!() const { |
| 308 |
return !this->is_initialized() ; |
| 309 |
} |
| 310 |
} |
| 311 |
; |
| 312 |
template<class OptionalPointee> inline bool equal_pointees2 ( OptionalPointee const& x, OptionalPointee const& y ) { |
| 313 |
return (!x) != (!y) ? false : ( !x ? true : (*x) == (*y) ) ; |
| 314 |
} |
| 315 |
template<class T> inline bool operator == ( optional<T> const& x, optional<T> const& y ) { |
| 316 |
return equal_pointees2(x,y); |
| 317 |
} |
| 318 |
template<class T> inline bool operator != ( optional<T> const& x, optional<T> const& y ) { |
| 319 |
return !( x == y ) ; |
| 320 |
} |
| 321 |
} |
| 322 |
::boost::optional< std::size_t > getitem(); |
| 323 |
class BAR { |
| 324 |
public: int FOO(); |
| 325 |
private: ::boost::optional< std::size_t > m_aHoveredItem; |
| 326 |
}; |
| 327 |
int BAR::FOO() { |
| 328 |
::boost::optional< std::size_t > aOldItem(getitem()); |
| 329 |
::boost::optional< std::size_t > aNewItem(m_aHoveredItem); |
| 330 |
if (aOldItem != aNewItem) return 1; |
| 331 |
return 0; |
| 332 |
} |
| 333 |
|