|
10 | 10 |
|
11 | 11 | #pragma once |
12 | 12 |
|
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 | | - |
21 | 13 | #if defined(__INTEL_COMPILER) |
22 | 14 | # pragma warning push |
23 | 15 | # pragma warning disable 68 // integer conversion resulted in a change of sign |
|
43 | 35 | # pragma GCC diagnostic ignored "-Wunused-but-set-parameter" |
44 | 36 | # pragma GCC diagnostic ignored "-Wunused-but-set-variable" |
45 | 37 | # pragma GCC diagnostic ignored "-Wmissing-field-initializers" |
46 | | -# if !PYBIND11_HAS_STD_LAUNDER |
47 | | -# pragma GCC diagnostic ignored "-Wstrict-aliasing" |
48 | | -# endif |
49 | 38 | # pragma GCC diagnostic ignored "-Wattributes" |
50 | 39 | # if __GNUC__ >= 7 |
51 | 40 | # pragma GCC diagnostic ignored "-Wnoexcept-type" |
|
63 | 52 | #include <string> |
64 | 53 | #include <utility> |
65 | 54 |
|
| 55 | +#if defined(__cpp_lib_launder) && !(defined(_MSC_VER) && (_MSC_VER < 1914)) |
| 56 | +# define PYBIND11_STD_LAUNDER std::launder |
| 57 | +# define PYBIND11_HAS_STD_LAUNDER 1 |
| 58 | +#else |
| 59 | +# define PYBIND11_STD_LAUNDER |
| 60 | +# define PYBIND11_HAS_STD_LAUNDER 0 |
| 61 | +#endif |
66 | 62 | #if defined(__GNUG__) && !defined(__clang__) |
67 | 63 | # include <cxxabi.h> |
68 | 64 | #endif |
@@ -161,8 +157,20 @@ class cpp_function : public function { |
161 | 157 | #if defined(__GNUG__) && !defined(__clang__) && __GNUC__ >= 6 |
162 | 158 | # pragma GCC diagnostic pop |
163 | 159 | #endif |
| 160 | +#if defined(__GNUG__) && !PYBIND11_HAS_STD_LAUNDER |
| 161 | +# pragma GCC diagnostic push |
| 162 | +# pragma GCC diagnostic ignored "-Wstrict-aliasing" |
| 163 | +#endif |
| 164 | + // UB without std::launder, but without breaking ABI and/or |
| 165 | + // a significant refactoring it's "impossible" to solve' |
164 | 166 | if (!std::is_trivially_destructible<Func>::value) |
165 | | - rec->free_data = [](function_record *r) { PYBIND11_STD_LAUNDER((capture *) &r->data)->~capture(); }; |
| 167 | + rec->free_data = [](function_record *r) { |
| 168 | + auto data = PYBIND11_STD_LAUNDER((capture *) &r->data); |
| 169 | + data->~capture(); |
| 170 | + }; |
| 171 | +#if defined(__GNUG__) && !PYBIND11_HAS_STD_LAUNDER |
| 172 | +# pragma GCC diagnostic pop |
| 173 | +#endif |
166 | 174 | } else { |
167 | 175 | rec->data[0] = new capture { std::forward<Func>(f) }; |
168 | 176 | rec->free_data = [](function_record *r) { delete ((capture *) r->data[0]); }; |
|
0 commit comments