Skip to content

Commit fe06e0a

Browse files
committed
Narrow down the scope of -Wstrict-aliasing
1 parent d68f534 commit fe06e0a

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

include/pybind11/pybind11.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@
1010

1111
#pragma once
1212

13-
#if defined(__cpp_lib_launder) && !(defined(_MSC_VER) && (_MSC_VER < 1914))
14-
# define PYBIND11_STD_LAUNDER std::launder
15-
# define PYBIND11_HAS_STD_LAUNDER 1
16-
#else
17-
# define PYBIND11_STD_LAUNDER
18-
# define PYBIND11_HAS_STD_LAUNDER 0
19-
#endif
20-
2113
#if defined(__INTEL_COMPILER)
2214
# pragma warning push
2315
# pragma warning disable 68 // integer conversion resulted in a change of sign
@@ -43,9 +35,6 @@
4335
# pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
4436
# pragma GCC diagnostic ignored "-Wunused-but-set-variable"
4537
# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
46-
# if !PYBIND11_HAS_STD_LAUNDER
47-
# pragma GCC diagnostic ignored "-Wstrict-aliasing"
48-
# endif
4938
# pragma GCC diagnostic ignored "-Wattributes"
5039
# if __GNUC__ >= 7
5140
# pragma GCC diagnostic ignored "-Wnoexcept-type"
@@ -162,7 +151,20 @@ class cpp_function : public function {
162151
# pragma GCC diagnostic pop
163152
#endif
164153
if (!std::is_trivially_destructible<Func>::value)
154+
#if defined(__cpp_lib_launder) && !(defined(_MSC_VER) && (_MSC_VER < 1914))
155+
# define PYBIND11_STD_LAUNDER std::launder
156+
# define PYBIND11_HAS_STD_LAUNDER 1
157+
#else
158+
# define PYBIND11_STD_LAUNDER
159+
# define PYBIND11_HAS_STD_LAUNDER 0
160+
# pragma GCC diagnostic push
161+
# pragma GCC diagnostic ignored "-Wstrict-aliasing"
162+
#endif
163+
165164
rec->free_data = [](function_record *r) { PYBIND11_STD_LAUNDER((capture *) &r->data)->~capture(); };
165+
#if !PYBIND11_HAS_STD_LAUNDER
166+
# pragma GCC diagnostic pop
167+
#endif
166168
} else {
167169
rec->data[0] = new capture { std::forward<Func>(f) };
168170
rec->free_data = [](function_record *r) { delete ((capture *) r->data[0]); };

0 commit comments

Comments
 (0)