1 // 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.
6 #pragma clang system_header
7 
8 typedef unsigned char uint8_t;
9 
10 namespace 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   };
64 
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;
78 
79   // 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 
107   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   }
113 
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 { };
119 
120   template <class _Tp>
121   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   };
135 
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:
145     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     }
152     bool empty() const;
153   };
154 
155   // basic_string
156   template<class _CharT, class _Alloc = allocator<_CharT> >
157   class __attribute__ ((__type_visibility__("default"))) basic_string {
158     _CharT localStorage[4];
159 
160     typedef allocator_traits<_Alloc> __alloc_traits;
161 
162   public:
163     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     }
177   };
178 }
179 
180 void* operator new(std::size_t, const std::nothrow_t&) throw();
181 void* operator new[](std::size_t, const std::nothrow_t&) throw();
182 void operator delete(void*, const std::nothrow_t&) throw();
183 void operator delete[](void*, const std::nothrow_t&) throw();
184 
185 void* operator new (std::size_t size, void* ptr) throw() { return ptr; };
186 void* operator new[] (std::size_t size, void* ptr) throw() { return ptr; };
187 void operator delete (void* ptr, void*) throw() {};
188 void operator delete[] (void* ptr, void*) throw() {};
189