File: std-allocator-const.cpp

package info (click to toggle)
llvm-toolchain-17 1%3A17.0.6-22
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,799,624 kB
  • sloc: cpp: 6,428,607; ansic: 1,383,196; asm: 793,408; python: 223,504; objc: 75,364; f90: 60,502; lisp: 33,869; pascal: 15,282; sh: 9,684; perl: 7,453; ml: 4,937; awk: 3,523; makefile: 2,889; javascript: 2,149; xml: 888; fortran: 619; cs: 573
file content (94 lines) | stat: -rw-r--r-- 3,180 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// 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

namespace absl {
template <class K, class H = std::hash<K>, class Eq = std::equal_to<K>, class A = std::allocator<K>>
class flat_hash_set {};
} // namespace absl

template <class T>
class allocator {};

void simple(const std::vector<const char> &v, std::deque<const short> *d) {
  // 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
  // CHECK-MESSAGES: [[#@LINE-2]]:52: warning: container
  std::list<const long> l;
  // CHECK-MESSAGES: [[#@LINE-1]]:8: warning: container

  std::multiset<int *const> ms;
  // CHECK-MESSAGES: [[#@LINE-1]]:8: warning: container
  std::set<const std::hash<int>> s;
  // CHECK-MESSAGES: [[#@LINE-1]]:8: warning: container
  std::unordered_multiset<int *const> ums;
  // CHECK-MESSAGES: [[#@LINE-1]]:8: warning: container
  std::unordered_set<const int> us;
  // CHECK-MESSAGES: [[#@LINE-1]]:8: warning: container

  absl::flat_hash_set<const int> fhs;
  // CHECK-MESSAGES: [[#@LINE-1]]:9: warning: container

  using my_vector = std::vector<const int>;
  // CHECK-MESSAGES: [[#@LINE-1]]:26: warning: container
  my_vector v1;
  using my_vector2 = my_vector;

  std::vector<int> neg1;
  std::vector<const int *> neg2;                     // not const T
  std::vector<const int, allocator<const int>> neg3; // not use std::allocator<const T>
  std::allocator<const int> a;                       // not caught, but rare
  std::forward_list<const int> forward;              // not caught, but rare
  std::stack<const int> stack;                       // not caught, but rare
}

template <class T>
void temp1() {
  std::vector<const T> v;
  // CHECK-MESSAGES: [[#@LINE-1]]:8: warning: container

  std::vector<T> neg1;
  std::forward_list<const T> neg2;
}
void use_temp1() { temp1<int>(); }

template <class T>
void temp2() {
  // Match std::vector<const dependent> for the uninstantiated temp2.
  std::vector<const T> v;
  // CHECK-MESSAGES: [[#@LINE-1]]:8: warning: container

  std::vector<T> neg1;
  std::forward_list<const T> neg2;
}