Skip to content

Commit 46c51fc

Browse files
rwgkhenryiii
authored andcommitted
Limiting pragma for ignoring GCC 7 -Wnoexcept-type to the scope of pybind11.h. (#3161)
* Moving pragma for ignoring -Wnoexcept-type to the one location where it is needed. * Trying a second location. * The previous commit worked (GitHub Actions green), but see the added comment about the dicy nature of -Wnoexcept-type ("if and only if"). * Applying reviewer suggestion.
1 parent 05852fb commit 46c51fc

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

include/pybind11/pybind11.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
# pragma GCC diagnostic push
2020
# pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
2121
# pragma GCC diagnostic ignored "-Wattributes"
22-
# if __GNUC__ >= 7
23-
# pragma GCC diagnostic ignored "-Wnoexcept-type"
24-
# endif
2522
#endif
2623

2724
#include "attr.h"
@@ -49,6 +46,18 @@
4946
# include <cxxabi.h>
5047
#endif
5148

49+
/* https://stackoverflow.com/questions/46798456/handling-gccs-noexcept-type-warning
50+
This warning is about ABI compatibility, not code health.
51+
It is only actually needed in a couple places, but apparently GCC 7 "generates this warning if
52+
and only if the first template instantiation ... involves noexcept" [stackoverflow], therefore
53+
it could get triggered from seemingly random places, depending on user code.
54+
No other GCC version generates this warning.
55+
*/
56+
#if defined(__GNUC__) && __GNUC__ == 7
57+
# pragma GCC diagnostic push
58+
# pragma GCC diagnostic ignored "-Wnoexcept-type"
59+
#endif
60+
5261
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
5362

5463
#if defined(_MSC_VER)
@@ -2309,6 +2318,10 @@ inline function get_overload(const T *this_ptr, const char *name) {
23092318

23102319
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
23112320

2321+
#if defined(__GNUC__) && __GNUC__ == 7
2322+
# pragma GCC diagnostic pop // -Wnoexcept-type
2323+
#endif
2324+
23122325
#if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
23132326
# pragma warning(pop)
23142327
#elif defined(__GNUG__) && !defined(__clang__) && !defined(__INTEL_COMPILER)

0 commit comments

Comments
 (0)