aboutsummaryrefslogtreecommitdiff
path: root/CPP/Common/Common0.h
diff options
context:
space:
mode:
authorIgor Pavlov <87184205+ip7z@users.noreply.github.com>2024-05-14 00:00:00 +0000
committerIgor Pavlov <87184205+ip7z@users.noreply.github.com>2024-05-15 23:55:04 +0500
commitfc662341e6f85da78ada0e443f6116b978f79f22 (patch)
tree1be1cc402a7a9cbc18d4eeea6b141354c2d559e3 /CPP/Common/Common0.h
parent5b39dc76f1bc82f941d5c800ab9f34407a06b53a (diff)
download7zip-24.05.tar.gz
7zip-24.05.tar.bz2
7zip-24.05.zip
24.0524.05
Diffstat (limited to 'CPP/Common/Common0.h')
-rw-r--r--CPP/Common/Common0.h330
1 files changed, 330 insertions, 0 deletions
diff --git a/CPP/Common/Common0.h b/CPP/Common/Common0.h
new file mode 100644
index 0000000..55606cd
--- /dev/null
+++ b/CPP/Common/Common0.h
@@ -0,0 +1,330 @@
1// Common0.h
2
3#if defined(_MSC_VER) && _MSC_VER >= 1800
4#pragma warning(disable : 4464) // relative include path contains '..'
5#endif
6
7#ifndef ZIP7_INC_COMMON0_H
8#define ZIP7_INC_COMMON0_H
9
10#include "../../C/Compiler.h"
11
12/*
13This file contains compiler related things for cpp files.
14This file is included to all cpp files in 7-Zip via "Common.h".
15Also this file is included in "IDecl.h" (that is included in interface files).
16So external modules can use 7-Zip interfaces without
17predefined macros defined in "Common.h".
18*/
19
20#ifdef _MSC_VER
21 #pragma warning(disable : 4710) // function not inlined
22 // 'CUncopyable::CUncopyable':
23 #pragma warning(disable : 4514) // unreferenced inline function has been removed
24 #if _MSC_VER < 1300
25 #pragma warning(disable : 4702) // unreachable code
26 #pragma warning(disable : 4714) // function marked as __forceinline not inlined
27 #pragma warning(disable : 4786) // identifier was truncated to '255' characters in the debug information
28 #endif
29 #if _MSC_VER < 1400
30 #pragma warning(disable : 4511) // copy constructor could not be generated // #pragma warning(disable : 4512) // assignment operator could not be generated
31 #pragma warning(disable : 4512) // assignment operator could not be generated
32 #endif
33 #if _MSC_VER > 1400 && _MSC_VER <= 1900
34 // #pragma warning(disable : 4996)
35 // strcat: This function or variable may be unsafe
36 // GetVersion was declared deprecated
37 #endif
38
39#if _MSC_VER > 1200
40// -Wall warnings
41
42#if _MSC_VER <= 1600
43#pragma warning(disable : 4917) // 'OLE_HANDLE' : a GUID can only be associated with a class, interface or namespace
44#endif
45
46// #pragma warning(disable : 4061) // enumerator '' in switch of enum '' is not explicitly handled by a case label
47// #pragma warning(disable : 4266) // no override available for virtual member function from base ''; function is hidden
48#pragma warning(disable : 4625) // copy constructor was implicitly defined as deleted
49#pragma warning(disable : 4626) // assignment operator was implicitly defined as deleted
50#if _MSC_VER >= 1600 && _MSC_VER < 1920
51#pragma warning(disable : 4571) // Informational: catch(...) semantics changed since Visual C++ 7.1; structured exceptions (SEH) are no longer caught
52#endif
53#if _MSC_VER >= 1600
54#pragma warning(disable : 4365) // 'initializing' : conversion from 'int' to 'unsigned int', signed / unsigned mismatch
55#endif
56#if _MSC_VER < 1800
57// we disable the warning, if we don't use 'final' in class
58#pragma warning(disable : 4265) // class has virtual functions, but destructor is not virtual
59#endif
60
61#if _MSC_VER >= 1900
62#pragma warning(disable : 5026) // move constructor was implicitly defined as deleted
63#pragma warning(disable : 5027) // move assignment operator was implicitly defined as deleted
64#endif
65#if _MSC_VER >= 1912
66#pragma warning(disable : 5039) // pointer or reference to potentially throwing function passed to 'extern "C"' function under - EHc.Undefined behavior may occur if this function throws an exception.
67#endif
68#if _MSC_VER >= 1925
69// #pragma warning(disable : 5204) // 'ISequentialInStream' : class has virtual functions, but its trivial destructor is not virtual; instances of objects derived from this class may not be destructed correctly
70#endif
71#if _MSC_VER >= 1934
72// #pragma warning(disable : 5264) // const variable is not used
73#endif
74
75#endif // _MSC_VER > 1200
76#endif // _MSC_VER
77
78
79#if defined(_MSC_VER) // && !defined(__clang__)
80#define Z7_DECLSPEC_NOTHROW __declspec(nothrow)
81#elif defined(__clang__) || defined(__GNUC__)
82#define Z7_DECLSPEC_NOTHROW __attribute__((nothrow))
83#else
84#define Z7_DECLSPEC_NOTHROW
85#endif
86
87/*
88#if defined (_MSC_VER) && _MSC_VER >= 1900 \
89 || defined(__clang__) && __clang_major__ >= 6 \
90 || defined(__GNUC__) && __GNUC__ >= 6
91 #define Z7_noexcept noexcept
92#else
93 #define Z7_noexcept throw()
94#endif
95*/
96
97
98#if defined(__clang__)
99
100#if /* defined(_WIN32) && */ __clang_major__ >= 16
101#pragma GCC diagnostic ignored "-Wc++98-compat-pedantic"
102#endif
103
104#if __clang_major__ >= 4 && __clang_major__ < 12 && !defined(_WIN32)
105/*
106if compiled with new GCC libstdc++, GCC libstdc++ can use:
10713.2.0/include/c++/
108 <new> : #define _NEW
109 <stdlib.h> : #define _GLIBCXX_STDLIB_H 1
110*/
111#pragma GCC diagnostic ignored "-Wreserved-id-macro"
112#endif
113
114// noexcept, final, = delete
115#pragma GCC diagnostic ignored "-Wc++98-compat"
116#if __clang_major__ >= 4
117// throw() dynamic exception specifications are deprecated
118#pragma GCC diagnostic ignored "-Wdeprecated-dynamic-exception-spec"
119#endif
120
121#if __clang_major__ <= 6 // check it
122#pragma GCC diagnostic ignored "-Wsign-conversion"
123#endif
124
125#pragma GCC diagnostic ignored "-Wold-style-cast"
126#pragma GCC diagnostic ignored "-Wglobal-constructors"
127#pragma GCC diagnostic ignored "-Wexit-time-destructors"
128
129#if defined(Z7_LLVM_CLANG_VERSION) && __clang_major__ >= 18 // 18.1.0RC
130#pragma GCC diagnostic ignored "-Wswitch-default"
131#endif
132// #pragma GCC diagnostic ignored "-Wunused-private-field"
133// #pragma GCC diagnostic ignored "-Wnonportable-system-include-path"
134// #pragma GCC diagnostic ignored "-Wsuggest-override"
135// #pragma GCC diagnostic ignored "-Wsign-conversion"
136// #pragma GCC diagnostic ignored "-Winconsistent-missing-override"
137// #pragma GCC diagnostic ignored "-Wsuggest-destructor-override"
138// #pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
139// #pragma GCC diagnostic ignored "-Wdeprecated-copy-with-user-provided-dtor"
140// #pragma GCC diagnostic ignored "-Wdeprecated-copy-dtor"
141// #ifndef _WIN32
142// #pragma GCC diagnostic ignored "-Wweak-vtables"
143// #endif
144/*
145#if defined(Z7_GCC_VERSION) && (Z7_GCC_VERSION >= 40400) \
146 || defined(Z7_CLANG_VERSION) && (Z7_CLANG_VERSION >= 30000)
147// enumeration values not explicitly handled in switch
148#pragma GCC diagnostic ignored "-Wswitch-enum"
149#endif
150*/
151#endif // __clang__
152
153
154#ifdef __GNUC__
155// #pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor"
156#endif
157
158
159/* There is BUG in MSVC 6.0 compiler for operator new[]:
160 It doesn't check overflow, when it calculates size in bytes for allocated array.
161 So we can use Z7_ARRAY_NEW macro instead of new[] operator. */
162
163#if defined(_MSC_VER) && (_MSC_VER == 1200) && !defined(_WIN64)
164 #define Z7_ARRAY_NEW(p, T, size) p = new T[((size) > 0xFFFFFFFFu / sizeof(T)) ? 0xFFFFFFFFu / sizeof(T) : (size)];
165#else
166 #define Z7_ARRAY_NEW(p, T, size) p = new T[size];
167#endif
168
169#if (defined(__GNUC__) && (__GNUC__ >= 8))
170 #define Z7_ATTR_NORETURN __attribute__((noreturn))
171#elif (defined(__clang__) && (__clang_major__ >= 3))
172 #if __has_feature(cxx_attributes)
173 #define Z7_ATTR_NORETURN [[noreturn]]
174 #else
175 #define Z7_ATTR_NORETURN __attribute__((noreturn))
176 #endif
177#elif (defined(_MSC_VER) && (_MSC_VER >= 1900))
178 #define Z7_ATTR_NORETURN [[noreturn]]
179#else
180 #define Z7_ATTR_NORETURN
181#endif
182
183
184// final in "GCC 4.7.0"
185// In C++98 and C++03 code the alternative spelling __final can be used instead (this is a GCC extension.)
186
187#if defined (__cplusplus) && __cplusplus >= 201103L \
188 || defined(_MSC_VER) && _MSC_VER >= 1800 \
189 || defined(__clang__) && __clang_major__ >= 4 \
190 /* || defined(__GNUC__) && __GNUC__ >= 9 */
191 #define Z7_final final
192 #if defined(__clang__) && __cplusplus < 201103L
193 #pragma GCC diagnostic ignored "-Wc++11-extensions"
194 #endif
195#elif defined (__cplusplus) && __cplusplus >= 199711L \
196 && defined(__GNUC__) && __GNUC__ >= 4 && !defined(__clang__)
197 #define Z7_final __final
198#else
199 #define Z7_final
200 #if defined(__clang__) && __clang_major__ >= 4 \
201 || defined(__GNUC__) && __GNUC__ >= 4
202 #pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
203 #pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor"
204 #endif
205#endif
206
207#define Z7_class_final(c) class c Z7_final
208
209
210#if defined (__cplusplus) && __cplusplus >= 201103L \
211 || (defined(_MSC_VER) && _MSC_VER >= 1800)
212 #define Z7_CPP_IS_SUPPORTED_default
213 #define Z7_eq_delete = delete
214 // #define Z7_DECL_DEFAULT_COPY_CONSTRUCTOR_IF_SUPPORTED(c) c(const c& k) = default;
215#else
216 #define Z7_eq_delete
217 // #define Z7_DECL_DEFAULT_COPY_CONSTRUCTOR_IF_SUPPORTED(c)
218#endif
219
220
221#if defined(__cplusplus) && (__cplusplus >= 201103L) \
222 || defined(_MSC_VER) && (_MSC_VER >= 1400) /* && (_MSC_VER != 1600) */ \
223 || defined(__clang__) && __clang_major__ >= 4
224 #if defined(_MSC_VER) && (_MSC_VER == 1600) /* && (_MSC_VER != 1600) */
225 #pragma warning(disable : 4481) // nonstandard extension used: override specifier 'override'
226 #define Z7_DESTRUCTOR_override
227 #else
228 #define Z7_DESTRUCTOR_override override
229 #endif
230 #define Z7_override override
231#else
232 #define Z7_override
233 #define Z7_DESTRUCTOR_override
234#endif
235
236
237
238#define Z7_CLASS_NO_COPY(cls) \
239 private: \
240 cls(const cls &) Z7_eq_delete; \
241 cls &operator=(const cls &) Z7_eq_delete;
242
243class CUncopyable
244{
245protected:
246 CUncopyable() {} // allow constructor
247 // ~CUncopyable() {}
248 Z7_CLASS_NO_COPY(CUncopyable)
249};
250
251#define MY_UNCOPYABLE :private CUncopyable
252// #define MY_UNCOPYABLE
253
254
255// typedef void (*Z7_void_Function)(void);
256
257#if defined(__clang__) || defined(__GNUC__)
258#define Z7_CAST_FUNC(t, e) reinterpret_cast<t>(reinterpret_cast<Z7_void_Function>(e))
259#else
260#define Z7_CAST_FUNC(t, e) reinterpret_cast<t>(reinterpret_cast<void*>(e))
261// #define Z7_CAST_FUNC(t, e) reinterpret_cast<t>(e)
262#endif
263
264#define Z7_GET_PROC_ADDRESS(func_type, hmodule, func_name) \
265 Z7_CAST_FUNC(func_type, GetProcAddress(hmodule, func_name))
266
267// || defined(__clang__)
268// || defined(__GNUC__)
269
270#if defined(_MSC_VER) && (_MSC_VER >= 1400)
271#define Z7_DECLSPEC_NOVTABLE __declspec(novtable)
272#else
273#define Z7_DECLSPEC_NOVTABLE
274#endif
275
276#ifdef __clang__
277#define Z7_PURE_INTERFACES_BEGIN \
278_Pragma("GCC diagnostic push") \
279_Pragma("GCC diagnostic ignored \"-Wnon-virtual-dtor\"")
280_Pragma("GCC diagnostic ignored \"-Wweak-vtables\"")
281#define Z7_PURE_INTERFACES_END \
282_Pragma("GCC diagnostic pop")
283#else
284#define Z7_PURE_INTERFACES_BEGIN
285#define Z7_PURE_INTERFACES_END
286#endif
287
288// NewHandler.h and NewHandler.cpp redefine operator new() to throw exceptions, if compiled with old MSVC compilers
289#include "NewHandler.h"
290
291/*
292// #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
293#ifndef ARRAY_SIZE
294#define ARRAY_SIZE(a) Z7_ARRAY_SIZE(a)
295#endif
296*/
297
298#endif // ZIP7_INC_COMMON0_H
299
300
301
302// #define Z7_REDEFINE_NULL
303
304#if defined(Z7_REDEFINE_NULL) /* && (!defined(__clang__) || defined(_MSC_VER)) */
305
306// NULL is defined in <stddef.h>
307#include <stddef.h>
308#undef NULL
309
310#ifdef __cplusplus
311 #if defined (__cplusplus) && __cplusplus >= 201103L \
312 || (defined(_MSC_VER) && _MSC_VER >= 1800)
313 #define NULL nullptr
314 #else
315 #define NULL 0
316 #endif
317#else
318 #define NULL ((void *)0)
319#endif
320
321#else // Z7_REDEFINE_NULL
322
323#if defined(__clang__) && __clang_major__ >= 5
324#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
325#endif
326
327#endif // Z7_REDEFINE_NULL
328
329// for precompiler:
330// #include "MyWindows.h"