blob: 9bb8ec48923d67e626949f44bca87d0476713e0f [file] [log] [blame]
Jordan Roseb54cfa32013-02-01 19:50:01 +00001// Like the compiler, the static analyzer treats some functions differently if
2// they come from a system header -- for example, it is assumed that system
3// functions do not arbitrarily free() their parameters, and that some bugs
4// found in system headers cannot be fixed by the user and should be
5// suppressed.
Jordan Rose1e0e4002012-09-10 21:27:35 +00006#pragma clang system_header
7
Anna Zaks830d2f72013-11-04 19:13:03 +00008typedef unsigned char uint8_t;
9
Jordan Rose1e0e4002012-09-10 21:27:35 +000010namespace std {
11 template <class T1, class T2>
12 struct pair {
13 T1 first;
14 T2 second;
15
16 pair() : first(), second() {}
17 pair(const T1 &a, const T2 &b) : first(a), second(b) {}
18
19 template<class U1, class U2>
20 pair(const pair<U1, U2> &other) : first(other.first), second(other.second) {}
21 };
22
23 typedef __typeof__(sizeof(int)) size_t;
24
25 template<typename T>
26 class vector {
27 T *_start;
28 T *_finish;
29 T *_end_of_storage;
30 public:
31 vector() : _start(0), _finish(0), _end_of_storage(0) {}
32 ~vector();
33
34 size_t size() const {
35 return size_t(_finish - _start);
36 }
37
38 void push_back();
39 T pop_back();
40
41 T &operator[](size_t n) {
42 return _start[n];
43 }
44
45 const T &operator[](size_t n) const {
46 return _start[n];
47 }
48
49 T *begin() { return _start; }
50 const T *begin() const { return _start; }
51
52 T *end() { return _finish; }
53 const T *end() const { return _finish; }
54 };
55
56 class exception {
57 public:
58 exception() throw();
59 virtual ~exception() throw();
60 virtual const char *what() const throw() {
61 return 0;
62 }
63 };
Anton Yartsev13df0362013-03-25 01:35:45 +000064
65 class bad_alloc : public exception {
66 public:
67 bad_alloc() throw();
68 bad_alloc(const bad_alloc&) throw();
69 bad_alloc& operator=(const bad_alloc&) throw();
70 virtual const char* what() const throw() {
71 return 0;
72 }
73 };
74
75 struct nothrow_t {};
76
77 extern const nothrow_t nothrow;
Jordan Rosed11ef1a2013-04-02 00:26:15 +000078
Jordan Rose05b2f982013-07-17 17:16:33 +000079 // libc++'s implementation
80 template <class _E>
81 class initializer_list
82 {
83 const _E* __begin_;
84 size_t __size_;
85
86 initializer_list(const _E* __b, size_t __s)
87 : __begin_(__b),
88 __size_(__s)
89 {}
90
91 public:
92 typedef _E value_type;
93 typedef const _E& reference;
94 typedef const _E& const_reference;
95 typedef size_t size_type;
96
97 typedef const _E* iterator;
98 typedef const _E* const_iterator;
99
100 initializer_list() : __begin_(0), __size_(0) {}
101
102 size_t size() const {return __size_;}
103 const _E* begin() const {return __begin_;}
104 const _E* end() const {return __begin_ + __size_;}
105 };
106
Jordan Rosed11ef1a2013-04-02 00:26:15 +0000107 template<class InputIter, class OutputIter>
108 OutputIter copy(InputIter II, InputIter IE, OutputIter OI) {
109 while (II != IE)
110 *OI++ = *II++;
111 return OI;
112 }
Jordan Rose7023a902013-05-01 22:39:31 +0000113
114 struct input_iterator_tag { };
115 struct output_iterator_tag { };
116 struct forward_iterator_tag : public input_iterator_tag { };
117 struct bidirectional_iterator_tag : public forward_iterator_tag { };
118 struct random_access_iterator_tag : public bidirectional_iterator_tag { };
Anna Zaksa42fb522013-07-04 02:38:10 +0000119
120 template <class _Tp>
Jordan Rose4c56c222013-11-15 02:11:19 +0000121 class allocator {
122 public:
123 void deallocate(void *p) {
124 ::delete p;
125 }
126 };
127
128 template <class _Alloc>
129 class allocator_traits {
130 public:
131 static void deallocate(void *p) {
132 _Alloc().deallocate(p);
133 }
134 };
Anna Zaksa42fb522013-07-04 02:38:10 +0000135
136 template <class _Tp, class _Alloc>
137 class __list_imp
138 {};
139
140 template <class _Tp, class _Alloc = allocator<_Tp> >
141 class list
142 : private __list_imp<_Tp, _Alloc>
143 {
144 public:
Anna Zakse0ad1042013-07-09 01:55:00 +0000145 void pop_front() {
146 // Fake use-after-free.
147 // No warning is expected as we are suppressing warning comming
148 // out of std::list.
149 int z = 0;
150 z = 5/z;
151 }
Anna Zaksa42fb522013-07-04 02:38:10 +0000152 bool empty() const;
153 };
154
Anna Zaks830d2f72013-11-04 19:13:03 +0000155 // basic_string
Jordan Rose4c56c222013-11-15 02:11:19 +0000156 template<class _CharT, class _Alloc = allocator<_CharT> >
Anna Zaks830d2f72013-11-04 19:13:03 +0000157 class __attribute__ ((__type_visibility__("default"))) basic_string {
Jordan Rose4c56c222013-11-15 02:11:19 +0000158 _CharT localStorage[4];
159
160 typedef allocator_traits<_Alloc> __alloc_traits;
161
Anna Zaks830d2f72013-11-04 19:13:03 +0000162 public:
Jordan Rose4c56c222013-11-15 02:11:19 +0000163 void push_back(int c) {
164 // Fake error trigger.
165 // No warning is expected as we are suppressing warning comming
166 // out of std::basic_string.
167 int z = 0;
168 z = 5/z;
169 }
170
171 basic_string &operator +=(int c) {
172 // Fake deallocate stack-based storage.
173 // No warning is expected as we are suppressing warnings within
174 // allocators being used by std::basic_string.
175 __alloc_traits::deallocate(&localStorage);
176 }
Anna Zaks830d2f72013-11-04 19:13:03 +0000177 };
Jordan Rose1e0e4002012-09-10 21:27:35 +0000178}
Anton Yartsev13df0362013-03-25 01:35:45 +0000179
180void* operator new(std::size_t, const std::nothrow_t&) throw();
181void* operator new[](std::size_t, const std::nothrow_t&) throw();
182void operator delete(void*, const std::nothrow_t&) throw();
183void operator delete[](void*, const std::nothrow_t&) throw();
184
185void* operator new (std::size_t size, void* ptr) throw() { return ptr; };
186void* operator new[] (std::size_t size, void* ptr) throw() { return ptr; };
187void operator delete (void* ptr, void*) throw() {};
188void operator delete[] (void* ptr, void*) throw() {};