system-header-simulator-cxx-std-suppression.h
3.38 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// This is a fake system header with divide-by-zero bugs introduced in
// c++ std library functions. We use these bugs to test hard-coded
// suppression of diagnostics within standard library functions that are known
// to produce false positives.
#pragma clang system_header
typedef unsigned char uint8_t;
typedef __typeof__(sizeof(int)) size_t;
void *memmove(void *s1, const void *s2, size_t n);
namespace std {
template <class _Tp>
class allocator {
public:
void deallocate(void *p) {
::delete p;
}
};
template <class _Alloc>
class allocator_traits {
public:
static void deallocate(void *p) {
_Alloc().deallocate(p);
}
};
template <class _Tp, class _Alloc>
class __list_imp
{};
template <class _Tp, class _Alloc = allocator<_Tp> >
class list
: private __list_imp<_Tp, _Alloc>
{
public:
void pop_front() {
// Fake use-after-free.
// No warning is expected as we are suppressing warning coming
// out of std::list.
int z = 0;
z = 5/z;
}
bool empty() const;
};
// basic_string
template<class _CharT, class _Alloc = allocator<_CharT> >
class __attribute__ ((__type_visibility__("default"))) basic_string {
bool isLong;
union {
_CharT localStorage[4];
_CharT *externalStorage;
void assignExternal(_CharT *newExternal) {
externalStorage = newExternal;
}
} storage;
typedef allocator_traits<_Alloc> __alloc_traits;
public:
basic_string();
void push_back(int c) {
// Fake error trigger.
// No warning is expected as we are suppressing warning coming
// out of std::basic_string.
int z = 0;
z = 5/z;
}
_CharT *getBuffer() {
return isLong ? storage.externalStorage : storage.localStorage;
}
basic_string &operator +=(int c) {
// Fake deallocate stack-based storage.
// No warning is expected as we are suppressing warnings within
// std::basic_string.
__alloc_traits::deallocate(getBuffer());
}
basic_string &operator =(const basic_string &other) {
// Fake deallocate stack-based storage, then use the variable in the
// same union.
// No warning is expected as we are suppressing warnings within
// std::basic_string.
__alloc_traits::deallocate(getBuffer());
storage.assignExternal(new _CharT[4]);
}
};
template<class _Engine, class _UIntType>
class __independent_bits_engine {
public:
// constructors and seeding functions
__independent_bits_engine(_Engine& __e, size_t __w);
};
template<class _Engine, class _UIntType>
__independent_bits_engine<_Engine, _UIntType>
::__independent_bits_engine(_Engine& __e, size_t __w)
{
// Fake error trigger.
// No warning is expected as we are suppressing warning coming
// out of std::__independent_bits_engine.
int z = 0;
z = 5/z;
}
#if __has_feature(cxx_decltype)
typedef decltype(nullptr) nullptr_t;
template<class _Tp>
class shared_ptr
{
public:
constexpr shared_ptr(nullptr_t);
explicit shared_ptr(_Tp* __p);
shared_ptr(shared_ptr&& __r) { }
~shared_ptr();
shared_ptr& operator=(shared_ptr&& __r) {
// Fake error trigger.
// No warning is expected as we are suppressing warning coming
// out of std::shared_ptr.
int z = 0;
z = 5/z;
}
};
template<class _Tp>
inline
constexpr
shared_ptr<_Tp>::shared_ptr(nullptr_t) {
}
#endif // __has_feature(cxx_decltype)
}