1// RUN: %check_clang_tidy -std=c++11-or-later %s portability-std-allocator-const %t -- -- -fno-delayed-template-parsing
2
3namespace std {
4typedef unsigned size_t;
5
6template <class T>
7class allocator {};
8template <class T>
9class hash {};
10template <class T>
11class equal_to {};
12template <class T>
13class less {};
14
15template <class T, class A = std::allocator<T>>
16class deque {};
17template <class T, class A = std::allocator<T>>
18class forward_list {};
19template <class T, class A = std::allocator<T>>
20class list {};
21template <class T, class A = std::allocator<T>>
22class vector {};
23
24template <class K, class C = std::less<K>, class A = std::allocator<K>>
25class multiset {};
26template <class K, class C = std::less<K>, class A = std::allocator<K>>
27class set {};
28template <class K, class H = std::hash<K>, class Eq = std::equal_to<K>, class A = std::allocator<K>>
29class unordered_multiset {};
30template <class K, class H = std::hash<K>, class Eq = std::equal_to<K>, class A = std::allocator<K>>
31class unordered_set {};
32
33template <class T, class C = std::deque<T>>
34class stack {};
35} // namespace std
36
37namespace absl {
38template <class K, class H = std::hash<K>, class Eq = std::equal_to<K>, class A = std::allocator<K>>
39class flat_hash_set {};
40} // namespace absl
41
42template <class T>
43class allocator {};
44
45void 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
76template <class T>
77void 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}
84void use_temp1() { temp1<int>(); }
85
86template <class T>
87void 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}
95

source code of clang-tools-extra/test/clang-tidy/checkers/portability/std-allocator-const.cpp