| 1 |
// RUN: %check_clang_tidy -std=c++11-or-later %s portability-std-allocator-const %t -- -- -fno-delayed-template-parsing |
| 2 |
|
| 3 |
namespace std { |
| 4 |
typedef unsigned size_t; |
| 5 |
|
| 6 |
template <class T> |
| 7 |
class allocator {}; |
| 8 |
template <class T> |
| 9 |
class hash {}; |
| 10 |
template <class T> |
| 11 |
class equal_to {}; |
| 12 |
template <class T> |
| 13 |
class less {}; |
| 14 |
|
| 15 |
template <class T, class A = std::allocator<T>> |
| 16 |
class deque {}; |
| 17 |
template <class T, class A = std::allocator<T>> |
| 18 |
class forward_list {}; |
| 19 |
template <class T, class A = std::allocator<T>> |
| 20 |
class list {}; |
| 21 |
template <class T, class A = std::allocator<T>> |
| 22 |
class vector {}; |
| 23 |
|
| 24 |
template <class K, class C = std::less<K>, class A = std::allocator<K>> |
| 25 |
class multiset {}; |
| 26 |
template <class K, class C = std::less<K>, class A = std::allocator<K>> |
| 27 |
class set {}; |
| 28 |
template <class K, class H = std::hash<K>, class Eq = std::equal_to<K>, class A = std::allocator<K>> |
| 29 |
class unordered_multiset {}; |
| 30 |
template <class K, class H = std::hash<K>, class Eq = std::equal_to<K>, class A = std::allocator<K>> |
| 31 |
class unordered_set {}; |
| 32 |
|
| 33 |
template <class T, class C = std::deque<T>> |
| 34 |
class stack {}; |
| 35 |
} // namespace std |
| 36 |
|
| 37 |
namespace absl { |
| 38 |
template <class K, class H = std::hash<K>, class Eq = std::equal_to<K>, class A = std::allocator<K>> |
| 39 |
class flat_hash_set {}; |
| 40 |
} // namespace absl |
| 41 |
|
| 42 |
template <class T> |
| 43 |
class allocator {}; |
| 44 |
|
| 45 |
void simple(const std::vector<const char> &v, std::deque<const short> *d) { |
| 46 |
// CHECK-MESSAGES: [[#@LINE-1]]:24: warning: container using std::allocator<const T> is a deprecated libc++ extension; remove const for compatibility with other standard libraries |
| 47 |
// CHECK-MESSAGES: [[#@LINE-2]]:52: warning: container |
| 48 |
std::list<const long> l; |
| 49 |
// CHECK-MESSAGES: [[#@LINE-1]]:8: warning: container |
| 50 |
|
| 51 |
std::multiset<int *const> ms; |
| 52 |
// CHECK-MESSAGES: [[#@LINE-1]]:8: warning: container |
| 53 |
std::set<const std::hash<int>> s; |
| 54 |
// CHECK-MESSAGES: [[#@LINE-1]]:8: warning: container |
| 55 |
std::unordered_multiset<int *const> ums; |
| 56 |
// CHECK-MESSAGES: [[#@LINE-1]]:8: warning: container |
| 57 |
std::unordered_set<const int> us; |
| 58 |
// CHECK-MESSAGES: [[#@LINE-1]]:8: warning: container |
| 59 |
|
| 60 |
absl::flat_hash_set<const int> fhs; |
| 61 |
// CHECK-MESSAGES: [[#@LINE-1]]:9: warning: container |
| 62 |
|
| 63 |
using my_vector = std::vector<const int>; |
| 64 |
// CHECK-MESSAGES: [[#@LINE-1]]:26: warning: container |
| 65 |
my_vector v1; |
| 66 |
using my_vector2 = my_vector; |
| 67 |
|
| 68 |
std::vector<int> neg1; |
| 69 |
std::vector<const int *> neg2; // not const T |
| 70 |
std::vector<const int, allocator<const int>> neg3; // not use std::allocator<const T> |
| 71 |
std::allocator<const int> a; // not caught, but rare |
| 72 |
std::forward_list<const int> forward; // not caught, but rare |
| 73 |
std::stack<const int> stack; // not caught, but rare |
| 74 |
} |
| 75 |
|
| 76 |
template <class T> |
| 77 |
void temp1() { |
| 78 |
std::vector<const T> v; |
| 79 |
// CHECK-MESSAGES: [[#@LINE-1]]:8: warning: container |
| 80 |
|
| 81 |
std::vector<T> neg1; |
| 82 |
std::forward_list<const T> neg2; |
| 83 |
} |
| 84 |
void use_temp1() { temp1<int>(); } |
| 85 |
|
| 86 |
template <class T> |
| 87 |
void temp2() { |
| 88 |
// Match std::vector<const dependent> for the uninstantiated temp2. |
| 89 |
std::vector<const T> v; |
| 90 |
// CHECK-MESSAGES: [[#@LINE-1]]:8: warning: container |
| 91 |
|
| 92 |
std::vector<T> neg1; |
| 93 |
std::forward_list<const T> neg2; |
| 94 |
} |