0029151: GCC 7.1 warnings "this statement may fall through" [-Wimplicit-fallthrough=]
[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
b1811c1d 71//! @def Standard_DEPRECATED("message")
72//! Can be used in declaration of a method or a class to mark it as deprecated.
73//! Use of such method or class will cause compiler warning (if supported by
74//! compiler and unless disabled).
75//! If macro OCCT_NO_DEPRECATED is defined, Standard_DEPRECATED is defined empty.
8ddd25b8 76#ifdef OCCT_NO_DEPRECATED
77 #define Standard_DEPRECATED(theMsg)
78#else
79#if defined(_MSC_VER)
80 #define Standard_DEPRECATED(theMsg) __declspec(deprecated(theMsg))
81#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) || defined(__clang__))
82 #define Standard_DEPRECATED(theMsg) __attribute__((deprecated(theMsg)))
83#elif defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
84 #define Standard_DEPRECATED(theMsg) __attribute__((deprecated))
85#else
86 #define Standard_DEPRECATED(theMsg)
87#endif
88#endif
89
b1811c1d 90//! @def Standard_DISABLE_DEPRECATION_WARNINGS
91//! Disables warnings on use of deprecated features (see Standard_DEPRECATED),
92//! from the current point till appearance of Standard_ENABLE_DEPRECATION_WARNINGS macro.
93//! This is useful for sections of code kept for backward compatibility and scheduled for removal.
94//!
95//! @def Standard_ENABLE_DEPRECATION_WARNINGS
96//! Enables warnings on use of deprecated features previously disabled by
97//! Standard_DISABLE_DEPRECATION_WARNINGS.
60273f77 98#if defined(__ICL) || defined (__INTEL_COMPILER)
99 #define Standard_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:1478))
100 #define Standard_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop))
101#elif defined(_MSC_VER)
102 #define Standard_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:4996))
103 #define Standard_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop))
104#elif (defined(__GNUC__) && __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__)
105 // available since at least gcc 4.2 (maybe earlier), however only gcc 4.6+ supports this pragma inside the function body
106 // CLang also supports this gcc syntax (in addition to "clang diagnostic ignored")
107 #define Standard_DISABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
108 #define Standard_ENABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic warning \"-Wdeprecated-declarations\"")
109#else
110 #define Standard_DISABLE_DEPRECATION_WARNINGS
111 #define Standard_ENABLE_DEPRECATION_WARNINGS
112#endif
113
d37ac0c2 114# ifdef _WIN32
7fd59977 115
116// We must be careful including windows.h: it is really poisonous stuff!
117// The most annoying are #defines of many identifiers that you could use in
118// normal code without knowing that Windows has its own knowledge of them...
119// So lets protect ourselves by switching OFF as much as possible of this in advance.
120// If someone needs more from windows.h, he is encouraged to #undef these symbols
121// or include windows.h prior to any OCCT stuff.
122// Note that we define each symbol to itself, so that it still can be used
123// e.g. as name of variable, method etc.
124#ifndef WIN32_LEAN_AND_MEAN
125#define WIN32_LEAN_AND_MEAN /* exclude extra Windows stuff */
126#endif
127#ifndef NOMINMAX
128#define NOMINMAX NOMINMAX /* avoid #define min() and max() */
129#endif
130#ifndef NOMSG
131#define NOMSG NOMSG /* avoid #define SendMessage etc. */
132#endif
133#ifndef NODRAWTEXT
134#define NODRAWTEXT NODRAWTEXT /* avoid #define DrawText etc. */
135#endif
136#ifndef NONLS
137#define NONLS NONLS /* avoid #define CompareString etc. */
138#endif
139#ifndef NOGDI
140#define NOGDI NOGDI /* avoid #define SetPrinter (winspool.h) etc. */
141#endif
142#ifndef NOSERVICE
143#define NOSERVICE NOSERVICE
144#endif
145#ifndef NOKERNEL
146#define NOKERNEL NOKERNEL
147#endif
148#ifndef NOUSER
149#define NOUSER NOUSER
150#endif
151#ifndef NOMCX
152#define NOMCX NOMCX
153#endif
154#ifndef NOIME
155#define NOIME NOIME
156#endif
157
d37ac0c2
TK
158#endif
159
b1811c1d 160//! @def Standard_EXPORT
161//! This macro should be used in declarations of public methods
162//! to ensure that they are exported from DLL on Windows and thus
163//! can be called from other (dependent) libraries or applications.
164
d37ac0c2
TK
165# if defined(_WIN32) && !defined(HAVE_NO_DLL)
166
167//======================================================
168// Windows-specific definitions
169//======================================================
170
171# ifndef Standard_EXPORT
172# define Standard_EXPORT __declspec( dllexport )
173// For global variables :
174# define Standard_EXPORTEXTERN __declspec( dllexport ) extern
175# define Standard_EXPORTEXTERNC extern "C" __declspec( dllexport )
176# endif /* Standard_EXPORT */
177
178# ifndef Standard_IMPORT
179# define Standard_IMPORT __declspec( dllimport ) extern
180# define Standard_IMPORTC extern "C" __declspec( dllimport )
181# endif /* Standard_IMPORT */
182
57c28b61 183# else /* UNIX */
7fd59977 184
185//======================================================
d37ac0c2 186// UNIX / static library definitions
7fd59977 187//======================================================
188
189# ifndef Standard_EXPORT
190# define Standard_EXPORT
191// For global variables :
192# define Standard_EXPORTEXTERN extern
193# define Standard_EXPORTEXTERNC extern "C"
194# endif /* Standard_EXPORT */
195
196# ifndef Standard_IMPORT
197# define Standard_IMPORT extern
198# define Standard_IMPORTC extern "C"
199# endif /* Standard_IMPORT */
200
201// Compatibility with old SUN compilers
202
203// This preprocessor directive is a kludge to get around
204// a bug in the Sun Workshop 5.0 compiler, it keeps the
205// /usr/include/memory.h file from being #included
206// with an incompatible extern "C" definition of memchr
207// October 18, 2000 <rboehne@ricardo-us.com>
208#if __SUNPRO_CC_COMPAT == 5
209#define _MEMORY_H
210#endif
211
57c28b61 212# endif /* _WIN32 */
7fd59977 213
214//======================================================
215// Other
216//======================================================
217
218# ifndef __Standard_API
a3157439 219# if !defined(_WIN32) || defined(__Standard_DLL) || defined(__FSD_DLL) || defined(__MMgt_DLL) || defined(__OSD_DLL) || defined(__Plugin_DLL) || defined(__Quantity_DLL) || defined(__Resource_DLL) || defined(__SortTools_DLL) || defined(__StdFail_DLL) || defined(__Storage_DLL) || defined(__TColStd_DLL) || defined(__TCollection_DLL) || defined(__TShort_DLL) || defined(__Units_DLL) || defined(__UnitsAPI_DLL) || defined(__Dico_DLL)
7fd59977 220# define __Standard_API Standard_EXPORT
221# define __Standard_APIEXTERN Standard_EXPORTEXTERN
222# else
223# define __Standard_API Standard_IMPORT
224# define __Standard_APIEXTERN Standard_IMPORT
225# endif // __Standard_DLL
7fd59977 226# endif // __Standard_API
227
b1811c1d 228//! @def OCCT_UWP
229//! This macro is defined on Windows platform in the case if the code
230//! is being compiled for UWP (Universal Windows Platform).
742cc8b0 231#if defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP
232 #define OCCT_UWP
233#else
234 #ifdef OCCT_UWP
235 #undef OCCT_UWP
236 #endif
237#endif
238
239#endif