Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Analysis / Inputs / system-header-simulator-cxx-std-suppression.h
blobdc53af269c9c2a3c0f8b6e0092424702bfb2764c
1 // This is a fake system header with divide-by-zero bugs introduced in
2 // c++ std library functions. We use these bugs to test hard-coded
3 // suppression of diagnostics within standard library functions that are known
4 // to produce false positives.
6 #pragma clang system_header
8 typedef unsigned char uint8_t;
10 typedef __typeof__(sizeof(int)) size_t;
11 void *memmove(void *s1, const void *s2, size_t n);
13 namespace std {
15 template <class _Tp>
16 class allocator {
17 public:
18 void deallocate(void *p) {
19 ::delete p;
23 template <class _Alloc>
24 class allocator_traits {
25 public:
26 static void deallocate(void *p) {
27 _Alloc().deallocate(p);
31 template <class _Tp, class _Alloc>
32 class __list_imp
33 {};
35 template <class _Tp, class _Alloc = allocator<_Tp> >
36 class list
37 : private __list_imp<_Tp, _Alloc>
39 public:
40 void pop_front() {
41 // Fake use-after-free.
42 // No warning is expected as we are suppressing warning coming
43 // out of std::list.
44 int z = 0;
45 z = 5/z;
47 bool empty() const;
50 // basic_string
51 template<class _CharT, class _Alloc = allocator<_CharT> >
52 class __attribute__ ((__type_visibility__("default"))) basic_string {
53 bool isLong;
54 union {
55 _CharT localStorage[4];
56 _CharT *externalStorage;
58 void assignExternal(_CharT *newExternal) {
59 externalStorage = newExternal;
61 } storage;
63 typedef allocator_traits<_Alloc> __alloc_traits;
65 public:
66 basic_string();
68 void push_back(int c) {
69 // Fake error trigger.
70 // No warning is expected as we are suppressing warning coming
71 // out of std::basic_string.
72 int z = 0;
73 z = 5/z;
76 _CharT *getBuffer() {
77 return isLong ? storage.externalStorage : storage.localStorage;
80 basic_string &operator +=(int c) {
81 // Fake deallocate stack-based storage.
82 // No warning is expected as we are suppressing warnings within
83 // std::basic_string.
84 __alloc_traits::deallocate(getBuffer());
87 basic_string &operator =(const basic_string &other) {
88 // Fake deallocate stack-based storage, then use the variable in the
89 // same union.
90 // No warning is expected as we are suppressing warnings within
91 // std::basic_string.
92 __alloc_traits::deallocate(getBuffer());
93 storage.assignExternal(new _CharT[4]);
97 template<class _Engine, class _UIntType>
98 class __independent_bits_engine {
99 public:
100 // constructors and seeding functions
101 __independent_bits_engine(_Engine& __e, size_t __w);
104 template<class _Engine, class _UIntType>
105 __independent_bits_engine<_Engine, _UIntType>
106 ::__independent_bits_engine(_Engine& __e, size_t __w)
108 // Fake error trigger.
109 // No warning is expected as we are suppressing warning coming
110 // out of std::__independent_bits_engine.
111 int z = 0;
112 z = 5/z;
115 #if __has_feature(cxx_decltype)
116 typedef decltype(nullptr) nullptr_t;
118 template<class _Tp>
119 class shared_ptr
121 public:
122 constexpr shared_ptr(nullptr_t);
123 explicit shared_ptr(_Tp* __p);
125 shared_ptr(shared_ptr&& __r) { }
127 ~shared_ptr();
129 shared_ptr& operator=(shared_ptr&& __r) {
130 // Fake error trigger.
131 // No warning is expected as we are suppressing warning coming
132 // out of std::shared_ptr.
133 int z = 0;
134 z = 5/z;
138 template<class _Tp>
139 inline
140 constexpr
141 shared_ptr<_Tp>::shared_ptr(nullptr_t) {
144 #endif // __has_feature(cxx_decltype)