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