Skip to content

Commit 4b4c43c

Browse files
committed
Enable -Wstrict-aliasing warning
1 parent fe84587 commit 4b4c43c

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

include/pybind11/pybind11.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
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+
1321
#if defined(__INTEL_COMPILER)
1422
# pragma warning push
1523
# pragma warning disable 68 // integer conversion resulted in a change of sign
@@ -35,7 +43,9 @@
3543
# pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
3644
# pragma GCC diagnostic ignored "-Wunused-but-set-variable"
3745
# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
38-
# pragma GCC diagnostic ignored "-Wstrict-aliasing"
46+
# if !PYBIND11_HAS_STD_LAUNDER
47+
# pragma GCC diagnostic ignored "-Wstrict-aliasing"
48+
# endif
3949
# pragma GCC diagnostic ignored "-Wattributes"
4050
# if __GNUC__ >= 7
4151
# pragma GCC diagnostic ignored "-Wnoexcept-type"
@@ -48,6 +58,7 @@
4858
#include "detail/init.h"
4959

5060
#include <memory>
61+
#include <new>
5162
#include <vector>
5263
#include <string>
5364
#include <utility>
@@ -151,7 +162,7 @@ class cpp_function : public function {
151162
# pragma GCC diagnostic pop
152163
#endif
153164
if (!std::is_trivially_destructible<Func>::value)
154-
rec->free_data = [](function_record *r) { ((capture *) &r->data)->~capture(); };
165+
rec->free_data = [](function_record *r) { PYBIND11_STD_LAUNDER((capture *) &r->data)->~capture(); };
155166
} else {
156167
rec->data[0] = new capture { std::forward<Func>(f) };
157168
rec->free_data = [](function_record *r) { delete ((capture *) r->data[0]); };

0 commit comments

Comments
 (0)