blob: f6b9d1e9aa53074551a4fb4562eace627a336a0e [file] [log] [blame]
// RUN: %check_clang_tidy %s zircon-fbl-memory %t -- -- -isystem %S/Inputs/zircon
#include <fbl/unique_ptr.h>
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: including fbl/unique_ptr.h is deprecated
// CHECK-FIXES-NOT: #include <fbl/unique_ptr.h>
// CHECK-FIXES: #include <memory>
namespace fbl {
template <typename T>
class unique_ptr {
public:
explicit unique_ptr(T* t) { }
};
template <typename T>
class unique_ptr<T[]> {
public:
explicit unique_ptr(T* t) { }
};
template <typename T>
struct unique_type {
using single = unique_ptr<T>;
};
template <typename T>
struct unique_type<T[]> {
using incomplete_array = unique_ptr<T[]>;
};
template <typename T> struct remove_extent { using type = T; };
template <typename T> struct remove_extent<T[]> { using type = T; };
// Constructs a new object and assigns it to a unique_ptr.
template <typename T, typename... Args>
typename unique_type<T>::single make_unique(Args &&... args) {
return unique_ptr<T>(new T());
}
template <typename T, typename... Args>
typename unique_type<T>::incomplete_array make_unique(int size) {
using single_type = typename remove_extent<T>::type;
return unique_ptr<single_type[]>(new single_type[size]());
}
} // namespace fbl
namespace std {
template <class T>
struct default_delete {};
template <class T> struct default_delete<T[]> {};
template <class T, class D = default_delete<T> > class unique_ptr {
public:
explicit unique_ptr(T *t) {}
};
template <class T, class D> class unique_ptr<T[], D> {
public:
explicit unique_ptr(T *t) {}
};
template <class _Tp> struct __unique_if {
typedef unique_ptr<_Tp> __unique_single;
};
template <class _Tp> struct __unique_if<_Tp[]> {
typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
};
template<class _Tp, int _Np>
struct __unique_if<_Tp[_Np]>
{
typedef void __unique_array_known_bound;
};
template <class _Tp> struct remove_extent
{typedef _Tp type;};
template <class _Tp> struct remove_extent<_Tp[]>
{typedef _Tp type;};
template <class _Tp, int _Np> struct remove_extent<_Tp[_Np]>
{typedef _Tp type;};
template<class _Tp, class... _Args>
typename __unique_if<_Tp>::__unique_single
make_unique(_Args&&... __args)
{
return unique_ptr<_Tp>(new _Tp());
}
template<class _Tp>
typename __unique_if<_Tp>::__unique_array_unknown_bound
make_unique(int __n)
{
typedef typename remove_extent<_Tp>::type _Up;
return unique_ptr<_Tp>(new _Up[__n]());
}
} // namespace std
int main() {
fbl::unique_ptr<int> a = fbl::make_unique<int>();
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use of fbl::unique_ptr is deprecated, use std::unique_ptr instead
// CHECK-MESSAGES: :[[@LINE-2]]:28: warning: use of fbl::make_unique is deprecated, use std::make_unique instead
// CHECK-FIXES: std::unique_ptr<int> a = std::make_unique<int>();
std::unique_ptr<int> b = std::make_unique<int>();
auto c = fbl::make_unique<int>();
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use of fbl::make_unique is deprecated, use std::make_unique instead
// CHECK-FIXES: auto d = std::make_unique<int>();
auto d = std::make_unique<int>();
}