IMP
2.2.0
The Integrative Modeling Platform
IMP Mainpage
All IMP Modules
Related Pages
Modules
Namespaces
Classes
Files
Examples
Indexes
File List
File Members
base/compiler_macros.h
Go to the documentation of this file.
1
/**
2
* \file IMP/base/compiler_macros.h
3
* \brief Various compiler workarounds
4
*
5
* Copyright 2007-2014 IMP Inventors. All rights reserved.
6
*/
7
8
#ifndef IMPBASE_COMPILER_MACROS_H
9
#define IMPBASE_COMPILER_MACROS_H
10
11
#include <boost/config.hpp>
12
#include <boost/version.hpp>
13
#if defined(BOOST_NO_CXX11_RANGE_BASED_FOR) || BOOST_VERSION <= 104100
14
#include <boost/foreach.hpp>
15
#define IMP_FOREACH(v, r) BOOST_FOREACH(v, r)
16
#else
17
/** Use C++11 range-based for if available or BOOST_FOREACH if not. */
18
#define IMP_FOREACH(v, r) for (v : r)
19
#endif
20
21
#include <boost/detail/endian.hpp>
22
23
#define IMP_STRINGIFY(x) #x
24
25
// recommended by http://gcc.gnu.org/gcc/Function-Names.html
26
#if defined(_MSC_VER)
27
#define IMP_CURRENT_FUNCTION __FUNCTION__
28
#define IMP_CURRENT_PRETTY_FUNCTION __FUNCTION__
29
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ < 199901L
30
#define IMP_CURRENT_FUNCTION __FUNCTION__
31
#define IMP_CURRENT_PRETTY_FUNCTION __PRETTY_FUNCTION__
32
#else
33
#define IMP_CURRENT_FUNCTION __func__
34
#define IMP_CURRENT_PRETTY_FUNCTION __PRETTY_FUNCTION__
35
#endif
36
37
#ifndef IMP_DOXYGEN
38
#ifdef __GNUC__
39
//! Use this to label a function with no side effects
40
/** \advanced */
41
#define IMP_NO_SIDEEFFECTS __attribute__((pure))
42
//! Use this to make the compiler (possibly) warn if the result is not used
43
/** \advanced */
44
#define IMP_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
45
//! restrict means that a variable is not aliased with this function
46
#define IMP_RESTRICT __restrict__
47
48
#else
49
#define IMP_NO_SIDEEFFECTS
50
#define IMP_WARN_UNUSED_RESULT
51
#define IMP_RESTRICT
52
#endif
53
54
#endif
55
56
#ifdef __clang__
57
#define IMP_COMPILER_HAS_OVERRIDE 1
58
#elif defined(__GNUC__) && __cplusplus >= 201103L
59
// probably should be finer here
60
#define IMP_COMPILER_HAS_OVERRIDE 1
61
#else
62
#define IMP_COMPILER_HAS_OVERRIDE 0
63
#endif
64
65
#if IMP_COMPILER_HAS_OVERRIDE
66
#define IMP_OVERRIDE override
67
#else
68
#define IMP_OVERRIDE
69
#endif
70
71
#if defined(IMP_SWIG_WRAPPER)
72
#define IMP_COMPILER_HAS_FINAL 0
73
#elif defined(__clang__)
74
#define IMP_COMPILER_HAS_FINAL 1
75
#elif defined(__GNUC__) && __cplusplus >= 201103L
76
// probably should be finer here
77
#define IMP_COMPILER_HAS_FINAL 1
78
#else
79
#define IMP_COMPILER_HAS_FINAL 0
80
#endif
81
82
#if IMP_COMPILER_HAS_FINAL
83
#define IMP_FINAL final
84
#else
85
#define IMP_FINAL
86
#endif
87
88
#if defined(__GNUC__) && __cplusplus >= 201103L
89
#define IMP_HAS_NOEXCEPT 1
90
#elif defined(__clang__) && defined(__has_feature)
91
#define IMP_HAS_NOEXCEPT __has_feature(cxx_noexcept)
92
#else
93
#define IMP_HAS_NOEXCEPT 0
94
#endif
95
96
#if IMP_HAS_NOEXCEPT
97
#define IMP_NOEXCEPT noexcept
98
#define IMP_CXX11_DEFAULT_COPY_CONSTRUCTOR(Name) \
99
Name(const Name &) = default; \
100
Name &operator=(const Name &) = default
101
#else
102
// probably should be finer here
103
#define IMP_NOEXCEPT throw()
104
#define IMP_CXX11_DEFAULT_COPY_CONSTRUCTOR(Name)
105
#endif
106
107
#if defined(__clang__) || defined(__GNUC__)
108
#define IMP_PRAGMA(x) _Pragma(IMP_STRINGIFY(x))
109
110
#if defined(__clang__)
111
#define IMP_CLANG_PRAGMA(x) IMP_PRAGMA(clang x)
112
#define IMP_GCC_PRAGMA(x)
113
#define IMP_VC_PRAGMA(x)
114
#else
115
#define IMP_CLANG_PRAGMA(x)
116
#define IMP_GCC_PRAGMA(x) IMP_PRAGMA(GCC x)
117
#define IMP_VC_PRAGMA(x)
118
#endif
119
120
#elif defined(_MSC_VER)
121
#define IMP_PRAGMA(x) __pragma(x)
122
#define IMP_CLANG_PRAGMA(x)
123
#define IMP_GCC_PRAGMA(x)
124
#define IMP_VC_PRAGMA(x) IMP_PRAGMA(x)
125
126
#else
127
#define IMP_PRAGMA(x)
128
#define IMP_CLANG_PRAGMA(x)
129
#define IMP_GCC_PRAGMA(x)
130
#define IMP_VC_PRAGMA(x)
131
#endif
132
133
#ifndef IMP_DOXYGEN
134
#if defined(BOOST_LITTLE_ENDIAN)
135
#define IMP_LITTLE_ENDIAN
136
#else
137
#define IMP_BIG_ENDIAN
138
#endif
139
#endif
140
141
#ifdef __clang__
142
143
#define IMP_GCC_PUSH_POP(x)
144
145
#define IMP_COMPILER_ENABLE_WARNINGS \
146
IMP_CLANG_PRAGMA(diagnostic push) \
147
IMP_CLANG_PRAGMA(diagnostic warning "-Wall") \
148
IMP_CLANG_PRAGMA(diagnostic warning "-Wextra") \
149
IMP_CLANG_PRAGMA(diagnostic warning "-Weverything") \
150
IMP_CLANG_PRAGMA(diagnostic ignored "-Wconversion") \
151
IMP_CLANG_PRAGMA(diagnostic ignored "-Wc++11-extensions") \
152
IMP_CLANG_PRAGMA(diagnostic ignored "-Wc++11-compat") \
153
IMP_CLANG_PRAGMA(diagnostic warning "-Wsign-compare") \
154
IMP_CLANG_PRAGMA(diagnostic ignored "-Wunused-member-function")
155
156
#define IMP_HELPER_MACRO_PUSH_WARNINGS IMP_CLANG_PRAGMA(diagnostic push)
157
158
#define IMP_HELPER_MACRO_POP_WARNINGS IMP_CLANG_PRAGMA(diagnostic pop)
159
160
#define IMP_COMPILER_DISABLE_WARNINGS IMP_CLANG_PRAGMA(diagnostic pop)
161
162
#elif defined(__GNUC__)
163
164
/*ret+=["-Wno-deprecated",
165
"-Wstrict-aliasing=2",
166
-fno-operator-names",]*/
167
#if __GNUC__ > 4 || __GNUC_MINOR__ >= 6
168
#define IMP_GCC_PUSH_POP(x) IMP_PRAGMA(x)
169
#define IMP_GCC_CXX0X_COMPAT \
170
IMP_GCC_PRAGMA(diagnostic ignored \
171
"-Wc++0x-compa" \
172
"t")
173
#define IMP_GCC_PROTOTYPES \
174
IMP_GCC_PRAGMA(diagnostic warning "-Wmissing-declarations")
175
176
#define IMP_HELPER_MACRO_PUSH_WARNINGS IMP_GCC_PRAGMA(diagnostic push)
177
178
#define IMP_HELPER_MACRO_POP_WARNINGS IMP_GCC_PRAGMA(diagnostic pop)
179
180
#else
181
#define IMP_GCC_PUSH_POP(x)
182
#define IMP_GCC_CXX0X_COMPAT
183
#define IMP_GCC_PROTOTYPES
184
#define IMP_HELPER_MACRO_PUSH_WARNINGS
185
#define IMP_HELPER_MACRO_POP_WARNINGS
186
#endif
187
188
#define IMP_COMPILER_ENABLE_WARNINGS \
189
IMP_GCC_PUSH_POP(GCC diagnostic push) \
190
IMP_GCC_PRAGMA(diagnostic warning "-Wall") \
191
IMP_GCC_PRAGMA(diagnostic warning "-Wextra") \
192
IMP_GCC_PRAGMA(diagnostic warning "-Winit-self") \
193
IMP_GCC_PRAGMA(diagnostic warning "-Wcast-align") \
194
IMP_GCC_PRAGMA(diagnostic warning "-Woverloaded-virtual") \
195
IMP_GCC_PRAGMA(diagnostic warning "-Wdeprecated-declarations") \
196
IMP_GCC_PRAGMA(diagnostic warning \
197
"-Wundef") IMP_GCC_PROTOTYPES IMP_GCC_CXX0X_COMPAT
198
199
#define IMP_COMPILER_DISABLE_WARNINGS IMP_GCC_PUSH_POP(GCC diagnostic pop)
200
201
#elif defined(_MSC_VER)
202
#define IMP_GCC_PUSH_POP(x)
203
204
#define IMP_COMPILER_ENABLE_WARNINGS \
205
IMP_VC_PRAGMA(warning(push)) IMP_VC_PRAGMA(warning(disable : 4273)) \
206
IMP_VC_PRAGMA(warning(disable : 4244)) \
207
IMP_VC_PRAGMA(warning(disable : 4068)) \
208
IMP_VC_PRAGMA(warning(disable : 4297))
209
210
#define IMP_COMPILER_DISABLE_WARNINGS IMP_VC_PRAGMA(warning(pop))
211
212
#define IMP_HELPER_MACRO_PUSH_WARNINGS
213
#define IMP_HELPER_MACRO_POP_WARNINGS
214
215
#else
216
#define IMP_COMPILER_ENABLE_WARNINGS
217
#define IMP_COMPILER_DISABLE_WARNINGS
218
#define IMP_HELPER_MACRO_PUSH_WARNINGS
219
#define IMP_HELPER_MACRO_POP_WARNINGS
220
#endif
221
222
#if defined(__GNUC__) || defined(__clang__)
223
#define IMP_DEPRECATED_ATTRIBUTE __attribute__((deprecated))
224
#else
225
#define IMP_DEPRECATED_ATTRIBUTE
226
#endif
227
228
#endif
/* IMPBASE_COMPILER_MACROS_H */