system-header-simulator-cxx.h revision bdc0bf3f84b8771572d8401c66903c56a2e1318e
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
8typedef unsigned char uint8_t;
9
10namespace 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
123  template <class _Tp, class _Alloc>
124  class __list_imp
125  {};
126
127  template <class _Tp, class _Alloc = allocator<_Tp> >
128  class list
129  : private __list_imp<_Tp, _Alloc>
130  {
131  public:
132    void pop_front() {
133      // Fake use-after-free.
134      // No warning is expected as we are suppressing warning comming
135      // out of std::list.
136      int z = 0;
137      z = 5/z;
138    }
139    bool empty() const;
140  };
141
142  // basic_string
143  template<class _CharT>
144  class __attribute__ ((__type_visibility__("default"))) basic_string {
145  public:
146    void push_back(int c);
147  };
148  template <class _CharT>
149  void basic_string<_CharT>::push_back(int __c) {
150        // Fake error trigger.
151        // No warning is expected as we are suppressing warning comming
152        // out of std::basic_string.
153        int z = 0;
154        z = 5/z;
155  }
156}
157
158void* operator new(std::size_t, const std::nothrow_t&) throw();
159void* operator new[](std::size_t, const std::nothrow_t&) throw();
160void operator delete(void*, const std::nothrow_t&) throw();
161void operator delete[](void*, const std::nothrow_t&) throw();
162
163void* operator new (std::size_t size, void* ptr) throw() { return ptr; };
164void* operator new[] (std::size_t size, void* ptr) throw() { return ptr; };
165void operator delete (void* ptr, void*) throw() {};
166void operator delete[] (void* ptr, void*) throw() {};
167