|
17 | 17 | // Additional convention: 0xD = dev
|
18 | 18 | #define PYBIND11_VERSION_HEX 0x020B00D1
|
19 | 19 |
|
20 |
| -#define PYBIND11_NAMESPACE_BEGIN(name) namespace name { |
21 |
| -#define PYBIND11_NAMESPACE_END(name) } |
| 20 | +// Define some generic pybind11 helper macros for warning management. |
| 21 | +// |
| 22 | +// Note that compiler-specific push/pop pairs are baked into the |
| 23 | +// PYBIND11_NAMESPACE_BEGIN/PYBIND11_NAMESPACE_END pair of macros. Therefore manual |
| 24 | +// PYBIND11_WARNING_PUSH/PYBIND11_WARNING_POP are usually only needed in `#include` sections. |
| 25 | +// |
| 26 | +// If you find you need to suppress a warning, please try to make the suppression as local as |
| 27 | +// possible using these macros. Please also be sure to push/pop with the pybind11 macros. Please |
| 28 | +// only use compiler specifics if you need to check specific versions, e.g. Apple Clang vs. vanilla |
| 29 | +// Clang. |
| 30 | +#if defined(_MSC_VER) |
| 31 | +# define PYBIND11_COMPILER_MSVC |
| 32 | +# define PYBIND11_PRAGMA(...) __pragma(__VA_ARGS__) |
| 33 | +# define PYBIND11_WARNING_PUSH PYBIND11_PRAGMA(warning(push)) |
| 34 | +# define PYBIND11_WARNING_POP PYBIND11_PRAGMA(warning(pop)) |
| 35 | +#elif defined(__INTEL_COMPILER) |
| 36 | +# define PYBIND11_COMPILER_INTEL |
| 37 | +# define PYBIND11_PRAGMA(...) _Pragma(# __VA_ARGS__) |
| 38 | +# define PYBIND11_WARNING_PUSH PYBIND11_PRAGMA(warning push) |
| 39 | +# define PYBIND11_WARNING_POP PYBIND11_PRAGMA(warning pop) |
| 40 | +#elif defined(__clang__) |
| 41 | +# define PYBIND11_COMPILER_CLANG |
| 42 | +# define PYBIND11_PRAGMA(...) _Pragma(# __VA_ARGS__) |
| 43 | +# define PYBIND11_WARNING_PUSH PYBIND11_PRAGMA(clang diagnostic push) |
| 44 | +# define PYBIND11_WARNING_POP PYBIND11_PRAGMA(clang diagnostic push) |
| 45 | +#elif defined(__GNUC__) |
| 46 | +# define PYBIND11_COMPILER_GCC |
| 47 | +# define PYBIND11_PRAGMA(...) _Pragma(# __VA_ARGS__) |
| 48 | +# define PYBIND11_WARNING_PUSH PYBIND11_PRAGMA(GCC diagnostic push) |
| 49 | +# define PYBIND11_WARNING_POP PYBIND11_PRAGMA(GCC diagnostic pop) |
| 50 | +#endif |
| 51 | + |
| 52 | +#ifdef PYBIND11_COMPILER_MSVC |
| 53 | +# define PYBIND11_WARNING_DISABLE_MSVC(name) PYBIND11_PRAGMA(warning(disable : name)) |
| 54 | +#else |
| 55 | +# define PYBIND11_WARNING_DISABLE_MSVC(name) |
| 56 | +#endif |
| 57 | + |
| 58 | +#ifdef PYBIND11_COMPILER_CLANG |
| 59 | +# define PYBIND11_WARNING_DISABLE_CLANG(name) PYBIND11_PRAGMA(clang diagnostic ignored name) |
| 60 | +#else |
| 61 | +# define PYBIND11_WARNING_DISABLE_CLANG(name) |
| 62 | +#endif |
| 63 | + |
| 64 | +#ifdef PYBIND11_COMPILER_GCC |
| 65 | +# define PYBIND11_WARNING_DISABLE_GCC(name) PYBIND11_PRAGMA(GCC diagnostic ignored name) |
| 66 | +#else |
| 67 | +# define PYBIND11_WARNING_DISABLE_GCC(name) |
| 68 | +#endif |
| 69 | + |
| 70 | +#ifdef PYBIND11_COMPILER_INTEL |
| 71 | +# define PYBIND11_WARNING_DISABLE_INTEL(name) PYBIND11_PRAGMA(warning disable name) |
| 72 | +#else |
| 73 | +# define PYBIND11_WARNING_DISABLE_INTEL(name) |
| 74 | +#endif |
| 75 | + |
| 76 | +#define PYBIND11_NAMESPACE_BEGIN(name) \ |
| 77 | + namespace name { \ |
| 78 | + PYBIND11_WARNING_PUSH |
| 79 | + |
| 80 | +#define PYBIND11_NAMESPACE_END(name) \ |
| 81 | + PYBIND11_WARNING_POP \ |
| 82 | + } |
22 | 83 |
|
23 | 84 | // Robust support for some features and loading modules compiled against different pybind versions
|
24 | 85 | // requires forcing hidden visibility on pybind code, so we enforce this by setting the attribute
|
|
151 | 212 |
|
152 | 213 | /// Include Python header, disable linking to pythonX_d.lib on Windows in debug mode
|
153 | 214 | #if defined(_MSC_VER)
|
154 |
| -# pragma warning(push) |
| 215 | +PYBIND11_WARNING_PUSH |
| 216 | +PYBIND11_WARNING_DISABLE_MSVC(4505) |
155 | 217 | // C4505: 'PySlice_GetIndicesEx': unreferenced local function has been removed (PyPy only)
|
156 |
| -# pragma warning(disable : 4505) |
157 | 218 | # if defined(_DEBUG) && !defined(Py_DEBUG)
|
158 | 219 | // Workaround for a VS 2022 issue.
|
159 | 220 | // NOTE: This workaround knowingly violates the Python.h include order requirement:
|
|
236 | 297 | # define _DEBUG
|
237 | 298 | # undef PYBIND11_DEBUG_MARKER
|
238 | 299 | # endif
|
239 |
| -# pragma warning(pop) |
| 300 | +PYBIND11_WARNING_POP |
240 | 301 | #endif
|
241 | 302 |
|
242 | 303 | #include <cstddef>
|
@@ -1136,17 +1197,6 @@ constexpr
|
1136 | 1197 | # define PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(...)
|
1137 | 1198 | #endif
|
1138 | 1199 |
|
1139 |
| -#if defined(_MSC_VER) // All versions (as of July 2021). |
1140 |
| - |
1141 |
| -// warning C4127: Conditional expression is constant |
1142 |
| -constexpr inline bool silence_msvc_c4127(bool cond) { return cond; } |
1143 |
| - |
1144 |
| -# define PYBIND11_SILENCE_MSVC_C4127(...) ::pybind11::detail::silence_msvc_c4127(__VA_ARGS__) |
1145 |
| - |
1146 |
| -#else |
1147 |
| -# define PYBIND11_SILENCE_MSVC_C4127(...) __VA_ARGS__ |
1148 |
| -#endif |
1149 |
| - |
1150 | 1200 | #if defined(__clang__) \
|
1151 | 1201 | && (defined(__apple_build_version__) /* AppleClang 13.0.0.13000029 was the only data point \
|
1152 | 1202 | available. */ \
|
|
0 commit comments