From 5e39dc6c8290ac433ea9e73a9a4521bc1d6bca33 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Fri, 30 Jul 2021 04:46:18 -0700 Subject: [PATCH 1/4] Moving pragma for ignoring -Wnoexcept-type to the one location where it is needed. --- include/pybind11/pybind11.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 139a4111e9..9abb05aaec 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -18,9 +18,6 @@ # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wunused-but-set-parameter" # pragma GCC diagnostic ignored "-Wattributes" -# if __GNUC__ >= 7 -# pragma GCC diagnostic ignored "-Wnoexcept-type" -# endif #endif #include "attr.h" @@ -1355,6 +1352,10 @@ class class_ : public detail::generic_type { template ::value, int> = 0> static void add_base(detail::type_record &) { } +#if defined(__GNUC__) && __GNUC__ == 7 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wnoexcept-type" +#endif template class_ &def(const char *name_, Func&& f, const Extra&... extra) { cpp_function cf(method_adaptor(std::forward(f)), name(name_), is_method(*this), @@ -1362,6 +1363,9 @@ class class_ : public detail::generic_type { add_class_method(*this, name_, cf); return *this; } +#if defined(__GNUC__) && __GNUC__ == 7 +# pragma GCC diagnostic pop +#endif template class_ & def_static(const char *name_, Func &&f, const Extra&... extra) { From 2aa832d2fe888657bf081a120e8a5885be7338ca Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Fri, 30 Jul 2021 05:07:51 -0700 Subject: [PATCH 2/4] Trying a second location. --- include/pybind11/pybind11.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 9abb05aaec..b42c46ef5b 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -991,6 +991,10 @@ class module_ : public object { #endif } +#if defined(__GNUC__) && __GNUC__ == 7 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wnoexcept-type" +#endif /** \rst Create Python binding for a new function within the module scope. ``Func`` can be a plain C++ function, a function pointer, or a lambda function. For @@ -1005,6 +1009,9 @@ class module_ : public object { add_object(name_, func, true /* overwrite */); return *this; } +#if defined(__GNUC__) && __GNUC__ == 7 +# pragma GCC diagnostic pop +#endif /** \rst Create and return a new Python submodule with the given name and docstring. From e9221dd72e140d5a5d5cd9d6a7f8ceb72fd19081 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Fri, 30 Jul 2021 05:48:42 -0700 Subject: [PATCH 3/4] The previous commit worked (GitHub Actions green), but see the added comment about the dicy nature of -Wnoexcept-type ("if and only if"). --- include/pybind11/pybind11.h | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index b42c46ef5b..0c11220dfa 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -45,6 +45,20 @@ # include #endif +/* https://stackoverflow.com/questions/46798456/handling-gccs-noexcept-type-warning + This warning is about ABI compatibility, not code health. + It is only actually needed in a couple places, but apparently GCC 7 "generates this warning if + and only if the first template instantiation ... involves noexcept" [stackoverflow], therefore + it could get triggered from seemingly random places, depending on user code. + It seems very unlikely that this warning will be useful to anyone (no other GCC version + generates it), but to be maximally accommodating we turn it off here instead of using a + command line option. + */ +#if defined(__GNUC__) && __GNUC__ == 7 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wnoexcept-type" +#endif + PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(detail) @@ -991,10 +1005,6 @@ class module_ : public object { #endif } -#if defined(__GNUC__) && __GNUC__ == 7 -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wnoexcept-type" -#endif /** \rst Create Python binding for a new function within the module scope. ``Func`` can be a plain C++ function, a function pointer, or a lambda function. For @@ -1009,9 +1019,6 @@ class module_ : public object { add_object(name_, func, true /* overwrite */); return *this; } -#if defined(__GNUC__) && __GNUC__ == 7 -# pragma GCC diagnostic pop -#endif /** \rst Create and return a new Python submodule with the given name and docstring. @@ -1359,10 +1366,6 @@ class class_ : public detail::generic_type { template ::value, int> = 0> static void add_base(detail::type_record &) { } -#if defined(__GNUC__) && __GNUC__ == 7 -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wnoexcept-type" -#endif template class_ &def(const char *name_, Func&& f, const Extra&... extra) { cpp_function cf(method_adaptor(std::forward(f)), name(name_), is_method(*this), @@ -1370,9 +1373,6 @@ class class_ : public detail::generic_type { add_class_method(*this, name_, cf); return *this; } -#if defined(__GNUC__) && __GNUC__ == 7 -# pragma GCC diagnostic pop -#endif template class_ & def_static(const char *name_, Func &&f, const Extra&... extra) { @@ -2387,6 +2387,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 +#endif + #if defined(_MSC_VER) && !defined(__INTEL_COMPILER) # pragma warning(pop) #elif defined(__GNUG__) && !defined(__clang__) && !defined(__INTEL_COMPILER) From 27ac762fc8daa8ef4cefcbf600cc0bf9e14a98c6 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Fri, 30 Jul 2021 06:48:39 -0700 Subject: [PATCH 4/4] Applying reviewer suggestion. --- include/pybind11/pybind11.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 0c11220dfa..16615421dc 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -50,9 +50,7 @@ It is only actually needed in a couple places, but apparently GCC 7 "generates this warning if and only if the first template instantiation ... involves noexcept" [stackoverflow], therefore it could get triggered from seemingly random places, depending on user code. - It seems very unlikely that this warning will be useful to anyone (no other GCC version - generates it), but to be maximally accommodating we turn it off here instead of using a - command line option. + No other GCC version generates this warning. */ #if defined(__GNUC__) && __GNUC__ == 7 # pragma GCC diagnostic push