[clang-tidy][NFC] Use universal containers mock (#186669)
Changes are quite big but most of them is just copypasting and creating mocks.
This commit is contained in:
parent
befad798a9
commit
2ab8924c53
@ -0,0 +1,71 @@
|
||||
#ifndef _DEQUE_
|
||||
#define _DEQUE_
|
||||
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
|
||||
namespace std {
|
||||
|
||||
template <typename T, typename Allocator = allocator<T>>
|
||||
class deque {
|
||||
public:
|
||||
using value_type = T;
|
||||
|
||||
class iterator {
|
||||
public:
|
||||
iterator &operator++();
|
||||
iterator operator++(int);
|
||||
bool operator!=(const iterator &other) const;
|
||||
bool operator==(const iterator &other) const;
|
||||
T &operator*();
|
||||
T *operator->();
|
||||
};
|
||||
class const_iterator {
|
||||
public:
|
||||
const_iterator() = default;
|
||||
const_iterator(const iterator &) {}
|
||||
const_iterator &operator++();
|
||||
const_iterator operator++(int);
|
||||
bool operator!=(const const_iterator &other) const;
|
||||
bool operator==(const const_iterator &other) const;
|
||||
const T &operator*() const;
|
||||
const T *operator->() const;
|
||||
};
|
||||
class reverse_iterator {};
|
||||
|
||||
deque() = default;
|
||||
deque(initializer_list<T>) {}
|
||||
|
||||
iterator begin();
|
||||
const_iterator begin() const;
|
||||
iterator end();
|
||||
const_iterator end() const;
|
||||
|
||||
void push_back(const T &) {}
|
||||
void push_back(T &&) {}
|
||||
|
||||
void push_front(const T &) {}
|
||||
void push_front(T &&) {}
|
||||
|
||||
template <typename... Args>
|
||||
iterator emplace(const_iterator pos, Args &&...args);
|
||||
template <typename... Args>
|
||||
void emplace_back(Args &&...args) {}
|
||||
template <typename... Args>
|
||||
void emplace_front(Args &&...args) {}
|
||||
|
||||
T &operator[](size_t);
|
||||
const T &operator[](size_t) const;
|
||||
|
||||
void assign(size_t count, const T &value);
|
||||
|
||||
void clear();
|
||||
bool empty() const;
|
||||
size_t size() const;
|
||||
|
||||
~deque();
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
#endif // _DEQUE_
|
||||
@ -0,0 +1,61 @@
|
||||
#ifndef _FORWARD_LIST_
|
||||
#define _FORWARD_LIST_
|
||||
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
|
||||
namespace std {
|
||||
|
||||
template <typename T, typename Allocator = allocator<T>>
|
||||
class forward_list {
|
||||
public:
|
||||
using value_type = T;
|
||||
|
||||
class iterator {
|
||||
public:
|
||||
iterator &operator++();
|
||||
iterator operator++(int);
|
||||
bool operator!=(const iterator &other) const;
|
||||
bool operator==(const iterator &other) const;
|
||||
T &operator*();
|
||||
T *operator->();
|
||||
};
|
||||
class const_iterator {
|
||||
public:
|
||||
const_iterator() = default;
|
||||
const_iterator(const iterator &) {}
|
||||
const_iterator &operator++();
|
||||
const_iterator operator++(int);
|
||||
bool operator!=(const const_iterator &other) const;
|
||||
bool operator==(const const_iterator &other) const;
|
||||
const T &operator*() const;
|
||||
const T *operator->() const;
|
||||
};
|
||||
|
||||
forward_list() = default;
|
||||
forward_list(initializer_list<T>) {}
|
||||
|
||||
iterator begin();
|
||||
const_iterator begin() const;
|
||||
iterator end();
|
||||
const_iterator end() const;
|
||||
|
||||
void push_front(const T &) {}
|
||||
void push_front(T &&) {}
|
||||
|
||||
template <typename... Args>
|
||||
void emplace_front(Args &&...args) {}
|
||||
template <typename... Args>
|
||||
iterator emplace_after(const_iterator pos, Args &&...args);
|
||||
|
||||
void assign(size_t count, const T &value);
|
||||
|
||||
void clear();
|
||||
bool empty() const;
|
||||
|
||||
~forward_list();
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
#endif // _FORWARD_LIST_
|
||||
@ -0,0 +1,82 @@
|
||||
#ifndef _FUNCTIONAL_
|
||||
#define _FUNCTIONAL_
|
||||
|
||||
namespace std {
|
||||
|
||||
template <typename T = void>
|
||||
struct less {
|
||||
constexpr bool operator()(const T &Lhs, const T &Rhs) const {
|
||||
return Lhs < Rhs;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct less<void> {
|
||||
template <typename T, typename U>
|
||||
constexpr bool operator()(T &&Lhs, U &&Rhs) const {
|
||||
return Lhs < Rhs;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T = void>
|
||||
struct greater {
|
||||
constexpr bool operator()(const T &Lhs, const T &Rhs) const {
|
||||
return Lhs > Rhs;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct greater<void> {
|
||||
template <typename T, typename U>
|
||||
constexpr bool operator()(T &&Lhs, U &&Rhs) const {
|
||||
return Lhs > Rhs;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T = void>
|
||||
struct equal_to {
|
||||
constexpr bool operator()(const T &Lhs, const T &Rhs) const {
|
||||
return Lhs == Rhs;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct equal_to<void> {
|
||||
template <typename T, typename U>
|
||||
constexpr bool operator()(T &&Lhs, U &&Rhs) const {
|
||||
return Lhs == Rhs;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct hash {};
|
||||
|
||||
template <typename T = void>
|
||||
struct plus {
|
||||
constexpr T operator()(const T &Lhs, const T &Rhs) const {
|
||||
return Lhs + Rhs;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct plus<void> {
|
||||
template <typename T, typename U>
|
||||
constexpr auto operator()(T &&Lhs, U &&Rhs) const -> decltype(Lhs + Rhs) {
|
||||
return Lhs + Rhs;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T = void>
|
||||
struct logical_not {
|
||||
constexpr bool operator()(const T &Arg) const { return !Arg; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct logical_not<void> {
|
||||
template <typename T>
|
||||
constexpr bool operator()(T &&Arg) const { return !Arg; }
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
#endif // _FUNCTIONAL_
|
||||
@ -0,0 +1,68 @@
|
||||
#ifndef _LIST_
|
||||
#define _LIST_
|
||||
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
|
||||
namespace std {
|
||||
|
||||
template <typename T, typename Allocator = allocator<T>>
|
||||
class list {
|
||||
public:
|
||||
using value_type = T;
|
||||
|
||||
class iterator {
|
||||
public:
|
||||
iterator &operator++();
|
||||
iterator operator++(int);
|
||||
bool operator!=(const iterator &other) const;
|
||||
bool operator==(const iterator &other) const;
|
||||
T &operator*();
|
||||
T *operator->();
|
||||
};
|
||||
class const_iterator {
|
||||
public:
|
||||
const_iterator() = default;
|
||||
const_iterator(const iterator &) {}
|
||||
const_iterator &operator++();
|
||||
const_iterator operator++(int);
|
||||
bool operator!=(const const_iterator &other) const;
|
||||
bool operator==(const const_iterator &other) const;
|
||||
const T &operator*() const;
|
||||
const T *operator->() const;
|
||||
};
|
||||
class reverse_iterator {};
|
||||
|
||||
list() = default;
|
||||
list(initializer_list<T>) {}
|
||||
|
||||
iterator begin();
|
||||
const_iterator begin() const;
|
||||
iterator end();
|
||||
const_iterator end() const;
|
||||
|
||||
void push_front(const T &) {}
|
||||
void push_front(T &&) {}
|
||||
|
||||
void push_back(const T &) {}
|
||||
void push_back(T &&) {}
|
||||
|
||||
template <typename... Args>
|
||||
iterator emplace(const_iterator pos, Args &&...args);
|
||||
template <typename... Args>
|
||||
void emplace_back(Args &&...args) {}
|
||||
template <typename... Args>
|
||||
void emplace_front(Args &&...args) {}
|
||||
|
||||
void assign(size_t count, const T &value);
|
||||
|
||||
void clear();
|
||||
bool empty() const;
|
||||
size_t size() const;
|
||||
|
||||
~list();
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
#endif // _LIST_
|
||||
@ -0,0 +1,127 @@
|
||||
#ifndef _MAP_
|
||||
#define _MAP_
|
||||
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
namespace std {
|
||||
|
||||
template <typename Key, typename T, typename Compare = less<Key>,
|
||||
typename Allocator = allocator<pair<const Key, T>>>
|
||||
class map {
|
||||
public:
|
||||
using key_type = Key;
|
||||
using mapped_type = T;
|
||||
using value_type = std::pair<const Key, T>;
|
||||
|
||||
class iterator {
|
||||
public:
|
||||
iterator &operator++();
|
||||
iterator operator++(int);
|
||||
bool operator!=(const iterator &other) const;
|
||||
bool operator==(const iterator &other) const;
|
||||
value_type &operator*();
|
||||
value_type *operator->();
|
||||
};
|
||||
class const_iterator {
|
||||
public:
|
||||
const_iterator() = default;
|
||||
const_iterator(const iterator &) {}
|
||||
const_iterator(decltype(nullptr)) {}
|
||||
const_iterator &operator++();
|
||||
const_iterator operator++(int);
|
||||
bool operator!=(const const_iterator &other) const;
|
||||
bool operator==(const const_iterator &other) const;
|
||||
const value_type &operator*() const;
|
||||
const value_type *operator->() const;
|
||||
};
|
||||
|
||||
map() = default;
|
||||
map(initializer_list<value_type>) {}
|
||||
|
||||
iterator begin();
|
||||
const_iterator begin() const;
|
||||
iterator end();
|
||||
const_iterator end() const;
|
||||
|
||||
T &operator[](const Key &);
|
||||
T &operator[](Key &&);
|
||||
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args) {}
|
||||
template <typename... Args>
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args);
|
||||
|
||||
template <typename... Args>
|
||||
pair<iterator, bool> try_emplace(const Key &key, Args &&...args);
|
||||
|
||||
iterator find(const Key &);
|
||||
const_iterator find(const Key &) const;
|
||||
|
||||
T &at(const Key &);
|
||||
const T &at(const Key &) const;
|
||||
|
||||
unsigned count(const Key &) const;
|
||||
bool contains(const Key &) const;
|
||||
|
||||
void clear();
|
||||
bool empty() const;
|
||||
size_t size() const;
|
||||
};
|
||||
|
||||
template <typename Key, typename T, typename Compare = less<Key>,
|
||||
typename Allocator = allocator<pair<const Key, T>>>
|
||||
class multimap {
|
||||
public:
|
||||
using key_type = Key;
|
||||
using mapped_type = T;
|
||||
using value_type = std::pair<const Key, T>;
|
||||
|
||||
class iterator {
|
||||
public:
|
||||
iterator &operator++();
|
||||
iterator operator++(int);
|
||||
bool operator!=(const iterator &other) const;
|
||||
bool operator==(const iterator &other) const;
|
||||
value_type &operator*();
|
||||
value_type *operator->();
|
||||
};
|
||||
class const_iterator {
|
||||
public:
|
||||
const_iterator() = default;
|
||||
const_iterator(const iterator &) {}
|
||||
const_iterator(decltype(nullptr)) {}
|
||||
const_iterator &operator++();
|
||||
const_iterator operator++(int);
|
||||
bool operator!=(const const_iterator &other) const;
|
||||
bool operator==(const const_iterator &other) const;
|
||||
const value_type &operator*() const;
|
||||
const value_type *operator->() const;
|
||||
};
|
||||
|
||||
multimap() = default;
|
||||
multimap(initializer_list<value_type>) {}
|
||||
|
||||
iterator begin();
|
||||
const_iterator begin() const;
|
||||
iterator end();
|
||||
const_iterator end() const;
|
||||
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args) {}
|
||||
template <typename... Args>
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args);
|
||||
|
||||
unsigned count(const Key &) const;
|
||||
bool contains(const Key &) const;
|
||||
|
||||
void clear();
|
||||
bool empty() const;
|
||||
size_t size() const;
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
#endif // _MAP_
|
||||
@ -0,0 +1,47 @@
|
||||
#ifndef _QUEUE_
|
||||
#define _QUEUE_
|
||||
|
||||
#include "stddef.h"
|
||||
|
||||
namespace std {
|
||||
|
||||
template <typename T, typename Container = void>
|
||||
class queue {
|
||||
public:
|
||||
using value_type = T;
|
||||
|
||||
void push(const T &) {}
|
||||
void push(T &&) {}
|
||||
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args) {}
|
||||
|
||||
T &front();
|
||||
const T &front() const;
|
||||
T &back();
|
||||
const T &back() const;
|
||||
|
||||
bool empty() const;
|
||||
size_t size() const;
|
||||
};
|
||||
|
||||
template <typename T, typename Container = void, typename Compare = void>
|
||||
class priority_queue {
|
||||
public:
|
||||
using value_type = T;
|
||||
|
||||
void push(const T &) {}
|
||||
void push(T &&) {}
|
||||
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args) {}
|
||||
|
||||
const T &top() const;
|
||||
|
||||
bool empty() const;
|
||||
size_t size() const;
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
#endif // _QUEUE_
|
||||
@ -0,0 +1,121 @@
|
||||
#ifndef _SET_
|
||||
#define _SET_
|
||||
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
namespace std {
|
||||
|
||||
template <typename T, typename Compare = less<T>,
|
||||
typename Allocator = allocator<T>>
|
||||
class set {
|
||||
public:
|
||||
using value_type = T;
|
||||
using key_type = T;
|
||||
|
||||
class iterator {
|
||||
public:
|
||||
iterator &operator++();
|
||||
iterator operator++(int);
|
||||
bool operator!=(const iterator &other) const;
|
||||
bool operator==(const iterator &other) const;
|
||||
const T &operator*() const;
|
||||
const T *operator->() const;
|
||||
};
|
||||
class const_iterator {
|
||||
public:
|
||||
const_iterator() = default;
|
||||
const_iterator(const iterator &) {}
|
||||
const_iterator(decltype(nullptr)) {}
|
||||
const_iterator &operator++();
|
||||
const_iterator operator++(int);
|
||||
bool operator!=(const const_iterator &other) const;
|
||||
bool operator==(const const_iterator &other) const;
|
||||
const T &operator*() const;
|
||||
const T *operator->() const;
|
||||
};
|
||||
|
||||
set() = default;
|
||||
set(initializer_list<T>) {}
|
||||
|
||||
iterator begin();
|
||||
const_iterator begin() const;
|
||||
iterator end();
|
||||
const_iterator end() const;
|
||||
|
||||
pair<iterator, bool> insert(const T &);
|
||||
pair<iterator, bool> insert(T &&);
|
||||
iterator insert(const_iterator hint, const T &);
|
||||
iterator insert(const_iterator hint, T &&);
|
||||
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args) {}
|
||||
template <typename... Args>
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args);
|
||||
|
||||
iterator find(const T &);
|
||||
const_iterator find(const T &) const;
|
||||
|
||||
unsigned count(const T &) const;
|
||||
bool contains(const T &) const;
|
||||
|
||||
void clear();
|
||||
bool empty() const;
|
||||
size_t size() const;
|
||||
};
|
||||
|
||||
template <typename T, typename Compare = less<T>,
|
||||
typename Allocator = allocator<T>>
|
||||
class multiset {
|
||||
public:
|
||||
using value_type = T;
|
||||
using key_type = T;
|
||||
|
||||
class iterator {
|
||||
public:
|
||||
iterator &operator++();
|
||||
iterator operator++(int);
|
||||
bool operator!=(const iterator &other) const;
|
||||
bool operator==(const iterator &other) const;
|
||||
const T &operator*() const;
|
||||
const T *operator->() const;
|
||||
};
|
||||
class const_iterator {
|
||||
public:
|
||||
const_iterator() = default;
|
||||
const_iterator(const iterator &) {}
|
||||
const_iterator(decltype(nullptr)) {}
|
||||
const_iterator &operator++();
|
||||
const_iterator operator++(int);
|
||||
bool operator!=(const const_iterator &other) const;
|
||||
bool operator==(const const_iterator &other) const;
|
||||
const T &operator*() const;
|
||||
const T *operator->() const;
|
||||
};
|
||||
|
||||
multiset() = default;
|
||||
multiset(initializer_list<T>) {}
|
||||
|
||||
iterator begin();
|
||||
const_iterator begin() const;
|
||||
iterator end();
|
||||
const_iterator end() const;
|
||||
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args) {}
|
||||
template <typename... Args>
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args);
|
||||
|
||||
unsigned count(const T &) const;
|
||||
bool contains(const T &) const;
|
||||
|
||||
void clear();
|
||||
bool empty() const;
|
||||
size_t size() const;
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
#endif // _SET_
|
||||
@ -0,0 +1,28 @@
|
||||
#ifndef _STACK_
|
||||
#define _STACK_
|
||||
|
||||
#include <deque>
|
||||
|
||||
namespace std {
|
||||
|
||||
template <typename T, typename Container = deque<T>>
|
||||
class stack {
|
||||
public:
|
||||
using value_type = T;
|
||||
|
||||
void push(const T &) {}
|
||||
void push(T &&) {}
|
||||
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args) {}
|
||||
|
||||
T &top();
|
||||
const T &top() const;
|
||||
|
||||
bool empty() const;
|
||||
size_t size() const;
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
#endif // _STACK_
|
||||
@ -33,6 +33,7 @@ struct basic_string {
|
||||
const C *c_str() const;
|
||||
const C *data() const;
|
||||
|
||||
void clear();
|
||||
bool empty() const;
|
||||
size_type size() const;
|
||||
size_type length() const;
|
||||
|
||||
@ -0,0 +1,76 @@
|
||||
#ifndef _TUPLE_
|
||||
#define _TUPLE_
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace std {
|
||||
|
||||
struct _Swallow_assign
|
||||
{
|
||||
template<class _Tp>
|
||||
const _Swallow_assign&
|
||||
operator=(const _Tp&) const
|
||||
{ return *this; }
|
||||
};
|
||||
|
||||
constexpr _Swallow_assign ignore{};
|
||||
|
||||
template <typename... Ts>
|
||||
class tuple {
|
||||
public:
|
||||
tuple() = default;
|
||||
tuple(const tuple &) = default;
|
||||
tuple(tuple &&) = default;
|
||||
tuple &operator=(const tuple &) = default;
|
||||
tuple &operator=(tuple &&) = default;
|
||||
|
||||
tuple(const Ts &...) {}
|
||||
tuple(Ts &&...) {}
|
||||
|
||||
template <typename... Us>
|
||||
tuple(const tuple<Us...> &) {}
|
||||
template <typename... Us>
|
||||
tuple(tuple<Us...> &&) {}
|
||||
|
||||
template <typename U1, typename U2>
|
||||
tuple(const pair<U1, U2> &) {}
|
||||
template <typename U1, typename U2>
|
||||
tuple(pair<U1, U2> &&) {}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct tuple_size;
|
||||
|
||||
template <typename... Ts>
|
||||
struct tuple_size<tuple<Ts...>>
|
||||
: integral_constant<size_t, sizeof...(Ts)> {};
|
||||
|
||||
template <size_t I, typename T>
|
||||
struct tuple_element;
|
||||
|
||||
template <size_t I, typename... Ts>
|
||||
struct tuple_element<I, tuple<Ts...>> {
|
||||
using type = __type_pack_element<I, Ts...>;
|
||||
};
|
||||
|
||||
template <size_t I, typename... Ts>
|
||||
typename tuple_element<I, tuple<Ts...>>::type
|
||||
get(const tuple<Ts...> &);
|
||||
|
||||
template <size_t I, typename... Ts>
|
||||
typename tuple_element<I, tuple<Ts...>>::type
|
||||
get(tuple<Ts...> &&);
|
||||
|
||||
template <typename... Ts>
|
||||
tuple<typename remove_reference<Ts>::type...> make_tuple(Ts &&...) {
|
||||
return {};
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
tuple<Args...> tie(Args&... args) {
|
||||
return tuple<Args...>(args...);
|
||||
}
|
||||
|
||||
} // namespace std
|
||||
|
||||
#endif // _TUPLE_
|
||||
@ -0,0 +1,126 @@
|
||||
#ifndef _UNORDERED_MAP_
|
||||
#define _UNORDERED_MAP_
|
||||
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
namespace std {
|
||||
|
||||
template <typename Key, typename T, typename Hash = hash<Key>,
|
||||
typename Pred = equal_to<Key>,
|
||||
typename Allocator = allocator<pair<const Key, T>>>
|
||||
class unordered_map {
|
||||
public:
|
||||
using key_type = Key;
|
||||
using mapped_type = T;
|
||||
using value_type = std::pair<const Key, T>;
|
||||
|
||||
class iterator {
|
||||
public:
|
||||
iterator &operator++();
|
||||
iterator operator++(int);
|
||||
bool operator!=(const iterator &other) const;
|
||||
bool operator==(const iterator &other) const;
|
||||
value_type &operator*();
|
||||
value_type *operator->();
|
||||
const value_type &operator*() const;
|
||||
const value_type *operator->() const;
|
||||
};
|
||||
class const_iterator {
|
||||
public:
|
||||
const_iterator() = default;
|
||||
const_iterator(const iterator &) {}
|
||||
const_iterator &operator++();
|
||||
const_iterator operator++(int);
|
||||
bool operator!=(const const_iterator &other) const;
|
||||
bool operator==(const const_iterator &other) const;
|
||||
const value_type &operator*() const;
|
||||
const value_type *operator->() const;
|
||||
};
|
||||
|
||||
unordered_map() = default;
|
||||
unordered_map(initializer_list<value_type>) {}
|
||||
|
||||
iterator begin();
|
||||
const_iterator begin() const;
|
||||
iterator end();
|
||||
const_iterator end() const;
|
||||
|
||||
T &operator[](const Key &);
|
||||
T &operator[](Key &&);
|
||||
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args) {}
|
||||
template <typename... Args>
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args);
|
||||
|
||||
template <typename... Args>
|
||||
pair<iterator, bool> try_emplace(const Key &key, Args &&...args);
|
||||
|
||||
iterator find(const Key &);
|
||||
const_iterator find(const Key &) const;
|
||||
|
||||
unsigned count(const Key &) const;
|
||||
bool contains(const Key &) const;
|
||||
|
||||
void clear();
|
||||
bool empty() const;
|
||||
size_t size() const;
|
||||
};
|
||||
|
||||
template <typename Key, typename T, typename Hash = hash<Key>,
|
||||
typename Pred = equal_to<Key>,
|
||||
typename Allocator = allocator<pair<const Key, T>>>
|
||||
class unordered_multimap {
|
||||
public:
|
||||
using key_type = Key;
|
||||
using mapped_type = T;
|
||||
using value_type = std::pair<const Key, T>;
|
||||
|
||||
class iterator {
|
||||
public:
|
||||
iterator &operator++();
|
||||
iterator operator++(int);
|
||||
bool operator!=(const iterator &other) const;
|
||||
bool operator==(const iterator &other) const;
|
||||
value_type &operator*();
|
||||
value_type *operator->();
|
||||
};
|
||||
class const_iterator {
|
||||
public:
|
||||
const_iterator() = default;
|
||||
const_iterator(const iterator &) {}
|
||||
const_iterator &operator++();
|
||||
const_iterator operator++(int);
|
||||
bool operator!=(const const_iterator &other) const;
|
||||
bool operator==(const const_iterator &other) const;
|
||||
const value_type &operator*() const;
|
||||
const value_type *operator->() const;
|
||||
};
|
||||
|
||||
unordered_multimap() = default;
|
||||
unordered_multimap(initializer_list<value_type>) {}
|
||||
|
||||
iterator begin();
|
||||
const_iterator begin() const;
|
||||
iterator end();
|
||||
const_iterator end() const;
|
||||
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args) {}
|
||||
template <typename... Args>
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args);
|
||||
|
||||
unsigned count(const Key &) const;
|
||||
bool contains(const Key &) const;
|
||||
|
||||
void clear();
|
||||
bool empty() const;
|
||||
size_t size() const;
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
#endif // _UNORDERED_MAP_
|
||||
@ -0,0 +1,113 @@
|
||||
#ifndef _UNORDERED_SET_
|
||||
#define _UNORDERED_SET_
|
||||
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
|
||||
namespace std {
|
||||
|
||||
template <typename T, typename Hash = hash<T>, typename Pred = equal_to<T>,
|
||||
typename Allocator = allocator<T>>
|
||||
class unordered_set {
|
||||
public:
|
||||
using value_type = T;
|
||||
using key_type = T;
|
||||
|
||||
class iterator {
|
||||
public:
|
||||
iterator &operator++();
|
||||
iterator operator++(int);
|
||||
bool operator!=(const iterator &other) const;
|
||||
bool operator==(const iterator &other) const;
|
||||
const T &operator*() const;
|
||||
const T *operator->() const;
|
||||
};
|
||||
class const_iterator {
|
||||
public:
|
||||
const_iterator() = default;
|
||||
const_iterator(const iterator &) {}
|
||||
const_iterator &operator++();
|
||||
const_iterator operator++(int);
|
||||
bool operator!=(const const_iterator &other) const;
|
||||
bool operator==(const const_iterator &other) const;
|
||||
const T &operator*() const;
|
||||
const T *operator->() const;
|
||||
};
|
||||
|
||||
unordered_set() = default;
|
||||
unordered_set(initializer_list<T>) {}
|
||||
|
||||
iterator begin();
|
||||
const_iterator begin() const;
|
||||
iterator end();
|
||||
const_iterator end() const;
|
||||
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args) {}
|
||||
template <typename... Args>
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args);
|
||||
|
||||
iterator find(const T &);
|
||||
const_iterator find(const T &) const;
|
||||
|
||||
unsigned count(const T &) const;
|
||||
bool contains(const T &) const;
|
||||
|
||||
void clear();
|
||||
bool empty() const;
|
||||
size_t size() const;
|
||||
};
|
||||
|
||||
template <typename T, typename Hash = hash<T>, typename Pred = equal_to<T>,
|
||||
typename Allocator = allocator<T>>
|
||||
class unordered_multiset {
|
||||
public:
|
||||
using value_type = T;
|
||||
using key_type = T;
|
||||
|
||||
class iterator {
|
||||
public:
|
||||
iterator &operator++();
|
||||
iterator operator++(int);
|
||||
bool operator!=(const iterator &other) const;
|
||||
bool operator==(const iterator &other) const;
|
||||
const T &operator*() const;
|
||||
const T *operator->() const;
|
||||
};
|
||||
class const_iterator {
|
||||
public:
|
||||
const_iterator() = default;
|
||||
const_iterator(const iterator &) {}
|
||||
const_iterator &operator++();
|
||||
const_iterator operator++(int);
|
||||
bool operator!=(const const_iterator &other) const;
|
||||
bool operator==(const const_iterator &other) const;
|
||||
const T &operator*() const;
|
||||
const T *operator->() const;
|
||||
};
|
||||
|
||||
unordered_multiset() = default;
|
||||
unordered_multiset(initializer_list<T>) {}
|
||||
|
||||
iterator begin();
|
||||
const_iterator begin() const;
|
||||
iterator end();
|
||||
const_iterator end() const;
|
||||
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args) {}
|
||||
template <typename... Args>
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args);
|
||||
|
||||
unsigned count(const T &) const;
|
||||
bool contains(const T &) const;
|
||||
|
||||
void clear();
|
||||
bool empty() const;
|
||||
size_t size() const;
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
#endif // _UNORDERED_SET_
|
||||
@ -27,6 +27,34 @@ void swap(T &a, T &b) {
|
||||
b = move(tmp);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
struct pair {
|
||||
T1 first;
|
||||
T2 second;
|
||||
|
||||
pair() = default;
|
||||
pair(const pair &) = default;
|
||||
pair(pair &&) = default;
|
||||
|
||||
pair(const T1 &a, const T2 &b) : first(a), second(b) {}
|
||||
pair(T1 &&a, T2 &&b)
|
||||
: first(std::move(a)), second(std::move(b)) {}
|
||||
|
||||
template <typename U1, typename U2>
|
||||
pair(const pair<U1, U2> &p) : first(p.first), second(p.second) {}
|
||||
template <typename U1, typename U2>
|
||||
pair(pair<U1, U2> &&p)
|
||||
: first(std::move(p.first)), second(std::move(p.second)) {}
|
||||
|
||||
pair &operator=(const pair &) = default;
|
||||
pair &operator=(pair &&) = default;
|
||||
};
|
||||
|
||||
template <typename T1, typename T2>
|
||||
pair<T1, T2> make_pair(T1 x, T2 y) {
|
||||
return pair<T1, T2>(x, y);
|
||||
}
|
||||
|
||||
} // namespace std
|
||||
|
||||
#endif // _UTILITY_
|
||||
|
||||
@ -28,11 +28,11 @@ public:
|
||||
vector &operator=(vector &&other);
|
||||
vector &operator=(initializer_list<T>);
|
||||
|
||||
void push_back(const T &value);
|
||||
void push_back(T &&value);
|
||||
void push_back(const T &value) {}
|
||||
void push_back(T &&value) {}
|
||||
|
||||
template <typename... Args>
|
||||
void emplace_back(Args &&...args);
|
||||
void emplace_back(Args &&...args) {}
|
||||
|
||||
template <typename... Args>
|
||||
iterator emplace(const_iterator pos, Args &&...args);
|
||||
|
||||
@ -6,36 +6,12 @@
|
||||
// RUN: -config="{CheckOptions: \
|
||||
// RUN: {bugprone-dangling-handle.HandleClasses: \
|
||||
// RUN: 'std::basic_string_view; ::llvm::StringRef;'}}"
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace std {
|
||||
|
||||
template <typename, typename>
|
||||
class pair {};
|
||||
|
||||
template <typename T>
|
||||
class set {
|
||||
public:
|
||||
using const_iterator = const T*;
|
||||
using iterator = T*;
|
||||
|
||||
std::pair<iterator, bool> insert(const T& value);
|
||||
std::pair<iterator, bool> insert(T&& value);
|
||||
iterator insert(const_iterator hint, const T& value);
|
||||
iterator insert(const_iterator hint, T&& value);
|
||||
};
|
||||
|
||||
template <typename Key, typename Value>
|
||||
class map {
|
||||
public:
|
||||
using value_type = pair<Key, Value>;
|
||||
value_type& operator[](const Key& key);
|
||||
value_type& operator[](Key&& key);
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
namespace llvm {
|
||||
|
||||
class StringRef {
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
// RUN: %check_clang_tidy %s bugprone-infinite-loop %t \
|
||||
// RUN: -- -- -fexceptions -fblocks -fno-delayed-template-parsing
|
||||
|
||||
#include <tuple>
|
||||
|
||||
void simple_infinite_loop1() {
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
@ -793,16 +795,6 @@ void issue_138842_reduced() {
|
||||
}
|
||||
}
|
||||
|
||||
namespace std {
|
||||
template <typename T, typename U>
|
||||
struct pair {
|
||||
T first;
|
||||
U second;
|
||||
|
||||
pair(T a, U b) : first(a), second(b) {}
|
||||
};
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
void structured_binding_in_template_byval(T a, U b) {
|
||||
auto [c, d] = std::pair<T, U>(a,b);
|
||||
@ -867,31 +859,6 @@ void array_structured_binding() {
|
||||
}
|
||||
}
|
||||
|
||||
namespace std {
|
||||
using size_t = int;
|
||||
template <class> struct tuple_size;
|
||||
template <std::size_t, class> struct tuple_element;
|
||||
template <class...> class tuple;
|
||||
|
||||
namespace {
|
||||
template <class T, T v>
|
||||
struct size_helper { static const T value = v; };
|
||||
} // namespace
|
||||
|
||||
template <class... T>
|
||||
struct tuple_size<tuple<T...>> : size_helper<std::size_t, sizeof...(T)> {};
|
||||
|
||||
template <std::size_t I, class... T>
|
||||
struct tuple_element<I, tuple<T...>> {
|
||||
using type = __type_pack_element<I, T...>;
|
||||
};
|
||||
|
||||
template <class...> class tuple {};
|
||||
|
||||
template <std::size_t I, class... T>
|
||||
typename tuple_element<I, tuple<T...>>::type get(tuple<T...>);
|
||||
} // namespace std
|
||||
|
||||
std::tuple<int*, int> &get_chunk();
|
||||
|
||||
void test_structured_bindings_tuple() {
|
||||
|
||||
@ -1,13 +1,9 @@
|
||||
// RUN: %check_clang_tidy -std=c++11-or-later %s bugprone-unsafe-functions %t --
|
||||
// RUN: %check_clang_tidy -std=c++11-or-later %s bugprone-unsafe-functions %t
|
||||
|
||||
#include <utility>
|
||||
#include <cstddef>
|
||||
|
||||
namespace std {
|
||||
template <class T1, class T2>
|
||||
struct pair {
|
||||
T1 first;
|
||||
T2 second;
|
||||
};
|
||||
|
||||
using ptrdiff_t = long long;
|
||||
|
||||
template<class T>
|
||||
std::pair<T*, std::ptrdiff_t>
|
||||
|
||||
@ -11,8 +11,17 @@
|
||||
// RUN: }}' -- \
|
||||
// RUN: -fno-delayed-template-parsing
|
||||
|
||||
#include <deque>
|
||||
#include <forward_list>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
typedef decltype(nullptr) nullptr_t;
|
||||
|
||||
@ -31,62 +40,6 @@ struct any {
|
||||
void reset();
|
||||
};
|
||||
|
||||
template <typename T1, typename T2>
|
||||
struct pair {};
|
||||
|
||||
template <typename Key, typename T>
|
||||
struct map {
|
||||
struct iterator {};
|
||||
|
||||
map();
|
||||
void clear();
|
||||
bool empty();
|
||||
template <class... Args>
|
||||
pair<iterator, bool> try_emplace(const Key &key, Args &&...args);
|
||||
};
|
||||
|
||||
template <typename Key, typename T>
|
||||
struct unordered_map {
|
||||
struct iterator {};
|
||||
|
||||
unordered_map();
|
||||
void clear();
|
||||
bool empty();
|
||||
template <class... Args>
|
||||
pair<iterator, bool> try_emplace(const Key &key, Args &&...args);
|
||||
};
|
||||
|
||||
#define DECLARE_STANDARD_CONTAINER(name) \
|
||||
template <typename T> \
|
||||
struct name { \
|
||||
name(); \
|
||||
void clear(); \
|
||||
bool empty(); \
|
||||
}
|
||||
|
||||
#define DECLARE_STANDARD_CONTAINER_WITH_ASSIGN(name) \
|
||||
template <typename T> \
|
||||
struct name { \
|
||||
name(); \
|
||||
void clear(); \
|
||||
bool empty(); \
|
||||
void assign(size_t, const T &); \
|
||||
}
|
||||
|
||||
DECLARE_STANDARD_CONTAINER_WITH_ASSIGN(basic_string);
|
||||
DECLARE_STANDARD_CONTAINER_WITH_ASSIGN(vector);
|
||||
DECLARE_STANDARD_CONTAINER_WITH_ASSIGN(deque);
|
||||
DECLARE_STANDARD_CONTAINER_WITH_ASSIGN(forward_list);
|
||||
DECLARE_STANDARD_CONTAINER_WITH_ASSIGN(list);
|
||||
DECLARE_STANDARD_CONTAINER(set);
|
||||
DECLARE_STANDARD_CONTAINER(multiset);
|
||||
DECLARE_STANDARD_CONTAINER(multimap);
|
||||
DECLARE_STANDARD_CONTAINER(unordered_set);
|
||||
DECLARE_STANDARD_CONTAINER(unordered_multiset);
|
||||
DECLARE_STANDARD_CONTAINER(unordered_multimap);
|
||||
|
||||
typedef basic_string<char> string;
|
||||
|
||||
} // namespace std
|
||||
|
||||
class A {
|
||||
@ -851,7 +804,7 @@ void standardContainerClearIsReinit() {
|
||||
container.empty();
|
||||
}
|
||||
{
|
||||
std::multimap<int> container;
|
||||
std::multimap<int, int> container;
|
||||
std::move(container);
|
||||
container.clear();
|
||||
container.empty();
|
||||
@ -875,7 +828,7 @@ void standardContainerClearIsReinit() {
|
||||
container.empty();
|
||||
}
|
||||
{
|
||||
std::unordered_multimap<int> container;
|
||||
std::unordered_multimap<int, int> container;
|
||||
std::move(container);
|
||||
container.clear();
|
||||
container.empty();
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
// RUN: %check_clang_tidy %s cppcoreguidelines-pro-bounds-pointer-arithmetic -check-suffixes=,DEFAULT %t
|
||||
// RUN: %check_clang_tidy %s cppcoreguidelines-pro-bounds-pointer-arithmetic %t -- \
|
||||
// RUN: -config="{CheckOptions: {cppcoreguidelines-pro-bounds-pointer-arithmetic.AllowIncrementDecrementOperators: true}}" --
|
||||
// RUN: -config="{CheckOptions: {cppcoreguidelines-pro-bounds-pointer-arithmetic.AllowIncrementDecrementOperators: true}}"
|
||||
|
||||
#include <utility>
|
||||
#include <map>
|
||||
|
||||
enum E {
|
||||
ENUM_LITERAL = 1
|
||||
@ -121,21 +124,8 @@ void okay() {
|
||||
|
||||
namespace gh126424 {
|
||||
|
||||
namespace std {
|
||||
template <typename, typename>
|
||||
class pair {};
|
||||
|
||||
template <typename Key, typename Value>
|
||||
class map {
|
||||
public:
|
||||
using value_type = pair<Key, Value>;
|
||||
value_type& operator[](const Key& key);
|
||||
value_type& operator[](Key&& key);
|
||||
};
|
||||
}
|
||||
|
||||
template <typename R>
|
||||
int f(std::map<R*, int>& map, R* r) {
|
||||
int f(::std::map<R*, int>& map, R* r) {
|
||||
return map[r]; // OK
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
// RUN: %check_clang_tidy -std=c++17-or-later %s fuchsia-trailing-return %t
|
||||
|
||||
#include <utility>
|
||||
|
||||
int add_one(const int arg) { return arg; }
|
||||
|
||||
auto get_add_one() -> int (*)(const int) {
|
||||
@ -29,12 +31,6 @@ struct ImplicitDeductionGuides {
|
||||
ImplicitDeductionGuides(const T &);
|
||||
};
|
||||
|
||||
template <typename A, typename B>
|
||||
struct pair {
|
||||
A first;
|
||||
B second;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct UserDefinedDeductionGuides {
|
||||
UserDefinedDeductionGuides(T);
|
||||
@ -43,7 +39,7 @@ struct UserDefinedDeductionGuides {
|
||||
};
|
||||
|
||||
template <typename T1, typename T2>
|
||||
UserDefinedDeductionGuides(T1, T2) -> UserDefinedDeductionGuides<pair<T1, T2>>;
|
||||
UserDefinedDeductionGuides(T1, T2) -> UserDefinedDeductionGuides<std::pair<T1, T2>>;
|
||||
|
||||
void foo() {
|
||||
ImplicitDeductionGuides X(42);
|
||||
|
||||
@ -1,16 +1,6 @@
|
||||
// RUN: %check_clang_tidy %s google-build-explicit-make-pair %t
|
||||
|
||||
namespace std {
|
||||
template <class T1, class T2>
|
||||
struct pair {
|
||||
pair(T1 x, T2 y) {}
|
||||
};
|
||||
|
||||
template <class T1, class T2>
|
||||
pair<T1, T2> make_pair(T1 x, T2 y) {
|
||||
return pair<T1, T2>(x, y);
|
||||
}
|
||||
}
|
||||
#include <utility>
|
||||
|
||||
template <typename T>
|
||||
void templ(T a, T b) {
|
||||
|
||||
@ -1,62 +0,0 @@
|
||||
namespace std {
|
||||
struct _Swallow_assign
|
||||
{
|
||||
template<class _Tp>
|
||||
const _Swallow_assign&
|
||||
operator=(const _Tp&) const
|
||||
{ return *this; }
|
||||
};
|
||||
|
||||
constexpr _Swallow_assign ignore{};
|
||||
|
||||
template<typename T1, typename T2>
|
||||
struct pair {
|
||||
T1 first;
|
||||
T2 second;
|
||||
|
||||
pair() = default;
|
||||
pair(T1 first, T2 second) : first(first), second(second) {}
|
||||
};
|
||||
|
||||
template<typename... Args>
|
||||
struct tuple {
|
||||
tuple(Args&...) {}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
tuple<T1, T2> operator=(const std::pair<T1, T2>&);
|
||||
};
|
||||
|
||||
template<typename... Args>
|
||||
tuple<Args...> tie(Args&... args) {
|
||||
return tuple<Args...>(args...);
|
||||
}
|
||||
|
||||
template <typename Key, typename Value>
|
||||
class unordered_map {
|
||||
public:
|
||||
using value_type = pair<Key, Value>;
|
||||
|
||||
class iterator {
|
||||
public:
|
||||
iterator& operator++();
|
||||
bool operator!=(const iterator &other);
|
||||
const value_type &operator*() const;
|
||||
value_type operator*();
|
||||
const value_type* operator->() const;
|
||||
};
|
||||
|
||||
iterator begin() const;
|
||||
iterator end() const;
|
||||
};
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
std::pair<T1, T2> getPair();
|
||||
|
||||
template<typename T1, typename T2>
|
||||
constexpr std::pair<T1, T2> getConstexprPair() {
|
||||
return std::pair<T1, T2>();
|
||||
}
|
||||
|
||||
template<typename T1, typename T2, typename T3>
|
||||
std::tuple<T1, T2, T3> getTuple();
|
||||
@ -7,314 +7,20 @@
|
||||
// RUN: modernize-use-emplace.TupleMakeFunctions: \
|
||||
// RUN: '::std::make_pair; ::std::make_tuple; ::test::MakeSingle'}}"
|
||||
|
||||
#include <tuple>
|
||||
#include <deque>
|
||||
#include <forward_list>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <queue>
|
||||
#include <set>
|
||||
#include <stack>
|
||||
#include <tuple>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
#include <memory>
|
||||
|
||||
namespace std {
|
||||
template <typename E>
|
||||
class initializer_list {
|
||||
public:
|
||||
const E *a, *b;
|
||||
initializer_list() noexcept {}
|
||||
};
|
||||
|
||||
template <typename T1, typename T2>
|
||||
class pair {
|
||||
public:
|
||||
pair() = default;
|
||||
pair(const pair &) = default;
|
||||
pair(pair &&) = default;
|
||||
|
||||
pair(const T1 &, const T2 &) {}
|
||||
pair(T1 &&, T2 &&) {}
|
||||
|
||||
template <typename U1, typename U2>
|
||||
pair(const pair<U1, U2> &){};
|
||||
template <typename U1, typename U2>
|
||||
pair(pair<U1, U2> &&){};
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class vector {
|
||||
public:
|
||||
using value_type = T;
|
||||
|
||||
class iterator {};
|
||||
class const_iterator {};
|
||||
const_iterator begin() { return const_iterator{}; }
|
||||
|
||||
vector() = default;
|
||||
vector(initializer_list<T>) {}
|
||||
|
||||
void push_back(const T &) {}
|
||||
void push_back(T &&) {}
|
||||
|
||||
template <typename... Args>
|
||||
void emplace_back(Args &&... args){};
|
||||
template <typename... Args>
|
||||
iterator emplace(const_iterator pos, Args &&...args);
|
||||
~vector();
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class list {
|
||||
public:
|
||||
using value_type = T;
|
||||
|
||||
class iterator {};
|
||||
class const_iterator {};
|
||||
const_iterator begin() { return const_iterator{}; }
|
||||
|
||||
void push_front(const T &) {}
|
||||
void push_front(T &&) {}
|
||||
|
||||
void push_back(const T &) {}
|
||||
void push_back(T &&) {}
|
||||
|
||||
template <typename... Args>
|
||||
iterator emplace(const_iterator pos, Args &&...args);
|
||||
template <typename... Args>
|
||||
void emplace_back(Args &&... args){};
|
||||
template <typename... Args>
|
||||
void emplace_front(Args &&...args){};
|
||||
~list();
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class deque {
|
||||
public:
|
||||
using value_type = T;
|
||||
|
||||
class iterator {};
|
||||
class const_iterator {};
|
||||
const_iterator begin() { return const_iterator{}; }
|
||||
|
||||
void push_back(const T &) {}
|
||||
void push_back(T &&) {}
|
||||
|
||||
void push_front(const T &) {}
|
||||
void push_front(T &&) {}
|
||||
|
||||
template <typename... Args>
|
||||
iterator emplace(const_iterator pos, Args &&...args);
|
||||
template <typename... Args>
|
||||
void emplace_back(Args &&... args){};
|
||||
template <typename... Args>
|
||||
void emplace_front(Args &&...args){};
|
||||
~deque();
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class forward_list {
|
||||
public:
|
||||
using value_type = T;
|
||||
|
||||
class iterator {};
|
||||
class const_iterator {};
|
||||
const_iterator begin() { return const_iterator{}; }
|
||||
|
||||
void push_front(const T &) {}
|
||||
void push_front(T &&) {}
|
||||
|
||||
template <typename... Args>
|
||||
void emplace_front(Args &&...args){};
|
||||
template <typename... Args>
|
||||
iterator emplace_after(const_iterator pos, Args &&...args);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class set {
|
||||
public:
|
||||
using value_type = T;
|
||||
|
||||
class iterator {};
|
||||
class const_iterator {};
|
||||
const_iterator begin() { return const_iterator{}; }
|
||||
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args){};
|
||||
template <typename... Args>
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args);
|
||||
};
|
||||
|
||||
template <typename Key, typename T>
|
||||
class map {
|
||||
public:
|
||||
using value_type = std::pair<Key, T>;
|
||||
|
||||
class iterator {};
|
||||
class const_iterator {};
|
||||
const_iterator begin() { return const_iterator{}; }
|
||||
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args){};
|
||||
template <typename... Args>
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class multiset {
|
||||
public:
|
||||
using value_type = T;
|
||||
|
||||
class iterator {};
|
||||
class const_iterator {};
|
||||
const_iterator begin() { return const_iterator{}; }
|
||||
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args){};
|
||||
template <typename... Args>
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args);
|
||||
};
|
||||
|
||||
template <typename Key, typename T>
|
||||
class multimap {
|
||||
public:
|
||||
using value_type = std::pair<Key, T>;
|
||||
|
||||
class iterator {};
|
||||
class const_iterator {};
|
||||
const_iterator begin() { return const_iterator{}; }
|
||||
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args){};
|
||||
template <typename... Args>
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class unordered_set {
|
||||
public:
|
||||
using value_type = T;
|
||||
|
||||
class iterator {};
|
||||
class const_iterator {};
|
||||
const_iterator begin() { return const_iterator{}; }
|
||||
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args){};
|
||||
template <typename... Args>
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args);
|
||||
};
|
||||
|
||||
template <typename Key, typename T>
|
||||
class unordered_map {
|
||||
public:
|
||||
using value_type = std::pair<Key, T>;
|
||||
|
||||
class iterator {};
|
||||
class const_iterator {};
|
||||
const_iterator begin() { return const_iterator{}; }
|
||||
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args){};
|
||||
template <typename... Args>
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class unordered_multiset {
|
||||
public:
|
||||
using value_type = T;
|
||||
|
||||
class iterator {};
|
||||
class const_iterator {};
|
||||
const_iterator begin() { return const_iterator{}; }
|
||||
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args){};
|
||||
template <typename... Args>
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args);
|
||||
};
|
||||
|
||||
template <typename Key, typename T>
|
||||
class unordered_multimap {
|
||||
public:
|
||||
using value_type = std::pair<Key, T>;
|
||||
|
||||
class iterator {};
|
||||
class const_iterator {};
|
||||
const_iterator begin() { return const_iterator{}; }
|
||||
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args){};
|
||||
template <typename... Args>
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class stack {
|
||||
public:
|
||||
using value_type = T;
|
||||
|
||||
void push(const T &) {}
|
||||
void push(T &&) {}
|
||||
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args){};
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class queue {
|
||||
public:
|
||||
using value_type = T;
|
||||
|
||||
void push(const T &) {}
|
||||
void push(T &&) {}
|
||||
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args){};
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class priority_queue {
|
||||
public:
|
||||
using value_type = T;
|
||||
|
||||
void push(const T &) {}
|
||||
void push(T &&) {}
|
||||
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args){};
|
||||
};
|
||||
|
||||
template <typename T1, typename T2>
|
||||
pair<typename remove_reference<T1>::type, typename remove_reference<T2>::type>
|
||||
make_pair(T1 &&, T2 &&) {
|
||||
return {};
|
||||
};
|
||||
|
||||
template <typename... Ts>
|
||||
class tuple {
|
||||
public:
|
||||
tuple() = default;
|
||||
tuple(const tuple &) = default;
|
||||
tuple(tuple &&) = default;
|
||||
|
||||
tuple(const Ts &...) {}
|
||||
tuple(Ts &&...) {}
|
||||
|
||||
template <typename... Us>
|
||||
tuple(const tuple<Us...> &){};
|
||||
template <typename... Us>
|
||||
tuple(tuple<Us...> &&) {}
|
||||
|
||||
template <typename U1, typename U2>
|
||||
tuple(const pair<U1, U2> &) {
|
||||
static_assert(sizeof...(Ts) == 2, "Wrong tuple size");
|
||||
};
|
||||
template <typename U1, typename U2>
|
||||
tuple(pair<U1, U2> &&) {
|
||||
static_assert(sizeof...(Ts) == 2, "Wrong tuple size");
|
||||
};
|
||||
};
|
||||
|
||||
template <typename... Ts>
|
||||
tuple<typename remove_reference<Ts>::type...> make_tuple(Ts &&...) {
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace std
|
||||
#include <vector>
|
||||
|
||||
namespace llvm {
|
||||
template <typename T>
|
||||
|
||||
@ -1,6 +1,21 @@
|
||||
// RUN: %check_clang_tidy -check-suffix=,CPP20ORLATER -std=c++20-or-later %s modernize-use-structured-binding %t -- -- -I %S/Inputs/use-structured-binding/
|
||||
// RUN: %check_clang_tidy -std=c++17 %s modernize-use-structured-binding %t -- -- -I %S/Inputs/use-structured-binding/
|
||||
#include "fake_std_pair_tuple.h"
|
||||
|
||||
#include <utility>
|
||||
#include <tuple>
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
template<typename T1, typename T2>
|
||||
std::pair<T1, T2> getPair();
|
||||
|
||||
template<typename T1, typename T2>
|
||||
constexpr std::pair<T1, T2> getConstexprPair() {
|
||||
return std::pair<T1, T2>();
|
||||
}
|
||||
|
||||
template<typename T1, typename T2, typename T3>
|
||||
std::tuple<T1, T2, T3> getTuple();
|
||||
|
||||
template<typename T>
|
||||
void MarkUsed(T x);
|
||||
@ -665,12 +680,12 @@ void IgnoreDirectInit() {
|
||||
}
|
||||
|
||||
void StdMapTestCases() {
|
||||
for (auto p : std::unordered_map<int, int>()) {
|
||||
for (const auto p : std::unordered_map<int, int>()) {
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
|
||||
// CHECK-FIXES: for (auto [x, y] : std::unordered_map<int, int>()) {
|
||||
// CHECK-FIXES: for (const auto [x, y] : std::unordered_map<int, int>()) {
|
||||
// CHECK-NEXT: // REMOVE
|
||||
int x = p.first;
|
||||
int y = p.second; // REMOVE
|
||||
const int x = p.first;
|
||||
const int y = p.second; // REMOVE
|
||||
// CHECK-FIXES: // REMOVE
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,44 +1,9 @@
|
||||
// RUN: %check_clang_tidy -std=c++14-or-later %s modernize-use-transparent-functors %t
|
||||
|
||||
#include <utility>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace std {
|
||||
template <typename T = void>
|
||||
struct plus {
|
||||
constexpr T operator()(const T &Lhs, const T &Rhs) const;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct plus<void> {
|
||||
template <typename T, typename U>
|
||||
constexpr auto operator()(T &&Lhs, U &&Rhs) const ->
|
||||
decltype(forward<T>(Lhs) + forward<U>(Rhs));
|
||||
};
|
||||
|
||||
template <typename T = void>
|
||||
struct less {
|
||||
constexpr bool operator()(const T &Lhs, const T &Rhs) const;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct less<void> {
|
||||
template <typename T, typename U>
|
||||
constexpr bool operator()(T &&Lhs, U &&Rhs) const;
|
||||
};
|
||||
|
||||
template <typename T = void>
|
||||
struct logical_not {
|
||||
constexpr bool operator()(const T &Arg) const;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct logical_not<void> {
|
||||
template <typename T>
|
||||
constexpr bool operator()(T &&Arg) const;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class allocator;
|
||||
|
||||
template <
|
||||
class Key,
|
||||
|
||||
@ -1,38 +1,12 @@
|
||||
// RUN: %check_clang_tidy -std=c++11-or-later %s portability-std-allocator-const %t -- -- -fno-delayed-template-parsing
|
||||
|
||||
namespace std {
|
||||
typedef unsigned size_t;
|
||||
|
||||
template <class T>
|
||||
class allocator {};
|
||||
template <class T>
|
||||
class hash {};
|
||||
template <class T>
|
||||
class equal_to {};
|
||||
template <class T>
|
||||
class less {};
|
||||
|
||||
template <class T, class A = std::allocator<T>>
|
||||
class deque {};
|
||||
template <class T, class A = std::allocator<T>>
|
||||
class forward_list {};
|
||||
template <class T, class A = std::allocator<T>>
|
||||
class list {};
|
||||
template <class T, class A = std::allocator<T>>
|
||||
class vector {};
|
||||
|
||||
template <class K, class C = std::less<K>, class A = std::allocator<K>>
|
||||
class multiset {};
|
||||
template <class K, class C = std::less<K>, class A = std::allocator<K>>
|
||||
class set {};
|
||||
template <class K, class H = std::hash<K>, class Eq = std::equal_to<K>, class A = std::allocator<K>>
|
||||
class unordered_multiset {};
|
||||
template <class K, class H = std::hash<K>, class Eq = std::equal_to<K>, class A = std::allocator<K>>
|
||||
class unordered_set {};
|
||||
|
||||
template <class T, class C = std::deque<T>>
|
||||
class stack {};
|
||||
} // namespace std
|
||||
#include <deque>
|
||||
#include <forward_list>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <stack>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
namespace absl {
|
||||
template <class K, class H = std::hash<K>, class Eq = std::equal_to<K>, class A = std::allocator<K>>
|
||||
|
||||
@ -1,41 +1,8 @@
|
||||
// RUN: %check_clang_tidy %s readability-container-contains %t
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
// Some *very* simplified versions of `map` etc.
|
||||
namespace std {
|
||||
|
||||
template <class Key, class T>
|
||||
struct map {
|
||||
struct iterator {
|
||||
bool operator==(const iterator &Other) const;
|
||||
bool operator!=(const iterator &Other) const;
|
||||
};
|
||||
|
||||
unsigned count(const Key &K) const;
|
||||
bool contains(const Key &K) const;
|
||||
iterator find(const Key &K);
|
||||
iterator end();
|
||||
};
|
||||
|
||||
template <class Key>
|
||||
struct set {
|
||||
unsigned count(const Key &K) const;
|
||||
bool contains(const Key &K) const;
|
||||
};
|
||||
|
||||
template <class Key>
|
||||
struct unordered_set {
|
||||
unsigned count(const Key &K) const;
|
||||
bool contains(const Key &K) const;
|
||||
};
|
||||
|
||||
template <class Key, class T>
|
||||
struct multimap {
|
||||
unsigned count(const Key &K) const;
|
||||
bool contains(const Key &K) const;
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
#include <unordered_set>
|
||||
|
||||
// Check that we detect various common ways to check for membership
|
||||
int testDifferentCheckTypes(std::map<int, int> &MyMap) {
|
||||
|
||||
@ -1,28 +1,14 @@
|
||||
// RUN: %check_clang_tidy -std=c++17-or-later %s readability-isolate-declaration %t
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
template <typename T1, typename T2>
|
||||
struct pair {
|
||||
T1 first;
|
||||
T2 second;
|
||||
pair(T1 v1, T2 v2) : first(v1), second(v2) {}
|
||||
|
||||
template <int N>
|
||||
decltype(auto) get() const {
|
||||
if constexpr (N == 0)
|
||||
return first;
|
||||
else if constexpr (N == 1)
|
||||
return second;
|
||||
}
|
||||
};
|
||||
|
||||
void forbidden_transformations() {
|
||||
if (int i = 42, j = i; i == j)
|
||||
;
|
||||
switch (int i = 12, j = 14; i)
|
||||
;
|
||||
|
||||
auto [i, j] = pair<int, int>(42, 42);
|
||||
auto [i, j] = std::pair<int, int>(42, 42);
|
||||
}
|
||||
|
||||
struct SomeClass {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user