Viskores  1.0
Deprecated.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_Deprecated_h
19 #define viskores_Deprecated_h
20 
21 #include <viskores/StaticAssert.h>
22 #include <viskores/Types.h>
23 
24 #define VISKORES_DEPRECATED_MAKE_MESSAGE(...) \
25  VISKORES_EXPAND( \
26  VISKORES_DEPRECATED_MAKE_MESSAGE_IMPL(__VA_ARGS__, "", viskores::internal::NullType{}))
27 #define VISKORES_DEPRECATED_MAKE_MESSAGE_IMPL(version, message, ...) \
28  message " Deprecated in version " #version "."
29 
43 
56 
65 
66 // Determine whether the [[deprecated]] attribute is supported. Note that we are not
67 // using other older compiler features such as __attribute__((__deprecated__)) because
68 // they do not all support all [[deprecated]] uses (such as uses in enums). If
69 // [[deprecated]] is supported, then VISKORES_DEPRECATED_ATTRIBUTE_SUPPORTED will get defined.
70 #ifndef VISKORES_DEPRECATED_ATTRIBUTE_SUPPORTED
71 
72 #if defined(__NVCC__)
73 // Currently nvcc has zero support deprecated attributes
74 #elif __cplusplus >= 201402L && !defined(VISKORES_GCC)
75 
76 // C++14 and better supports [[deprecated]]
77 // Except in these cases:
78 // - nvcc
79 #define VISKORES_DEPRECATED_ATTRIBUTE_SUPPORTED
80 
81 #elif defined(VISKORES_GCC)
82 // GCC has supported [[deprecated]] since version 5.0, but using it on enum was not
83 // supported until 6.0. So we have to make a special case to only use it for high
84 // enough revisions.
85 #if __GNUC__ >= 6
86 #define VISKORES_DEPRECATED_ATTRIBUTE_SUPPORTED
87 #endif // Too old GCC
88 
89 #elif defined(__has_cpp_attribute)
90 
91 #if __has_cpp_attribute(deprecated)
92 // Compiler not fully C++14 compliant, but it reports to support [[deprecated]]
93 #define VISKORES_DEPRECATED_ATTRIBUTE_SUPPORTED
94 #endif // __has_cpp_attribute(deprecated)
95 
96 #elif defined(VISKORES_MSVC) && (_MSC_VER >= 1920)
97 
98 #define VISKORES_DEPRECATED_ATTRIBUTE_SUPPORTED
99 
100 #endif // no known compiler support for [[deprecated]]
101 
102 #endif // VISKORES_DEPRECATED_ATTRIBUTE_SUPPORTED check
103 
104 // Determine how to turn deprecated warnings on and off, generally with pragmas. If
105 // deprecated warnings can be turned off and on, then VISKORES_DEPRECATED_SUPPRESS_SUPPORTED
106 // is defined and the pair VISKORES_DEPRECATED_SUPPRESS_BEGIN and VISKORES_DEPRECATED_SUPRESS_END
107 // are defined to the pragmas to disable and restore these warnings. If this support
108 // cannot be determined, VISKORES_DEPRECATED_SUPPRESS_SUPPORTED is _not_ define whereas
109 // VISKORES_DEPRECATED_SUPPRESS_BEGIN and VISKORES_DEPRECATED_SUPPRESS_END are defined to be
110 // empty.
111 #ifndef VISKORES_DEPRECATED_SUPPRESS_SUPPORTED
112 
113 #if defined(VISKORES_GCC) || defined(VISKORES_CLANG)
114 
115 #define VISKORES_DEPRECATED_SUPPRESS_SUPPORTED
116 #define VISKORES_DEPRECATED_SUPPRESS_BEGIN \
117  _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
118 #define VISKORES_DEPRECATED_SUPPRESS_END _Pragma("GCC diagnostic pop")
119 
120 #elif defined(VISKORES_MSVC)
121 
122 #define VISKORES_DEPRECATED_SUPPRESS_SUPPORTED
123 #define VISKORES_DEPRECATED_SUPPRESS_BEGIN __pragma(warning(push)) __pragma(warning(disable : 4996))
124 #define VISKORES_DEPRECATED_SUPPRESS_END __pragma(warning(pop))
125 
126 #else
127 
128 // Other compilers probably have different pragmas for turning warnings off and on.
129 // Adding more compilers to this list is fine, but the above probably capture most
130 // developers and should be covered on dashboards.
131 #define VISKORES_DEPRECATED_SUPPRESS_BEGIN
132 #define VISKORES_DEPRECATED_SUPPRESS_END
133 
134 #endif
135 
136 #endif // VISKORES_DEPRECATED_SUPPRESS_SUPPORTED check
137 
138 #if !defined(VISKORES_DEPRECATED_SUPPRESS_BEGIN) || !defined(VISKORES_DEPRECATED_SUPPRESS_END)
139 #error VISKORES_DEPRECATED_SUPPRESS macros not properly defined.
140 #endif
141 
142 // Only actually use the [[deprecated]] attribute if the compiler supports it AND
143 // we know how to suppress deprecations when necessary.
144 #if defined(VISKORES_DEPRECATED_ATTRIBUTE_SUPPORTED) && \
145  defined(VISKORES_DEPRECATED_SUPPRESS_SUPPORTED)
146 #ifdef VISKORES_MSVC
147 #define VISKORES_DEPRECATED(...) [[deprecated(VISKORES_DEPRECATED_MAKE_MESSAGE(__VA_ARGS__))]]
148 #else // !MSVC
149 // GCC and other compilers support the C++14 attribute [[deprecated]], but there appears to be a
150 // bug (or other undesirable behavior) where if you mix [[deprecated]] with __attribute__(()) you
151 // get compile errors. To get around this, use __attribute((deprecated)) where supported.
152 #define VISKORES_DEPRECATED(...) \
153  __attribute__((deprecated(VISKORES_DEPRECATED_MAKE_MESSAGE(__VA_ARGS__))))
154 #endif // !MSVC
155 #else
156 #define VISKORES_DEPRECATED(...)
157 #endif
158 
159 #endif // viskores_Deprecated_h
Types.h
StaticAssert.h