From cae0e0094792d994e189813ea2e87df77b75bb30 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Thu, 7 Jul 2016 16:11:42 -0400 Subject: [PATCH 1/2] Disable -Wplacement-new warning false alarm GCC-6 adds a -Wplacement-new warning that warns for placement-new into a space that is too small, which is sometimes being triggered here (e.g. example5 always generates the warning under g++-6). It's a false warning, however: the line immediately before just checked the size, and so this line is never going to actually be reached in the cases where the GCC warning is being triggered. This localizes the warning disabling just to this one spot as there are other placement-new uses in pybind11 where this warning could warn about legitimate future problems. --- include/pybind11/pybind11.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 3d31b21d..b7833fc6 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -82,7 +82,14 @@ protected: /* Store the capture object directly in the function record if there is enough space */ if (sizeof(capture) <= sizeof(rec->data)) { +#if defined(__GNUG__) && !defined(__clang__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wplacement-new" +#endif new ((capture *) &rec->data) capture { std::forward(f) }; +#if defined(__GNUG__) && !defined(__clang__) +# pragma GCC diagnostic pop +#endif if (!std::is_trivially_destructible::value) rec->free_data = [](detail::function_record *r) { ((capture *) &r->data)->~capture(); }; } else { From 0b12f91fa3fd8994d2683db4059821b97d739103 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Thu, 7 Jul 2016 16:26:04 -0400 Subject: [PATCH 2/2] Only disable placement-new warning under gcc >= 6 Otherwise this would create unknown option warnings under g++ < 6. --- include/pybind11/pybind11.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index b7833fc6..3c9e6910 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -82,12 +82,12 @@ protected: /* Store the capture object directly in the function record if there is enough space */ if (sizeof(capture) <= sizeof(rec->data)) { -#if defined(__GNUG__) && !defined(__clang__) +#if defined(__GNUG__) && !defined(__clang__) && __GNUC__ >= 6 # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wplacement-new" #endif new ((capture *) &rec->data) capture { std::forward(f) }; -#if defined(__GNUG__) && !defined(__clang__) +#if defined(__GNUG__) && !defined(__clang__) && __GNUC__ >= 6 # pragma GCC diagnostic pop #endif if (!std::is_trivially_destructible::value)