diff --git a/include/pybind11/attr.h b/include/pybind11/attr.h index ab1fe80446..5efd7b4f87 100644 --- a/include/pybind11/attr.h +++ b/include/pybind11/attr.h @@ -12,6 +12,11 @@ #include "cast.h" +#if defined(PYBIND11_NOINLINE_GCC_PRAGMA_ATTRIBUTES_NEEDED) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wattributes" +#endif + PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) /// \addtogroup annotations @@ -562,3 +567,7 @@ constexpr bool expected_num_args(size_t nargs, bool has_args, bool has_kwargs) { PYBIND11_NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) + +#if defined(PYBIND11_NOINLINE_GCC_PRAGMA_ATTRIBUTES_NEEDED) +# pragma GCC diagnostic pop +#endif diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index cc24a52fd3..8b06d771b2 100644 --- a/include/pybind11/detail/common.h +++ b/include/pybind11/detail/common.h @@ -56,9 +56,6 @@ # elif __INTEL_COMPILER < 1900 && defined(PYBIND11_CPP14) # error pybind11 supports only C++11 with Intel C++ compiler v18. Use v19 or newer for C++14. # endif -/* The following pragma cannot be pop'ed: - https://community.intel.com/t5/Intel-C-Compiler/Inline-and-no-inline-warning/td-p/1216764 */ -# pragma warning disable 2196 // warning #2196: routine is both "inline" and "noinline" #elif defined(__clang__) && !defined(__apple_build_version__) # if __clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 3) # error pybind11 requires clang 3.3 or newer @@ -110,6 +107,17 @@ # define PYBIND11_NOINLINE __attribute__ ((noinline)) inline #endif +#if !defined(PYBIND11_NOINLINE_DISABLED) +# if (defined(__CUDACC__) || (defined(__GNUC__) && (__GNUC__ == 7 || __GNUC__ == 8))) \ + && !defined(PYBIND11_NOINLINE_GCC_PRAGMA_ATTRIBUTES_NEEDED) +# define PYBIND11_NOINLINE_GCC_PRAGMA_ATTRIBUTES_NEEDED +# elif defined(__INTEL_COMPILER) +// The following pragma cannot be pop'ed: +// https://community.intel.com/t5/Intel-C-Compiler/Inline-and-no-inline-warning/td-p/1216764 +# pragma warning disable 2196 // warning #2196: routine is both "inline" and "noinline" +# endif +#endif + #if defined(__MINGW32__) // For unknown reasons all PYBIND11_DEPRECATED member trigger a warning when declared // whether it is used or not @@ -379,6 +387,11 @@ extern "C" { } \ void PYBIND11_CONCAT(pybind11_init_, name)(::pybind11::module_ & (variable)) +#if defined(PYBIND11_NOINLINE_GCC_PRAGMA_ATTRIBUTES_NEEDED) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wattributes" +#endif + PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) using ssize_t = Py_ssize_t; @@ -965,3 +978,7 @@ constexpr inline bool silence_msvc_c4127(bool cond) { return cond; } PYBIND11_NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) + +#if defined(PYBIND11_NOINLINE_GCC_PRAGMA_ATTRIBUTES_NEEDED) +# pragma GCC diagnostic pop +#endif diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h index b177801a11..c5f341cb03 100644 --- a/include/pybind11/detail/internals.h +++ b/include/pybind11/detail/internals.h @@ -11,6 +11,11 @@ #include "../pytypes.h" +#if defined(PYBIND11_NOINLINE_GCC_PRAGMA_ATTRIBUTES_NEEDED) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wattributes" +#endif + PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) using ExceptionTranslator = void (*)(std::exception_ptr); @@ -380,3 +385,7 @@ T &get_or_create_shared_data(const std::string &name) { } PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) + +#if defined(PYBIND11_NOINLINE_GCC_PRAGMA_ATTRIBUTES_NEEDED) +# pragma GCC diagnostic pop +#endif diff --git a/include/pybind11/detail/type_caster_base.h b/include/pybind11/detail/type_caster_base.h index 14cb27cad2..eb28233612 100644 --- a/include/pybind11/detail/type_caster_base.h +++ b/include/pybind11/detail/type_caster_base.h @@ -25,6 +25,11 @@ #include #include +#if defined(PYBIND11_NOINLINE_GCC_PRAGMA_ATTRIBUTES_NEEDED) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wattributes" +#endif + PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(detail) @@ -949,3 +954,7 @@ template class type_caster_base : public type_caster_generic { PYBIND11_NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) + +#if defined(PYBIND11_NOINLINE_GCC_PRAGMA_ATTRIBUTES_NEEDED) +# pragma GCC diagnostic pop +#endif diff --git a/include/pybind11/detail/typeid.h b/include/pybind11/detail/typeid.h index 39ba8ce0f7..cb07ba7fbc 100644 --- a/include/pybind11/detail/typeid.h +++ b/include/pybind11/detail/typeid.h @@ -18,6 +18,11 @@ #include "common.h" +#if defined(PYBIND11_NOINLINE_GCC_PRAGMA_ATTRIBUTES_NEEDED) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wattributes" +#endif + PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(detail) /// Erase all occurrences of a substring @@ -53,3 +58,7 @@ template static std::string type_id() { } PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) + +#if defined(PYBIND11_NOINLINE_GCC_PRAGMA_ATTRIBUTES_NEEDED) +# pragma GCC diagnostic pop +#endif diff --git a/include/pybind11/gil.h b/include/pybind11/gil.h index 32f1a8963b..5bcfafcf37 100644 --- a/include/pybind11/gil.h +++ b/include/pybind11/gil.h @@ -12,8 +12,12 @@ #include "detail/common.h" #include "detail/internals.h" -PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) +#if defined(PYBIND11_NOINLINE_GCC_PRAGMA_ATTRIBUTES_NEEDED) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wattributes" +#endif +PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(detail) @@ -191,3 +195,7 @@ class gil_scoped_release { #endif PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) + +#if defined(PYBIND11_NOINLINE_GCC_PRAGMA_ATTRIBUTES_NEEDED) +# pragma GCC diagnostic pop +#endif diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 2dc0f29f0b..941c268b5c 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -30,6 +30,11 @@ # pragma warning(disable: 4127) // warning C4127: Conditional expression is constant #endif +#if defined(PYBIND11_NOINLINE_GCC_PRAGMA_ATTRIBUTES_NEEDED) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wattributes" +#endif + /* This will be true on all flat address space platforms and allows us to reduce the whole npy_intp / ssize_t / Py_intptr_t business down to just ssize_t for all size and dimension types (e.g. shape, strides, indexing), instead of inflicting this @@ -1709,6 +1714,10 @@ Helper vectorize(Return (Class::*f)(Args...) const) { PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) +#if defined(PYBIND11_NOINLINE_GCC_PRAGMA_ATTRIBUTES_NEEDED) +# pragma GCC diagnostic pop +#endif + #if defined(_MSC_VER) #pragma warning(pop) #endif diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 20df6a01fd..ab8ac22532 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -10,11 +10,6 @@ #pragma once -#if defined(__CUDACC__) || (defined(__GNUC__) && (__GNUC__ == 7 || __GNUC__ == 8)) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wattributes" -#endif - #include "attr.h" #include "gil.h" #include "options.h" @@ -52,6 +47,11 @@ # pragma GCC diagnostic ignored "-Wnoexcept-type" #endif +#if defined(PYBIND11_NOINLINE_GCC_PRAGMA_ATTRIBUTES_NEEDED) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wattributes" +#endif + PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(detail) @@ -1874,7 +1874,6 @@ template class enum_ : public class_ { PYBIND11_NAMESPACE_BEGIN(detail) - PYBIND11_NOINLINE void keep_alive_impl(handle nurse, handle patient) { if (!nurse || !patient) pybind11_fail("Could not activate keep_alive!"); @@ -2380,10 +2379,10 @@ inline function get_overload(const T *this_ptr, const char *name) { PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) -#if defined(__GNUC__) && __GNUC__ == 7 -# pragma GCC diagnostic pop // -Wnoexcept-type +#if defined(PYBIND11_NOINLINE_GCC_PRAGMA_ATTRIBUTES_NEEDED) +# pragma GCC diagnostic pop #endif -#if defined(__CUDACC__) || (defined(__GNUC__) && (__GNUC__ == 7 || __GNUC__ == 8)) -# pragma GCC diagnostic pop +#if defined(__GNUC__) && __GNUC__ == 7 +# pragma GCC diagnostic pop // -Wnoexcept-type #endif diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index 21e14960cf..e6d985630b 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -14,6 +14,11 @@ #include #include +#if defined(PYBIND11_NOINLINE_GCC_PRAGMA_ATTRIBUTES_NEEDED) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wattributes" +#endif + PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) /* A few forward declarations */ @@ -1763,3 +1768,7 @@ PYBIND11_MATH_OPERATOR_BINARY(operator>>=, PyNumber_InPlaceRshift) PYBIND11_NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) + +#if defined(PYBIND11_NOINLINE_GCC_PRAGMA_ATTRIBUTES_NEEDED) +# pragma GCC diagnostic pop +#endif