95 lines · cpp
1// RUN: %check_clang_tidy -std=c++11-or-later %s portability-std-allocator-const %t -- -- -fno-delayed-template-parsing2 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 std36 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 absl41 42template <class T>43class allocator {};44 45void simple(const std::vector<const char> &v, std::deque<const short> *d) {46 // CHECK-MESSAGES: [[#@LINE-1]]:19: warning: container using std::allocator<const T> is a deprecated libc++ extension; remove const for compatibility with other standard libraries47 // CHECK-MESSAGES: [[#@LINE-2]]:47: warning: container48 std::list<const long> l;49 // CHECK-MESSAGES: [[#@LINE-1]]:3: warning: container50 51 std::multiset<int *const> ms;52 // CHECK-MESSAGES: [[#@LINE-1]]:3: warning: container53 std::set<const std::hash<int>> s;54 // CHECK-MESSAGES: [[#@LINE-1]]:3: warning: container55 std::unordered_multiset<int *const> ums;56 // CHECK-MESSAGES: [[#@LINE-1]]:3: warning: container57 std::unordered_set<const int> us;58 // CHECK-MESSAGES: [[#@LINE-1]]:3: warning: container59 60 absl::flat_hash_set<const int> fhs;61 // CHECK-MESSAGES: [[#@LINE-1]]:3: warning: container62 63 using my_vector = std::vector<const int>;64 // CHECK-MESSAGES: [[#@LINE-1]]:21: warning: container65 my_vector v1;66 using my_vector2 = my_vector;67 68 std::vector<int> neg1;69 std::vector<const int *> neg2; // not const T70 std::vector<const int, allocator<const int>> neg3; // not use std::allocator<const T>71 std::allocator<const int> a; // not caught, but rare72 std::forward_list<const int> forward; // not caught, but rare73 std::stack<const int> stack; // not caught, but rare74}75 76template <class T>77void temp1() {78 std::vector<const T> v;79 // CHECK-MESSAGES: [[#@LINE-1]]:3: warning: container80 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]]:3: warning: container91 92 std::vector<T> neg1;93 std::forward_list<const T> neg2;94}95