home
about
news
download
doc
source
systems
tests
bugs
contact
IMP Reference Guide
2.19.0
The Integrative Modeling Platform
IMP Manual
Reference Guide
Tutorial Index
Modules
Classes
Examples
include
IMP
version 2.19.0
compiler_macros.h
Go to the documentation of this file.
1
/**
2
* \file IMP/compiler_macros.h
3
* \brief Various compiler workarounds
4
*
5
* Copyright 2007-2022 IMP Inventors. All rights reserved.
6
*/
7
8
#ifndef IMPKERNEL_COMPILER_MACROS_H
9
#define IMPKERNEL_COMPILER_MACROS_H
10
11
#define IMP_STRINGIFY(x) #x
12
13
// recommended by http://gcc.gnu.org/gcc/Function-Names.html
14
#if defined(_MSC_VER)
15
#define IMP_CURRENT_FUNCTION __FUNCTION__
16
#define IMP_CURRENT_PRETTY_FUNCTION __FUNCTION__
17
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ < 199901L
18
#define IMP_CURRENT_FUNCTION __FUNCTION__
19
#define IMP_CURRENT_PRETTY_FUNCTION __PRETTY_FUNCTION__
20
#else
21
#define IMP_CURRENT_FUNCTION __func__
22
#define IMP_CURRENT_PRETTY_FUNCTION __PRETTY_FUNCTION__
23
#endif
24
25
#ifndef IMP_DOXYGEN
26
#ifdef __GNUC__
27
#define IMP_NO_SIDEEFFECTS __attribute__((pure))
28
#define IMP_UNUSED_FUNCTION __attribute__((unused))
29
#define IMP_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
30
#define IMP_RESTRICT __restrict__
31
32
#else
33
#define IMP_NO_SIDEEFFECTS
34
#define IMP_UNUSED_FUNCTION
35
#define IMP_WARN_UNUSED_RESULT
36
#define IMP_RESTRICT
37
#endif
38
39
#else
40
//! Use this to label a function with no side effects
41
/** \advancedmethod */
42
#define IMP_NO_SIDEEFFECTS
43
//! Use this to make the compiler (possibly) warn if the result is not used
44
/** \advancedmethod */
45
#define IMP_WARN_UNUSED_RESULT
46
//! Label a function that is never called
47
/** \advancedmethod */
48
#define IMP_UNUSED_FUNCTION
49
//! restrict means that a variable is not aliased with this function
50
#define IMP_RESTRICT
51
#endif
52
53
54
#ifdef IMP_DOXYGEN
55
//! Have the compiler report an error if anything overrides this method
56
#define IMP_SWIG_FINAL
57
#else
58
#if defined(IMP_SWIG_WRAPPER) || defined(SWIG)
59
#define IMP_SWIG_FINAL
60
#else
61
#define IMP_SWIG_FINAL final
62
#endif
63
#endif
64
65
// Deprecated: just use 'noexcept' directly
66
#define IMP_NOEXCEPT noexcept
67
#define IMP_CXX11_DEFAULT_COPY_CONSTRUCTOR(Name) \
68
Name(const Name &) = default; \
69
Name &operator=(const Name &) = default
70
71
#if defined(__clang__) || defined(__GNUC__)
72
#define IMP_PRAGMA(x) _Pragma(IMP_STRINGIFY(x))
73
74
#if defined(__clang__)
75
#define IMP_CLANG_PRAGMA(x) IMP_PRAGMA(clang x)
76
#define IMP_GCC_PRAGMA(x)
77
#define IMP_VC_PRAGMA(x)
78
#else
79
#define IMP_CLANG_PRAGMA(x)
80
#define IMP_GCC_PRAGMA(x) IMP_PRAGMA(GCC x)
81
#define IMP_VC_PRAGMA(x)
82
#endif
83
84
#elif defined(_MSC_VER)
85
#define IMP_PRAGMA(x) __pragma(x)
86
#define IMP_CLANG_PRAGMA(x)
87
#define IMP_GCC_PRAGMA(x)
88
#define IMP_VC_PRAGMA(x) IMP_PRAGMA(x)
89
90
#else
91
#define IMP_PRAGMA(x)
92
#define IMP_CLANG_PRAGMA(x)
93
#define IMP_GCC_PRAGMA(x)
94
#define IMP_VC_PRAGMA(x)
95
#endif
96
97
#ifdef __clang__
98
99
#define IMP_GCC_PUSH_POP(x)
100
101
#define IMP_COMPILER_ENABLE_WARNINGS \
102
IMP_CLANG_PRAGMA(diagnostic push) \
103
IMP_CLANG_PRAGMA(diagnostic warning "-Wall") \
104
IMP_CLANG_PRAGMA(diagnostic warning "-Wextra") \
105
IMP_CLANG_PRAGMA(diagnostic warning "-Weverything") \
106
IMP_CLANG_PRAGMA(diagnostic ignored "-Wconversion") \
107
IMP_CLANG_PRAGMA(diagnostic ignored "-Wc++11-extensions") \
108
IMP_CLANG_PRAGMA(diagnostic ignored "-Wc++11-compat") \
109
IMP_CLANG_PRAGMA(diagnostic warning "-Wsign-compare") \
110
IMP_CLANG_PRAGMA(diagnostic ignored "-Wunused-member-function")
111
112
#define IMP_HELPER_MACRO_PUSH_WARNINGS IMP_CLANG_PRAGMA(diagnostic push)
113
114
#define IMP_HELPER_MACRO_POP_WARNINGS IMP_CLANG_PRAGMA(diagnostic pop)
115
116
#define IMP_COMPILER_DISABLE_WARNINGS IMP_CLANG_PRAGMA(diagnostic pop)
117
118
#elif defined(__GNUC__)
119
120
/*ret+=["-Wno-deprecated",
121
"-Wstrict-aliasing=2",
122
-fno-operator-names",]*/
123
#if __GNUC__ > 4 || __GNUC_MINOR__ >= 6
124
#define IMP_GCC_PUSH_POP(x) IMP_PRAGMA(x)
125
#define IMP_GCC_CXX0X_COMPAT \
126
IMP_GCC_PRAGMA(diagnostic ignored \
127
"-Wc++0x-compat")
128
#ifdef IMP_SWIG_WRAPPER
129
#define IMP_GCC_PROTOTYPES
130
#else
131
#define IMP_GCC_PROTOTYPES \
132
IMP_GCC_PRAGMA(diagnostic warning "-Wmissing-declarations")
133
#endif
134
135
#define IMP_HELPER_MACRO_PUSH_WARNINGS IMP_GCC_PRAGMA(diagnostic push)
136
137
#define IMP_HELPER_MACRO_POP_WARNINGS IMP_GCC_PRAGMA(diagnostic pop)
138
139
#else
140
#define IMP_GCC_PUSH_POP(x)
141
#define IMP_GCC_CXX0X_COMPAT
142
#define IMP_GCC_PROTOTYPES
143
#define IMP_HELPER_MACRO_PUSH_WARNINGS
144
#define IMP_HELPER_MACRO_POP_WARNINGS
145
#endif
146
147
// Warn about missing override on virtual methods if gcc is new enough
148
#if __GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)
149
#ifdef IMP_SWIG_WRAPPER
150
#define IMP_GCC_OVERRIDE
151
#else
152
#define IMP_GCC_OVERRIDE \
153
IMP_GCC_PRAGMA(diagnostic warning "-Wsuggest-override")
154
#endif
155
#else
156
#define IMP_GCC_OVERRIDE
157
#endif
158
159
#define IMP_COMPILER_ENABLE_WARNINGS \
160
IMP_GCC_PUSH_POP(GCC diagnostic push) \
161
IMP_GCC_PRAGMA(diagnostic warning "-Wall") \
162
IMP_GCC_PRAGMA(diagnostic warning "-Wextra") \
163
IMP_GCC_PRAGMA(diagnostic warning "-Winit-self") \
164
IMP_GCC_PRAGMA(diagnostic warning "-Wcast-align") \
165
IMP_GCC_PRAGMA(diagnostic warning "-Woverloaded-virtual") \
166
IMP_GCC_PRAGMA(diagnostic warning "-Wdeprecated-declarations") \
167
IMP_GCC_PRAGMA(diagnostic warning "-Wundef") \
168
IMP_GCC_PROTOTYPES IMP_GCC_CXX0X_COMPAT IMP_GCC_OVERRIDE
169
170
#define IMP_COMPILER_DISABLE_WARNINGS IMP_GCC_PUSH_POP(GCC diagnostic pop)
171
172
#elif defined(_MSC_VER)
173
#define IMP_GCC_PUSH_POP(x)
174
175
#define IMP_COMPILER_ENABLE_WARNINGS \
176
IMP_VC_PRAGMA(warning(push)) IMP_VC_PRAGMA(warning(disable : 4273)) \
177
IMP_VC_PRAGMA(warning(disable : 4244)) \
178
IMP_VC_PRAGMA(warning(disable : 4068)) \
179
IMP_VC_PRAGMA(warning(disable : 4297))
180
181
#define IMP_COMPILER_DISABLE_WARNINGS IMP_VC_PRAGMA(warning(pop))
182
183
#define IMP_HELPER_MACRO_PUSH_WARNINGS
184
#define IMP_HELPER_MACRO_POP_WARNINGS
185
186
#else
187
#define IMP_COMPILER_ENABLE_WARNINGS
188
#define IMP_COMPILER_DISABLE_WARNINGS
189
#define IMP_HELPER_MACRO_PUSH_WARNINGS
190
#define IMP_HELPER_MACRO_POP_WARNINGS
191
#endif
192
193
#if defined(__GNUC__) || defined(__clang__)
194
#define IMP_DEPRECATED_ATTRIBUTE __attribute__((deprecated))
195
#else
196
#define IMP_DEPRECATED_ATTRIBUTE
197
#endif
198
199
// likely/unlikely macros provide manual optimization of branch
200
// prediction - particularly useful for rare cases in scoring
201
// functions, but use only if you know what you're doing cause
202
// profiler is better at this in 99.9% of times:
203
#if defined(__GNUC__)
204
#define IMP_LIKELY(x) __builtin_expect (!!(x), 1)
205
#define IMP_UNLIKELY(x) __builtin_expect (!!(x), 0)
206
#else // ifdef __GNUC__
207
#define IMP_LIKELY(x) x
208
#define IMP_UNLIKELY(x) x
209
#endif // ifdef __GNUC__
210
211
#if defined(_MSC_VER)
212
//! platform independent C open() method
213
#define IMP_C_OPEN _open
214
#define IMP_C_CLOSE _close
215
//! platform independent C flag for open() method
216
#define IMP_C_OPEN_FLAG(x) _##x
217
#define IMP_C_OPEN_BINARY _O_BINARY
218
#else
219
//! platform independent C open() method
220
#define IMP_C_OPEN open
221
#define IMP_C_CLOSE close
222
//! platform independent C flag for open() method
223
#define IMP_C_OPEN_FLAG(x) x
224
#define IMP_C_OPEN_BINARY 0
225
#endif
226
227
#endif
/* IMPKERNEL_COMPILER_MACROS_H */