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