Ignition Common

API Reference

3.0.0
detail/SuppressWarning.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 
19 #ifndef IGNITION_COMMON_DETAIL_SUPPRESSWARNING_HH_
20 #define IGNITION_COMMON_DETAIL_SUPPRESSWARNING_HH_
21 
22 #define DETAIL_IGN_COMMON_STRINGIFY(x) #x
23 
24 /* cppcheck-suppress */
25 
26 // BEGIN / FINISH Macros
27 
28 #if defined __clang__
29 
30  #define DETAIL_IGN_COMMON_BEGIN_WARN_SUP_PUSH \
31  _Pragma("clang diagnostic push")
32 
33 
34  #define DETAIL_IGN_COMMON_WARN_SUP_HELPER_2(w) \
35  DETAIL_IGN_COMMON_STRINGIFY(clang diagnostic ignored w)
36 
37 
38  #define DETAIL_IGN_COMMON_WARN_SUP_HELPER(w) \
39  _Pragma(DETAIL_IGN_COMMON_WARN_SUP_HELPER_2(w))
40 
41 
42  #define DETAIL_IGN_COMMON_WARN_RESUME \
43  _Pragma("clang diagnostic pop")
44 
45 
46 #elif defined __GNUC__
47 
48  // NOTE: clang will define both __clang__ and __GNUC__, and it seems that
49  // clang will gladly accept GCC pragmas. Even so, if we want the pragmas to
50  // target the "correct" compiler, we should check if __clang__ is defined
51  // before checking whether __GNUC__ is defined.
52 
53  #define DETAIL_IGN_COMMON_BEGIN_WARN_SUP_PUSH \
54  _Pragma("GCC diagnostic push")
55 
56 
57  #define DETAIL_IGN_COMMON_WARN_SUP_HELPER_2(w) \
58  DETAIL_IGN_COMMON_STRINGIFY(GCC diagnostic ignored w)
59 
60 
61  #define DETAIL_IGN_COMMON_WARN_SUP_HELPER(w) \
62  _Pragma(DETAIL_IGN_COMMON_WARN_SUP_HELPER_2(w))
63 
64 
65  #define DETAIL_IGN_COMMON_WARN_RESUME \
66  _Pragma("GCC diagnostic pop")
67 
68 
69 #elif defined _MSC_VER
70 
71 
72  #define DETAIL_IGN_COMMON_BEGIN_WARN_SUP_PUSH \
73  __pragma(warning(push))
74 
75 
76  #define DETAIL_IGN_COMMON_WARN_SUP_HELPER(w) \
77  __pragma(warning(disable: w))
78 
79 
80  #define DETAIL_IGN_COMMON_WARN_RESUME \
81  __pragma(warning(pop))
82 
83 
84 #else
85 
86  // Make these into no-ops if we don't know the type of compiler
87 
88  #define DETAIL_IGN_COMMON_BEGIN_WARN_SUP_PUSH
89 
90 
91  #define DETAIL_IGN_COMMON_WARN_SUP_HELPER(w)
92 
93 
94  #define DETAIL_IGN_COMMON_WARN_RESUME
95 
96 
97 #endif
98 
99 
100 #define DETAIL_IGN_COMMON_BEGIN_WARNING_SUPPRESSION(warning_token) \
101  DETAIL_IGN_COMMON_BEGIN_WARN_SUP_PUSH \
102  DETAIL_IGN_COMMON_WARN_SUP_HELPER(warning_token)
103 
104 
105 
106 // Warning Tokens
107 #if defined __GNUC__ || defined __clang__
108 
109  #define DETAIL_IGN_COMMON_WARN_IGNORE__DELETE_NON_VIRTUAL_DESTRUCTOR \
110  DETAIL_IGN_COMMON_BEGIN_WARNING_SUPPRESSION("-Wdelete-non-virtual-dtor")
111 
112  #define DETAIL_IGN_COMMON_WARN_RESUME__DELETE_NON_VIRTUAL_DESTRUCTOR \
113  DETAIL_IGN_COMMON_WARN_RESUME
114 
115 
116  // There is no analogous warning for this in GCC or Clang so we just make
117  // blank macros for this warning type.
118  #define DETAIL_IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
119  #define DETAIL_IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
120 
121 
122 #elif defined _MSC_VER
123 
124  #define DETAIL_IGN_COMMON_WARN_IGNORE__DELETE_NON_VIRTUAL_DESTRUCTOR \
125  DETAIL_IGN_COMMON_BEGIN_WARNING_SUPPRESSION(4265)
126 
127  #define DETAIL_IGN_COMMON_WARN_RESUME__DELETE_NON_VIRTUAL_DESTRUCTOR \
128  DETAIL_IGN_COMMON_WARN_RESUME
129 
130 
131  #define DETAIL_IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING \
132  DETAIL_IGN_COMMON_BEGIN_WARNING_SUPPRESSION(4251)
133 
134  #define DETAIL_IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING \
135  DETAIL_IGN_COMMON_WARN_RESUME
136 
137 
138 #else
139 
140  // If the compiler is unknown, we simply leave these macros blank to avoid
141  // compilation errors.
142 
143  #define DETAIL_IGN_COMMON_WARN_IGNORE__DELETE_NON_VIRTUAL_DESTRUCTOR
144  #define DETAIL_IGN_COMMON_WARN_RESUME__DELETE_NON_VIRTUAL_DESTRUCTOR
145 
146 
147  #define DETAIL_IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
148  #define DETAIL_IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
149 
150 
151 #endif
152 
153 
154 #endif