0030344: Coding Rules - suppress GCC compiler warnings -Wstrict-overflow on Standard_...
[occt.git] / src / Standard / Standard_Macro.hxx
CommitLineData
b311480e 1// Copyright (c) 1998-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
b1811c1d 15//! @file
16//! This file is intended to be the first file included to any
17//! Open CASCADE source. It defines platform-specific pre-processor
18//! macros necessary for correct compilation of Open CASCADE code.
7fd59977 19
20#ifndef _Standard_Macro_HeaderFile
21# define _Standard_Macro_HeaderFile
22
b1811c1d 23//! @def Standard_OVERRIDE
24//! Should be used in declarations of virtual methods overriden in the
25//! derived classes, to cause compilation error in the case if that virtual
26//! function disappears or changes its signature in the base class.
27//!
28//! Expands to C++11 keyword "override" on compilers that are known to
29//! suppot it; empty in other cases.
a3157439 30#if defined(__cplusplus) && (__cplusplus >= 201100L)
31 // part of C++11 standard
32 #define Standard_OVERRIDE override
33#elif defined(_MSC_VER) && (_MSC_VER >= 1700)
31b1749c 34 // MSVC extension since VS2012
a3157439 35 #define Standard_OVERRIDE override
36#else
37 #define Standard_OVERRIDE
38#endif
39
b1811c1d 40//! @def Standard_FALLTHROUGH
41//! Should be used in a switch statement immediately before a case label,
42//! if code associated with the previous case label may fall through to that
43//! next label (i.e. does not end with "break" or "return" etc.).
44//! This macro indicates that the fall through is intentional and should not be
45//! diagnosed by a compiler that warns on fallthrough.
46//!
47//! Expands to C++17 attribute statement "[[fallthrough]];" on compilers that
48//! declare support of C++17, or to "__attribute__((fallthrough));" on
49//! GCC 7+.
50#if defined(__cplusplus) && (__cplusplus >= 201703L)
51 // part of C++17 standard
52 #define Standard_FALLTHROUGH [[fallthrough]];
53#elif defined(__GNUC__) && (__GNUC__ >= 7)
54 // gcc 7+
55 #define Standard_FALLTHROUGH __attribute__((fallthrough));
56#else
57 #define Standard_FALLTHROUGH
58#endif
59
60//! @def Standard_UNUSED
61//! Macro for marking variables / functions as possibly unused
62//! so that compiler will not emit redundant "unused" warnings.
63//!
64//! Expands to "__attribute__((unused))" on GCC and CLang.
fb0b0531 65#if defined(__GNUC__) || defined(__clang__)
66 #define Standard_UNUSED __attribute__((unused))
67#else
68 #define Standard_UNUSED
69#endif
70
6f498847 71//! @def Standard_THREADLOCAL
72//! Define Standard_THREADLOCAL modifier as C++11 thread_local keyword where it is available.
73#if defined(__clang__)
74 // CLang version: standard CLang > 3.3 or XCode >= 8 (but excluding 32-bit ARM)
75 // Note: this has to be in separate #if to avoid failure of preprocessor on other platforms
76 #if __has_feature(cxx_thread_local)
77 #define Standard_THREADLOCAL thread_local
78 #endif
79#elif defined(__INTEL_COMPILER)
80 #if (defined(_MSC_VER) && _MSC_VER >= 1900 && __INTEL_COMPILER > 1400)
81 // requires msvcrt vc14+ (Visual Studio 2015+)
82 #define Standard_THREADLOCAL thread_local
83 #elif (!defined(_MSC_VER) && __INTEL_COMPILER > 1500)
84 #define Standard_THREADLOCAL thread_local
85 #endif
86#elif (defined(_MSC_VER) && _MSC_VER >= 1900)
87 // msvcrt coming with vc14+ (VS2015+)
88 #define Standard_THREADLOCAL thread_local
89#elif (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)))
90 // GCC >= 4.8
91 #define Standard_THREADLOCAL thread_local
92#endif
93
94#ifndef Standard_THREADLOCAL
95 #define Standard_THREADLOCAL
96#endif
97
b1811c1d 98//! @def Standard_DEPRECATED("message")
99//! Can be used in declaration of a method or a class to mark it as deprecated.
100//! Use of such method or class will cause compiler warning (if supported by
101//! compiler and unless disabled).
102//! If macro OCCT_NO_DEPRECATED is defined, Standard_DEPRECATED is defined empty.
8ddd25b8 103#ifdef OCCT_NO_DEPRECATED
104 #define Standard_DEPRECATED(theMsg)
105#else
106#if defined(_MSC_VER)
107 #define Standard_DEPRECATED(theMsg) __declspec(deprecated(theMsg))
108#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) || defined(__clang__))
109 #define Standard_DEPRECATED(theMsg) __attribute__((deprecated(theMsg)))
110#elif defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
111 #define Standard_DEPRECATED(theMsg) __attribute__((deprecated))
112#else
113 #define Standard_DEPRECATED(theMsg)
114#endif
115#endif
116
b1811c1d 117//! @def Standard_DISABLE_DEPRECATION_WARNINGS
118//! Disables warnings on use of deprecated features (see Standard_DEPRECATED),
119//! from the current point till appearance of Standard_ENABLE_DEPRECATION_WARNINGS macro.
120//! This is useful for sections of code kept for backward compatibility and scheduled for removal.
121//!
122//! @def Standard_ENABLE_DEPRECATION_WARNINGS
123//! Enables warnings on use of deprecated features previously disabled by
124//! Standard_DISABLE_DEPRECATION_WARNINGS.
60273f77 125#if defined(__ICL) || defined (__INTEL_COMPILER)
126 #define Standard_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:1478))
127 #define Standard_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop))
128#elif defined(_MSC_VER)
129 #define Standard_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:4996))
130 #define Standard_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop))
131#elif (defined(__GNUC__) && __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__)
132 // available since at least gcc 4.2 (maybe earlier), however only gcc 4.6+ supports this pragma inside the function body
133 // CLang also supports this gcc syntax (in addition to "clang diagnostic ignored")
134 #define Standard_DISABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
135 #define Standard_ENABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic warning \"-Wdeprecated-declarations\"")
136#else
137 #define Standard_DISABLE_DEPRECATION_WARNINGS
138 #define Standard_ENABLE_DEPRECATION_WARNINGS
139#endif
140
6286195c 141//! @def OCCT_NO_RVALUE_REFERENCE
142//! Disables methods and constructors that use rvalue references
143//! (C++11 move semantics) not supported by obsolete compilers.
144#if (defined(_MSC_VER) && (_MSC_VER < 1600))
145 #define OCCT_NO_RVALUE_REFERENCE
146#endif
147
d37ac0c2 148# ifdef _WIN32
7fd59977 149
150// We must be careful including windows.h: it is really poisonous stuff!
151// The most annoying are #defines of many identifiers that you could use in
152// normal code without knowing that Windows has its own knowledge of them...
153// So lets protect ourselves by switching OFF as much as possible of this in advance.
154// If someone needs more from windows.h, he is encouraged to #undef these symbols
155// or include windows.h prior to any OCCT stuff.
156// Note that we define each symbol to itself, so that it still can be used
157// e.g. as name of variable, method etc.
158#ifndef WIN32_LEAN_AND_MEAN
159#define WIN32_LEAN_AND_MEAN /* exclude extra Windows stuff */
160#endif
161#ifndef NOMINMAX
162#define NOMINMAX NOMINMAX /* avoid #define min() and max() */
163#endif
164#ifndef NOMSG
165#define NOMSG NOMSG /* avoid #define SendMessage etc. */
166#endif
167#ifndef NODRAWTEXT
168#define NODRAWTEXT NODRAWTEXT /* avoid #define DrawText etc. */
169#endif
170#ifndef NONLS
171#define NONLS NONLS /* avoid #define CompareString etc. */
172#endif
173#ifndef NOGDI
174#define NOGDI NOGDI /* avoid #define SetPrinter (winspool.h) etc. */
175#endif
176#ifndef NOSERVICE
177#define NOSERVICE NOSERVICE
178#endif
179#ifndef NOKERNEL
180#define NOKERNEL NOKERNEL
181#endif
182#ifndef NOUSER
183#define NOUSER NOUSER
184#endif
185#ifndef NOMCX
186#define NOMCX NOMCX
187#endif
188#ifndef NOIME
189#define NOIME NOIME
190#endif
191
d37ac0c2
TK
192#endif
193
b1811c1d 194//! @def Standard_EXPORT
195//! This macro should be used in declarations of public methods
196//! to ensure that they are exported from DLL on Windows and thus
197//! can be called from other (dependent) libraries or applications.
68df8478 198//!
199//! If macro OCCT_STATIC_BUILD is defined, then Standard_EXPORT
200//! is set to empty.
b1811c1d 201
68df8478 202# if defined(_WIN32) && !defined(OCCT_STATIC_BUILD) && !defined(HAVE_NO_DLL)
d37ac0c2
TK
203
204//======================================================
205// Windows-specific definitions
206//======================================================
207
208# ifndef Standard_EXPORT
209# define Standard_EXPORT __declspec( dllexport )
210// For global variables :
211# define Standard_EXPORTEXTERN __declspec( dllexport ) extern
212# define Standard_EXPORTEXTERNC extern "C" __declspec( dllexport )
213# endif /* Standard_EXPORT */
214
215# ifndef Standard_IMPORT
216# define Standard_IMPORT __declspec( dllimport ) extern
217# define Standard_IMPORTC extern "C" __declspec( dllimport )
218# endif /* Standard_IMPORT */
219
57c28b61 220# else /* UNIX */
7fd59977 221
222//======================================================
d37ac0c2 223// UNIX / static library definitions
7fd59977 224//======================================================
225
226# ifndef Standard_EXPORT
227# define Standard_EXPORT
228// For global variables :
229# define Standard_EXPORTEXTERN extern
230# define Standard_EXPORTEXTERNC extern "C"
231# endif /* Standard_EXPORT */
232
233# ifndef Standard_IMPORT
234# define Standard_IMPORT extern
235# define Standard_IMPORTC extern "C"
236# endif /* Standard_IMPORT */
237
238// Compatibility with old SUN compilers
239
240// This preprocessor directive is a kludge to get around
241// a bug in the Sun Workshop 5.0 compiler, it keeps the
242// /usr/include/memory.h file from being #included
243// with an incompatible extern "C" definition of memchr
244// October 18, 2000 <rboehne@ricardo-us.com>
245#if __SUNPRO_CC_COMPAT == 5
246#define _MEMORY_H
247#endif
248
57c28b61 249# endif /* _WIN32 */
7fd59977 250
b1811c1d 251//! @def OCCT_UWP
252//! This macro is defined on Windows platform in the case if the code
253//! is being compiled for UWP (Universal Windows Platform).
742cc8b0 254#if defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP
255 #define OCCT_UWP
256#else
257 #ifdef OCCT_UWP
258 #undef OCCT_UWP
259 #endif
260#endif
261
262#endif