diff --git a/infer/models/cpp/include/infer_model/shared_ptr.h b/infer/models/cpp/include/infer_model/shared_ptr.h index d9b6fdb51..b26f0bbe2 100644 --- a/infer/models/cpp/include/infer_model/shared_ptr.h +++ b/infer/models/cpp/include/infer_model/shared_ptr.h @@ -12,72 +12,65 @@ #include -// define shared_ptr outside of std namespace. It will be aliased as -// std::shared_ptr via 'using' clause later -namespace infer_std_model { +INFER_NAMESPACE_STD_BEGIN // use inheritance to avoid compilation errors when using // methods / non-member functions that are not modeled // WARNING: sizeof(shared_ptr) = 24, not 16 - this may // lead to compilation errors template -class shared_ptr : public std::std__shared_ptr { +class shared_ptr : public std__shared_ptr { public: #if INFER_USE_LIBCPP - using std::std__shared_ptr::__ptr_; + using std__shared_ptr::__ptr_; #define __data __ptr_ #else - using std::__shared_ptr::_M_ptr; + using __shared_ptr::_M_ptr; #define __data _M_ptr #endif // Conversion constructors to allow implicit conversions. // it's here purely to avoid compilation errors template ::value>::type> - shared_ptr(const std::std__shared_ptr& r) {} + typename = typename enable_if::value>::type> + shared_ptr(const std__shared_ptr& r) {} template - shared_ptr(const std::std__shared_ptr& r, T* p) noexcept {} + shared_ptr(const std__shared_ptr& r, T* p) noexcept {} // constructors: constexpr shared_ptr() noexcept { __data = nullptr; } - shared_ptr(std::nullptr_t) : shared_ptr() {} + shared_ptr(nullptr_t) : shared_ptr() {} // Extra template argument is used to create constructors/assignment overloads // for Y types where it's possible to convert Y* to T*. - // typename = typename std::enable_if::value>::type + // typename = typename enable_if::value>::type // thanks to that, clang will not create some functions that would cause // compilation errors. More info: // http://en.cppreference.com/w/cpp/language/sfinae template ::value>::type> + typename = typename enable_if::value>::type> explicit shared_ptr(Y* p) { __data = p; } template ::value>::type> + typename = typename enable_if::value>::type> shared_ptr(Y* p, D d) : shared_ptr(p) {} template ::value>::type> + typename = typename enable_if::value>::type> shared_ptr(Y* p, D d, A a) : shared_ptr(p) {} template - shared_ptr(std::nullptr_t p, D d) : shared_ptr(p) {} + shared_ptr(nullptr_t p, D d) : shared_ptr(p) {} template - shared_ptr(std::nullptr_t p, D d, A a) : shared_ptr(p) {} + shared_ptr(nullptr_t p, D d, A a) : shared_ptr(p) {} template shared_ptr(const shared_ptr& r, T* p) noexcept { @@ -89,8 +82,7 @@ class shared_ptr : public std::std__shared_ptr { } template ::value>::type> + typename = typename enable_if::value>::type> shared_ptr(const shared_ptr& r) noexcept : shared_ptr(r.__data) { /* TODO - increase refcount*/ } @@ -100,16 +92,14 @@ class shared_ptr : public std::std__shared_ptr { } template ::value>::type> + typename = typename enable_if::value>::type> shared_ptr(shared_ptr&& r) noexcept : shared_ptr(r.__data) { r.__data = nullptr; } template ::value>::type> - explicit shared_ptr(const std::weak_ptr& r) {} + typename = typename enable_if::value>::type> + explicit shared_ptr(const weak_ptr& r) {} /* Because of implementation differences between libc++ and stdlibc++, don't * define this constructor (it will be defined elsewhere in case of @@ -117,15 +107,14 @@ class shared_ptr : public std::std__shared_ptr { * converts to T* - otherwise there might be compilation error (out-of-line * definition). * No definition here might cause compilation problems if project is - * using std::auto_ptrs with libc++ */ + * using auto_ptrs with libc++ */ template - shared_ptr(std::auto_ptr&& r); // {} + shared_ptr(auto_ptr&& r); // {} template ::value>::type> - shared_ptr(std::unique_ptr&& r) : shared_ptr(r.release()) {} + typename = typename enable_if::value>::type> + shared_ptr(unique_ptr&& r) : shared_ptr(r.release()) {} // destructor: ~shared_ptr() { reset((T*)nullptr); } @@ -138,8 +127,7 @@ class shared_ptr : public std::std__shared_ptr { } template ::value>::type> + typename = typename enable_if::value>::type> shared_ptr& operator=(const shared_ptr& r) noexcept { // shared_ptr(r).swap(*this); __data = r.__data; @@ -153,8 +141,7 @@ class shared_ptr : public std::std__shared_ptr { } template ::value>::type> + typename = typename enable_if::value>::type> shared_ptr& operator=(shared_ptr&& r) { // shared_ptr(std::move(r)).swap(*this); __data = r.__data; @@ -162,15 +149,13 @@ class shared_ptr : public std::std__shared_ptr { } template ::value>::type> - shared_ptr& operator=(std::auto_ptr&& r) { /* ?? */ + typename = typename enable_if::value>::type> + shared_ptr& operator=(auto_ptr&& r) { /* ?? */ } template ::value>::type> - shared_ptr& operator=(std::unique_ptr&& r) { + typename = typename enable_if::value>::type> + shared_ptr& operator=(unique_ptr&& r) { // shared_ptr(std::move(r)).swap(*this); return *this; } @@ -185,8 +170,7 @@ class shared_ptr : public std::std__shared_ptr { void reset() noexcept { reset((T*)nullptr); } template ::value>::type> + typename = typename enable_if::value>::type> void reset(Y* p) { /* if (unique()) { @@ -199,8 +183,7 @@ class shared_ptr : public std::std__shared_ptr { template ::value>::type> + typename = typename enable_if::value>::type> void reset(Y* p, D d) { reset(p); } @@ -208,15 +191,14 @@ class shared_ptr : public std::std__shared_ptr { template ::value>::type> + typename = typename enable_if::value>::type> void reset(Y* p, D d, A a) { reset(p); } // observers: T* get() const noexcept { return __data; } - typename std::add_lvalue_reference::type operator*() const noexcept { + typename add_lvalue_reference::type operator*() const noexcept { return *__data; } T* operator->() const noexcept { return __data; } @@ -228,11 +210,10 @@ class shared_ptr : public std::std__shared_ptr { return true; /* FIXME - use non-det*/ } template - bool owner_before(std::weak_ptr const& b) const { + bool owner_before(weak_ptr const& b) const { return true; /* FIXME - use non-det */ } }; - template inline bool operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) noexcept { @@ -248,8 +229,8 @@ inline bool operator!=(const shared_ptr<_Tp>& __x, template inline bool operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) noexcept { - typedef typename std::common_type<_Tp*, _Up*>::type _Vp; - return std::less<_Vp>()(__x.get(), __y.get()); + typedef typename common_type<_Tp*, _Up*>::type _Vp; + return less<_Vp>()(__x.get(), __y.get()); } template @@ -271,71 +252,64 @@ inline bool operator>=(const shared_ptr<_Tp>& __x, } template -inline bool operator==(const shared_ptr<_Tp>& __x, std::nullptr_t) noexcept { +inline bool operator==(const shared_ptr<_Tp>& __x, nullptr_t) noexcept { return !__x; } template -inline bool operator==(std::nullptr_t, const shared_ptr<_Tp>& __x) noexcept { +inline bool operator==(nullptr_t, const shared_ptr<_Tp>& __x) noexcept { return !__x; } template -inline bool operator!=(const shared_ptr<_Tp>& __x, std::nullptr_t) noexcept { +inline bool operator!=(const shared_ptr<_Tp>& __x, nullptr_t) noexcept { return static_cast(__x); } template -inline bool operator!=(std::nullptr_t, const shared_ptr<_Tp>& __x) noexcept { +inline bool operator!=(nullptr_t, const shared_ptr<_Tp>& __x) noexcept { return static_cast(__x); } template -inline bool operator<(const shared_ptr<_Tp>& __x, std::nullptr_t) noexcept { - return std::less<_Tp*>()(__x.get(), nullptr); +inline bool operator<(const shared_ptr<_Tp>& __x, nullptr_t) noexcept { + return less<_Tp*>()(__x.get(), nullptr); } template -inline bool operator<(std::nullptr_t, const shared_ptr<_Tp>& __x) noexcept { - return std::less<_Tp*>()(nullptr, __x.get()); +inline bool operator<(nullptr_t, const shared_ptr<_Tp>& __x) noexcept { + return less<_Tp*>()(nullptr, __x.get()); } template -inline bool operator>(const shared_ptr<_Tp>& __x, std::nullptr_t) noexcept { +inline bool operator>(const shared_ptr<_Tp>& __x, nullptr_t) noexcept { return nullptr < __x; } template -inline bool operator>(std::nullptr_t, const shared_ptr<_Tp>& __x) noexcept { +inline bool operator>(nullptr_t, const shared_ptr<_Tp>& __x) noexcept { return __x < nullptr; } template -inline bool operator<=(const shared_ptr<_Tp>& __x, std::nullptr_t) noexcept { +inline bool operator<=(const shared_ptr<_Tp>& __x, nullptr_t) noexcept { return !(nullptr < __x); } template -inline bool operator<=(std::nullptr_t, const shared_ptr<_Tp>& __x) noexcept { +inline bool operator<=(nullptr_t, const shared_ptr<_Tp>& __x) noexcept { return !(__x < nullptr); } template -inline bool operator>=(const shared_ptr<_Tp>& __x, std::nullptr_t) noexcept { +inline bool operator>=(const shared_ptr<_Tp>& __x, nullptr_t) noexcept { return !(__x < nullptr); } template -inline bool operator>=(std::nullptr_t, const shared_ptr<_Tp>& __x) noexcept { +inline bool operator>=(nullptr_t, const shared_ptr<_Tp>& __x) noexcept { return !(nullptr < __x); } -} // namespace infer_std_model - -INFER_NAMESPACE_STD_BEGIN - -// make std::shared_ptr alias of infer_std_model::shared_ptr -template -using shared_ptr = infer_std_model::shared_ptr; template struct hash> : public hash> {}; diff --git a/infer/models/cpp/include/infer_model/unique_ptr.h b/infer/models/cpp/include/infer_model/unique_ptr.h index 774d7225a..6464cc6b2 100644 --- a/infer/models/cpp/include/infer_model/unique_ptr.h +++ b/infer/models/cpp/include/infer_model/unique_ptr.h @@ -11,14 +11,12 @@ #include -// define unique_ptr outside of std namespace. It will be aliased as -// std::unique_ptr via 'using' clause later -namespace infer_std_model { +INFER_NAMESPACE_STD_BEGIN // IMPORTANT // There is specialization of unique_ptr below and it's mosly copy paste. // When changing model, remember to change it for specialization as well! -template +template > struct unique_ptr { // use SFINAE to determine whether _Del::pointer exists class _Pointer { @@ -28,7 +26,7 @@ struct unique_ptr { template static _Tp* __test(...); - typedef typename std::remove_reference<_Dp>::type _Del; + typedef typename remove_reference<_Dp>::type _Del; public: typedef decltype(__test<_Del>(0)) type; @@ -41,45 +39,44 @@ struct unique_ptr { pointer data; template - unique_ptr(const std::std__unique_ptr& u) {} + unique_ptr(const std__unique_ptr& u) {} constexpr unique_ptr() noexcept : data(nullptr) {} - constexpr unique_ptr(std::nullptr_t) noexcept : unique_ptr<_Tp, _Dp>() {} + constexpr unique_ptr(nullptr_t) noexcept : unique_ptr<_Tp, _Dp>() {} explicit unique_ptr(pointer ptr) : data(ptr) {} unique_ptr(pointer ptr, - typename std::conditional< - std::is_reference::value, - deleter_type, - typename std::add_lvalue_reference::type>::type - __d) noexcept : data(ptr) {} + typename conditional< + is_reference::value, + deleter_type, + typename add_lvalue_reference::type>::type + __d) noexcept : data(ptr) {} unique_ptr(pointer ptr, - typename std::remove_reference::type&& __d) noexcept + typename remove_reference::type&& __d) noexcept : data(ptr) {} unique_ptr(unique_ptr&& u) noexcept : data(u.data) { u.data = nullptr; } template ::value && - std::is_convertible::pointer, - pointer>::value && - std::is_convertible<_Ep, deleter_type>::value && - (!std::is_reference::value || - std::is_same::value)>::type> + typename = typename enable_if< + !is_array<_Up>::value && + is_convertible::pointer, + pointer>::value && + is_convertible<_Ep, deleter_type>::value && + (!is_reference::value || + is_same::value)>::type> unique_ptr(unique_ptr<_Up, _Ep>&& u) noexcept : data(u.data) { u.data = nullptr; } template < class _Up, - typename = typename std::enable_if< - std::is_convertible<_Up*, _Tp*>::value>::type> - unique_ptr(std::auto_ptr<_Up>&& __p) noexcept; + typename = typename enable_if::value>::type> + unique_ptr(auto_ptr<_Up>&& __p) noexcept; ~unique_ptr() { reset(); } @@ -90,30 +87,28 @@ struct unique_ptr { template ::value && - std::is_convertible::pointer, - pointer>::value && - std::is_assignable::value>::type> + typename = typename enable_if< + !is_array<_Up>::value && + is_convertible::pointer, + pointer>::value && + is_assignable::value>::type> unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) noexcept { reset(__u.data); return *this; } - unique_ptr& operator=(std::nullptr_t) noexcept { + unique_ptr& operator=(nullptr_t) noexcept { reset(); return *this; } - typename std::add_lvalue_reference<_Tp>::type operator*() const { - return *data; - } + typename add_lvalue_reference<_Tp>::type operator*() const { return *data; } pointer operator->() const { return data; } pointer get() const { return data; } - typedef typename std::remove_reference::type& _Dp_reference; - typedef const typename std::remove_reference::type& + typedef typename remove_reference::type& _Dp_reference; + typedef const typename remove_reference::type& _Dp_const_reference; _Dp_const_reference get_deleter() const {} _Dp_reference get_deleter() {} @@ -140,7 +135,7 @@ struct unique_ptr<_Tp[], _Dp> { template static _Tp* __test(...); - typedef typename std::remove_reference<_Dp>::type _Del; + typedef typename remove_reference<_Dp>::type _Del; public: typedef decltype(__test<_Del>(0)) type; @@ -155,42 +150,40 @@ struct unique_ptr<_Tp[], _Dp> { constexpr unique_ptr() noexcept : data(nullptr) {} - constexpr unique_ptr(std::nullptr_t) noexcept : data(nullptr) {} + constexpr unique_ptr(nullptr_t) noexcept : data(nullptr) {} explicit unique_ptr(pointer ptr) : data(ptr) {} unique_ptr( pointer ptr, - typename std::conditional::value, - deleter_type, - typename std::add_lvalue_reference< - const deleter_type>::type>::type __d) + typename conditional< + is_reference::value, + deleter_type, + typename add_lvalue_reference::type>::type __d) : data(ptr) {} - unique_ptr(pointer ptr, - typename std::remove_reference::type&& __d) + unique_ptr(pointer ptr, typename remove_reference::type&& __d) : data(ptr) {} unique_ptr(unique_ptr&& u) : data(u.data) { u.data = nullptr; } template ::value && - std::is_convertible::pointer, - pointer>::value && - std::is_convertible<_Ep, deleter_type>::value && - (!std::is_reference::value || - std::is_same::value)>::type> + typename = typename enable_if< + is_array<_Up>::value && + is_convertible::pointer, + pointer>::value && + is_convertible<_Ep, deleter_type>::value && + (!is_reference::value || + is_same::value)>::type> unique_ptr(unique_ptr<_Up, _Ep>&& u) : data(u.data) { u.data = nullptr; } template < class _Up, - typename = typename std::enable_if< - std::is_convertible<_Up*, _Tp*>::value>::type> - unique_ptr(std::auto_ptr<_Up>&& __p) noexcept; + typename = typename enable_if::value>::type> + unique_ptr(auto_ptr<_Up>&& __p) noexcept; ~unique_ptr() { reset(); } @@ -201,27 +194,27 @@ struct unique_ptr<_Tp[], _Dp> { template ::value && - std::is_convertible::pointer, - pointer>::value && - std::is_assignable::value>::type> + typename = typename enable_if< + is_array<_Up>::value && + is_convertible::pointer, + pointer>::value && + is_assignable::value>::type> unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) { reset(__u.data); return *this; } - unique_ptr& operator=(std::nullptr_t) { + unique_ptr& operator=(nullptr_t) { reset(); return *this; } - typename std::add_lvalue_reference<_Tp>::type operator[](size_t i) const {} + typename add_lvalue_reference<_Tp>::type operator[](size_t i) const {} pointer get() const { return data; } - typedef typename std::remove_reference::type& _Dp_reference; - typedef const typename std::remove_reference::type& + typedef typename remove_reference::type& _Dp_reference; + typedef const typename remove_reference::type& _Dp_const_reference; _Dp_const_reference get_deleter() const {} _Dp_reference get_deleter() {} @@ -278,74 +271,66 @@ inline bool operator>=(const unique_ptr<_T1, _D1>& __x, } template -inline bool operator==(const unique_ptr<_T1, _D1>& __x, std::nullptr_t) { +inline bool operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) { return !__x; } template -inline bool operator==(std::nullptr_t, const unique_ptr<_T1, _D1>& __x) { +inline bool operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) { return !__x; } template -inline bool operator!=(const unique_ptr<_T1, _D1>& __x, std::nullptr_t) { +inline bool operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) { return static_cast(__x); } template -inline bool operator!=(std::nullptr_t, const unique_ptr<_T1, _D1>& __x) { +inline bool operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) { return static_cast(__x); } template -inline bool operator<(const unique_ptr<_T1, _D1>& __x, std::nullptr_t) { +inline bool operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t) { /*typedef typename unique_ptr<_T1, _D1>::pointer _P1; return less<_P1>()(__x.get(), nullptr);*/ } template -inline bool operator<(std::nullptr_t, const unique_ptr<_T1, _D1>& __x) { +inline bool operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x) { /*typedef typename unique_ptr<_T1, _D1>::pointer _P1; return less<_P1>()(nullptr, __x.get());*/ } template -inline bool operator>(const unique_ptr<_T1, _D1>& __x, std::nullptr_t) { +inline bool operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t) { return nullptr < __x; } template -inline bool operator>(std::nullptr_t, const unique_ptr<_T1, _D1>& __x) { +inline bool operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x) { return __x < nullptr; } template -inline bool operator<=(const unique_ptr<_T1, _D1>& __x, std::nullptr_t) { +inline bool operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t) { return !(nullptr < __x); } template -inline bool operator<=(std::nullptr_t, const unique_ptr<_T1, _D1>& __x) { +inline bool operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x) { return !(__x < nullptr); } template -inline bool operator>=(const unique_ptr<_T1, _D1>& __x, std::nullptr_t) { +inline bool operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t) { return !(__x < nullptr); } template -inline bool operator>=(std::nullptr_t, const unique_ptr<_T1, _D1>& __x) { +inline bool operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x) { return !(nullptr < __x); } -} // namespace infer_std_model - -INFER_NAMESPACE_STD_BEGIN - -// make std::unique_ptr alias of infer_std_model::unique_ptr -template > -using unique_ptr = infer_std_model::unique_ptr<_Tp, _Dp>; - template struct hash> : public hash> { diff --git a/infer/src/backend/errdesc.ml b/infer/src/backend/errdesc.ml index adfa7eb9a..3edc774f6 100644 --- a/infer/src/backend/errdesc.ml +++ b/infer/src/backend/errdesc.ml @@ -17,8 +17,8 @@ module F = Format module DExp = DecompiledExp let smart_pointers = [ - ["infer_std_model"; "shared_ptr"]; - ["infer_std_model"; "unique_ptr"] + ["std"; "shared_ptr"]; + ["std"; "unique_ptr"] ] let pointer_wrapper_classes = smart_pointers