RMF
Toggle main menu visibility
compiler_macros.h
Go to the documentation of this file.
1
/**
2
* \file RMF/compiler_macros.h
3
* \brief Various compiler workarounds
4
*
5
* Copyright 2007-2022 IMP Inventors. All rights reserved.
6
*/
7
8
#ifndef RMF_INTERNAL_COMPILER_MACROS_H
9
#define RMF_INTERNAL_COMPILER_MACROS_H
10
11
#define RMF_STRINGIFY(x) #x
12
13
// recommended by http://gcc.gnu.org/gcc/Function-Names.html
14
#if defined(_MSC_VER)
15
#define __func__ __FUNCTION__
16
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ < 199901L
17
#if __GNUC__ >= 2
18
#define __func__ __FUNCTION__
19
#else
20
#define __func__ "<unknown>"
21
#endif
22
#endif
23
24
// Deprecated; just use 'override' keyword instead
25
#define RMF_OVERRIDE override
26
27
// Deprecated; just use 'final' keyword instead
28
#define RMF_FINAL final
29
30
// Deprecated; just use 'noexcept' keyword instead
31
#define RMF_NOEXCEPT noexcept
32
#define RMF_CANEXCEPT noexcept(false)
33
34
#define RMF_CXX11_DEFAULT_COPY_CONSTRUCTOR(Name) \
35
Name(const Name &) = default; \
36
Name &operator=(const Name &) = default
37
38
#if defined(__clang__) || defined(__GNUC__)
39
#define RMF_PRAGMA(x) _Pragma(RMF_STRINGIFY(x))
40
#elif defined(_MSC_VER)
41
#define RMF_PRAGMA(x) __pragma(x)
42
#else
43
#define RMF_PRAGMA(x)
44
#endif
45
46
// Compiler-specific pragma support
47
#if defined(__clang__)
48
#define RMF_CLANG_PRAGMA(x) RMF_PRAGMA(clang x)
49
#define RMF_GCC_PRAGMA(x)
50
#define RMF_VC_PRAGMA(x)
51
52
#elif defined(__GNUC__)
53
#define RMF_CLANG_PRAGMA(x)
54
#define RMF_GCC_PRAGMA(x) RMF_PRAGMA(GCC x)
55
#define RMF_VC_PRAGMA(x)
56
57
#elif defined(_MSC_VER)
58
#define RMF_CLANG_PRAGMA(x)
59
#define RMF_GCC_PRAGMA(x)
60
#define RMF_VC_PRAGMA(x) RMF_PRAGMA(x)
61
62
#else
63
#define RMF_CLANG_PRAGMA(x)
64
#define RMF_GCC_PRAGMA(x)
65
#define RMF_VC_PRAGMA(x)
66
#endif
67
68
// Support for pushing and popping of warning state
69
#if defined(__clang__)
70
#define RMF_PUSH_WARNINGS RMF_CLANG_PRAGMA(diagnostic push)
71
#define RMF_POP_WARNINGS RMF_CLANG_PRAGMA(diagnostic pop)
72
73
#elif defined(__GNUC__)
74
#if __GNUC__ > 4 || __GNUC_MINOR__ >= 6
75
#define RMF_PUSH_WARNINGS RMF_GCC_PRAGMA(diagnostic push)
76
#define RMF_POP_WARNINGS RMF_GCC_PRAGMA(diagnostic pop)
77
78
#else
79
#define RMF_PUSH_WARNINGS
80
#define RMF_POP_WARNINGS
81
82
#endif
83
84
#elif defined(_MSC_VER)
85
#define RMF_PUSH_WARNINGS RMF_VC_PRAGMA(warning(push))
86
#define RMF_POP_WARNINGS RMF_VC_PRAGMA(warning(pop))
87
88
#else
89
#define RMF_PUSH_WARNINGS
90
#define RMF_POP_WARNINGS
91
92
#endif
93
94
// Turning on and off compiler-specific warnings
95
#ifdef __clang__
96
#define RMF_COMPILER_WARNINGS \
97
RMF_CLANG_PRAGMA(diagnostic warning "-Wall") \
98
RMF_CLANG_PRAGMA(diagnostic warning "-Wextra") \
99
RMF_CLANG_PRAGMA(diagnostic ignored "-Wconversion") \
100
RMF_CLANG_PRAGMA(diagnostic ignored "-Wc++11-extensions") \
101
RMF_CLANG_PRAGMA(diagnostic ignored "-Wc++11-compat") \
102
RMF_CLANG_PRAGMA(diagnostic ignored "-Wunused-member-function")
103
104
#elif defined(__GNUC__)
105
106
/*ret+=["-Wno-deprecated",
107
"-Wstrict-aliasing=2",
108
-fno-operator-names",]*/
109
#if __GNUC__ > 4 || __GNUC_MINOR__ >= 6
110
#define RMF_GCC_CXX0X_COMPAT \
111
RMF_GCC_PRAGMA(diagnostic ignored \
112
"-Wc++0x-compat")
113
#ifdef RMF_SWIG_WRAPPER
114
#define RMF_GCC_PROTOTYPES
115
#else
116
#define RMF_GCC_PROTOTYPES \
117
RMF_GCC_PRAGMA(diagnostic warning "-Wmissing-declarations")
118
#endif
119
120
#else
121
#define RMF_GCC_CXX0X_COMPAT
122
#define RMF_GCC_PROTOTYPES
123
#endif
124
125
// Warn about missing override on virtual methods if gcc is new enough
126
#if __GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)
127
#ifdef RMF_SWIG_WRAPPER
128
#define RMF_GCC_OVERRIDE
129
#else
130
#define RMF_GCC_OVERRIDE \
131
RMF_GCC_PRAGMA(diagnostic warning "-Wsuggest-override")
132
#endif
133
#else
134
#define RMF_GCC_OVERRIDE
135
#endif
136
137
#define RMF_COMPILER_WARNINGS \
138
RMF_GCC_PRAGMA(diagnostic warning "-Wall") \
139
RMF_GCC_PRAGMA(diagnostic warning "-Wextra") \
140
RMF_GCC_PRAGMA(diagnostic warning "-Winit-self") \
141
RMF_GCC_PRAGMA(diagnostic warning "-Wcast-align") \
142
RMF_GCC_PRAGMA(diagnostic warning "-Woverloaded-virtual") \
143
RMF_GCC_PRAGMA(diagnostic ignored "-Wconversion") \
144
RMF_GCC_PRAGMA(diagnostic warning "-Wundef") \
145
RMF_GCC_PROTOTYPES RMF_GCC_CXX0X_COMPAT RMF_GCC_OVERRIDE
146
147
#elif defined(_MSC_VER)
148
#define RMF_COMPILER_WARNINGS \
149
RMF_VC_PRAGMA(warning(disable : 4275; disable : 4251; disable : 4244; disable : 4068; disable : 4297))
150
151
#else
152
#define RMF_COMPILER_WARNINGS
153
154
#endif
155
156
#define RMF_ENABLE_WARNINGS RMF_PUSH_WARNINGS RMF_COMPILER_WARNINGS
157
158
#define RMF_DISABLE_WARNINGS RMF_POP_WARNINGS
159
160
#endif
/* RMF_INTERNAL_COMPILER_MACROS_H */