mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 05:05:11 +00:00
fix: allow -Wpedantic in C++20 mode (#5322)
* fix: allow -Wpedantic again Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * tests: ignore pedantic warning for PYBIND11_DECLARE_HOLDER_TYPE Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * tests: try just turning off pedantic for one file Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * tests: only run pedantic in C++20 mode Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * Update tests/local_bindings.h --------- Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
This commit is contained in:
parent
2baf9d6833
commit
9966ad409d
@ -162,7 +162,7 @@ the declaration
|
|||||||
|
|
||||||
.. code-block:: cpp
|
.. code-block:: cpp
|
||||||
|
|
||||||
PYBIND11_MAKE_OPAQUE(std::vector<int>);
|
PYBIND11_MAKE_OPAQUE(std::vector<int>)
|
||||||
|
|
||||||
before any binding code (e.g. invocations to ``class_::def()``, etc.). This
|
before any binding code (e.g. invocations to ``class_::def()``, etc.). This
|
||||||
macro must be specified at the top level (and outside of any namespaces), since
|
macro must be specified at the top level (and outside of any namespaces), since
|
||||||
@ -207,8 +207,8 @@ The following example showcases usage of :file:`pybind11/stl_bind.h`:
|
|||||||
// Don't forget this
|
// Don't forget this
|
||||||
#include <pybind11/stl_bind.h>
|
#include <pybind11/stl_bind.h>
|
||||||
|
|
||||||
PYBIND11_MAKE_OPAQUE(std::vector<int>);
|
PYBIND11_MAKE_OPAQUE(std::vector<int>)
|
||||||
PYBIND11_MAKE_OPAQUE(std::map<std::string, double>);
|
PYBIND11_MAKE_OPAQUE(std::map<std::string, double>)
|
||||||
|
|
||||||
// ...
|
// ...
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ top namespace level before any binding code:
|
|||||||
|
|
||||||
.. code-block:: cpp
|
.. code-block:: cpp
|
||||||
|
|
||||||
PYBIND11_DECLARE_HOLDER_TYPE(T, SmartPtr<T>);
|
PYBIND11_DECLARE_HOLDER_TYPE(T, SmartPtr<T>)
|
||||||
|
|
||||||
The first argument of :func:`PYBIND11_DECLARE_HOLDER_TYPE` should be a
|
The first argument of :func:`PYBIND11_DECLARE_HOLDER_TYPE` should be a
|
||||||
placeholder name that is used as a template parameter of the second argument.
|
placeholder name that is used as a template parameter of the second argument.
|
||||||
@ -136,7 +136,7 @@ by default. Specify
|
|||||||
|
|
||||||
.. code-block:: cpp
|
.. code-block:: cpp
|
||||||
|
|
||||||
PYBIND11_DECLARE_HOLDER_TYPE(T, SmartPtr<T>, true);
|
PYBIND11_DECLARE_HOLDER_TYPE(T, SmartPtr<T>, true)
|
||||||
|
|
||||||
if ``SmartPtr<T>`` can always be initialized from a ``T*`` pointer without the
|
if ``SmartPtr<T>`` can always be initialized from a ``T*`` pointer without the
|
||||||
risk of inconsistencies (such as multiple independent ``SmartPtr`` instances
|
risk of inconsistencies (such as multiple independent ``SmartPtr`` instances
|
||||||
@ -154,7 +154,7 @@ specialized:
|
|||||||
.. code-block:: cpp
|
.. code-block:: cpp
|
||||||
|
|
||||||
// Always needed for custom holder types
|
// Always needed for custom holder types
|
||||||
PYBIND11_DECLARE_HOLDER_TYPE(T, SmartPtr<T>);
|
PYBIND11_DECLARE_HOLDER_TYPE(T, SmartPtr<T>)
|
||||||
|
|
||||||
// Only needed if the type's `.get()` goes by another name
|
// Only needed if the type's `.get()` goes by another name
|
||||||
namespace PYBIND11_NAMESPACE { namespace detail {
|
namespace PYBIND11_NAMESPACE { namespace detail {
|
||||||
|
@ -479,6 +479,8 @@ PYBIND11_WARNING_POP
|
|||||||
}
|
}
|
||||||
|
|
||||||
\endrst */
|
\endrst */
|
||||||
|
PYBIND11_WARNING_PUSH
|
||||||
|
PYBIND11_WARNING_DISABLE_CLANG("-Wgnu-zero-variadic-macro-arguments")
|
||||||
#define PYBIND11_MODULE(name, variable, ...) \
|
#define PYBIND11_MODULE(name, variable, ...) \
|
||||||
static ::pybind11::module_::module_def PYBIND11_CONCAT(pybind11_module_def_, name) \
|
static ::pybind11::module_::module_def PYBIND11_CONCAT(pybind11_module_def_, name) \
|
||||||
PYBIND11_MAYBE_UNUSED; \
|
PYBIND11_MAYBE_UNUSED; \
|
||||||
@ -499,6 +501,7 @@ PYBIND11_WARNING_POP
|
|||||||
PYBIND11_CATCH_INIT_EXCEPTIONS \
|
PYBIND11_CATCH_INIT_EXCEPTIONS \
|
||||||
} \
|
} \
|
||||||
void PYBIND11_CONCAT(pybind11_init_, name)(::pybind11::module_ & (variable))
|
void PYBIND11_CONCAT(pybind11_init_, name)(::pybind11::module_ & (variable))
|
||||||
|
PYBIND11_WARNING_POP
|
||||||
|
|
||||||
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
||||||
|
|
||||||
|
@ -382,6 +382,9 @@ function(pybind11_enable_warnings target_name)
|
|||||||
-Wdeprecated
|
-Wdeprecated
|
||||||
-Wundef
|
-Wundef
|
||||||
-Wnon-virtual-dtor)
|
-Wnon-virtual-dtor)
|
||||||
|
if(DEFINED CMAKE_CXX_STANDARD AND NOT CMAKE_CXX_STANDARD VERSION_LESS 20)
|
||||||
|
target_compile_options(${target_name} PRIVATE -Wpedantic)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(PYBIND11_WERROR)
|
if(PYBIND11_WERROR)
|
||||||
|
@ -56,13 +56,13 @@ private:
|
|||||||
std::string message = "";
|
std::string message = "";
|
||||||
};
|
};
|
||||||
|
|
||||||
PYBIND11_MAKE_OPAQUE(LocalVec);
|
PYBIND11_MAKE_OPAQUE(LocalVec)
|
||||||
PYBIND11_MAKE_OPAQUE(LocalVec2);
|
PYBIND11_MAKE_OPAQUE(LocalVec2)
|
||||||
PYBIND11_MAKE_OPAQUE(LocalMap);
|
PYBIND11_MAKE_OPAQUE(LocalMap)
|
||||||
PYBIND11_MAKE_OPAQUE(NonLocalVec);
|
PYBIND11_MAKE_OPAQUE(NonLocalVec)
|
||||||
// PYBIND11_MAKE_OPAQUE(NonLocalVec2); // same type as LocalVec2
|
// PYBIND11_MAKE_OPAQUE(NonLocalVec2) // same type as LocalVec2
|
||||||
PYBIND11_MAKE_OPAQUE(NonLocalMap);
|
PYBIND11_MAKE_OPAQUE(NonLocalMap)
|
||||||
PYBIND11_MAKE_OPAQUE(NonLocalMap2);
|
PYBIND11_MAKE_OPAQUE(NonLocalMap2)
|
||||||
|
|
||||||
// Simple bindings (used with the above):
|
// Simple bindings (used with the above):
|
||||||
template <typename T, int Adjust = 0, typename... Args>
|
template <typename T, int Adjust = 0, typename... Args>
|
||||||
@ -70,7 +70,7 @@ py::class_<T> bind_local(Args &&...args) {
|
|||||||
return py::class_<T>(std::forward<Args>(args)...).def(py::init<int>()).def("get", [](T &i) {
|
return py::class_<T>(std::forward<Args>(args)...).def(py::init<int>()).def("get", [](T &i) {
|
||||||
return i.i + Adjust;
|
return i.i + Adjust;
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
// Simulate a foreign library base class (to match the example in the docs):
|
// Simulate a foreign library base class (to match the example in the docs):
|
||||||
namespace pets {
|
namespace pets {
|
||||||
|
@ -148,7 +148,7 @@ TEST_SUBMODULE(callbacks, m) {
|
|||||||
m.def("dummy_function2", [](int i, int j) { return i + j; });
|
m.def("dummy_function2", [](int i, int j) { return i + j; });
|
||||||
m.def(
|
m.def(
|
||||||
"roundtrip",
|
"roundtrip",
|
||||||
[](std::function<int(int)> f, bool expect_none = false) {
|
[](std::function<int(int)> f, bool expect_none) {
|
||||||
if (expect_none && f) {
|
if (expect_none && f) {
|
||||||
throw std::runtime_error("Expected None to be converted to empty std::function");
|
throw std::runtime_error("Expected None to be converted to empty std::function");
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ void reset_refs() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns element 2,1 from a matrix (used to test copy/nocopy)
|
// Returns element 2,1 from a matrix (used to test copy/nocopy)
|
||||||
double get_elem(const Eigen::Ref<const Eigen::MatrixXd> &m) { return m(2, 1); };
|
double get_elem(const Eigen::Ref<const Eigen::MatrixXd> &m) { return m(2, 1); }
|
||||||
|
|
||||||
// Returns a matrix with 10*r + 100*c added to each matrix element (to help test that the matrix
|
// Returns a matrix with 10*r + 100*c added to each matrix element (to help test that the matrix
|
||||||
// reference is referencing rows/columns correctly).
|
// reference is referencing rows/columns correctly).
|
||||||
@ -76,7 +76,7 @@ struct CustomOperatorNew {
|
|||||||
Eigen::Matrix4d a = Eigen::Matrix4d::Zero();
|
Eigen::Matrix4d a = Eigen::Matrix4d::Zero();
|
||||||
Eigen::Matrix4d b = Eigen::Matrix4d::Identity();
|
Eigen::Matrix4d b = Eigen::Matrix4d::Identity();
|
||||||
|
|
||||||
EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
|
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_SUBMODULE(eigen_matrix, m) {
|
TEST_SUBMODULE(eigen_matrix, m) {
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
// This also deliberately doesn't use the below StringList type alias to test
|
// This also deliberately doesn't use the below StringList type alias to test
|
||||||
// that MAKE_OPAQUE can handle a type containing a `,`. (The `std::allocator`
|
// that MAKE_OPAQUE can handle a type containing a `,`. (The `std::allocator`
|
||||||
// bit is just the default `std::vector` allocator).
|
// bit is just the default `std::vector` allocator).
|
||||||
PYBIND11_MAKE_OPAQUE(std::vector<std::string, std::allocator<std::string>>);
|
PYBIND11_MAKE_OPAQUE(std::vector<std::string, std::allocator<std::string>>)
|
||||||
|
|
||||||
using StringList = std::vector<std::string, std::allocator<std::string>>;
|
using StringList = std::vector<std::string, std::allocator<std::string>>;
|
||||||
|
|
||||||
|
@ -86,8 +86,8 @@ private:
|
|||||||
};
|
};
|
||||||
using NonCopyableIntPair = std::pair<NonCopyableInt, NonCopyableInt>;
|
using NonCopyableIntPair = std::pair<NonCopyableInt, NonCopyableInt>;
|
||||||
|
|
||||||
PYBIND11_MAKE_OPAQUE(std::vector<NonCopyableInt>);
|
PYBIND11_MAKE_OPAQUE(std::vector<NonCopyableInt>)
|
||||||
PYBIND11_MAKE_OPAQUE(std::vector<NonCopyableIntPair>);
|
PYBIND11_MAKE_OPAQUE(std::vector<NonCopyableIntPair>)
|
||||||
|
|
||||||
template <typename PythonType>
|
template <typename PythonType>
|
||||||
py::list test_random_access_iterator(PythonType x) {
|
py::list test_random_access_iterator(PythonType x) {
|
||||||
|
@ -11,6 +11,9 @@
|
|||||||
#include "object.h"
|
#include "object.h"
|
||||||
#include "pybind11_tests.h"
|
#include "pybind11_tests.h"
|
||||||
|
|
||||||
|
// This breaks on PYBIND11_DECLARE_HOLDER_TYPE
|
||||||
|
PYBIND11_WARNING_DISABLE_GCC("-Wpedantic")
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// This is just a wrapper around unique_ptr, but with extra fields to deliberately bloat up the
|
// This is just a wrapper around unique_ptr, but with extra fields to deliberately bloat up the
|
||||||
@ -279,13 +282,13 @@ struct holder_helper<ref<T>> {
|
|||||||
} // namespace PYBIND11_NAMESPACE
|
} // namespace PYBIND11_NAMESPACE
|
||||||
|
|
||||||
// Make pybind aware of the ref-counted wrapper type (s):
|
// Make pybind aware of the ref-counted wrapper type (s):
|
||||||
PYBIND11_DECLARE_HOLDER_TYPE(T, ref<T>, true);
|
PYBIND11_DECLARE_HOLDER_TYPE(T, ref<T>, true)
|
||||||
// The following is not required anymore for std::shared_ptr, but it should compile without error:
|
// The following is not required anymore for std::shared_ptr, but it should compile without error:
|
||||||
PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>);
|
PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>)
|
||||||
PYBIND11_DECLARE_HOLDER_TYPE(T, huge_unique_ptr<T>);
|
PYBIND11_DECLARE_HOLDER_TYPE(T, huge_unique_ptr<T>)
|
||||||
PYBIND11_DECLARE_HOLDER_TYPE(T, custom_unique_ptr<T>);
|
PYBIND11_DECLARE_HOLDER_TYPE(T, custom_unique_ptr<T>)
|
||||||
PYBIND11_DECLARE_HOLDER_TYPE(T, shared_ptr_with_addressof_operator<T>);
|
PYBIND11_DECLARE_HOLDER_TYPE(T, shared_ptr_with_addressof_operator<T>)
|
||||||
PYBIND11_DECLARE_HOLDER_TYPE(T, unique_ptr_with_addressof_operator<T>);
|
PYBIND11_DECLARE_HOLDER_TYPE(T, unique_ptr_with_addressof_operator<T>)
|
||||||
|
|
||||||
TEST_SUBMODULE(smart_ptr, m) {
|
TEST_SUBMODULE(smart_ptr, m) {
|
||||||
// Please do not interleave `struct` and `class` definitions with bindings code,
|
// Please do not interleave `struct` and `class` definitions with bindings code,
|
||||||
|
@ -59,7 +59,7 @@ struct visit_helper<boost::variant> {
|
|||||||
} // namespace PYBIND11_NAMESPACE
|
} // namespace PYBIND11_NAMESPACE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
PYBIND11_MAKE_OPAQUE(std::vector<std::string, std::allocator<std::string>>);
|
PYBIND11_MAKE_OPAQUE(std::vector<std::string, std::allocator<std::string>>)
|
||||||
|
|
||||||
/// Issue #528: templated constructor
|
/// Issue #528: templated constructor
|
||||||
struct TplCtorClass {
|
struct TplCtorClass {
|
||||||
|
@ -145,4 +145,4 @@ TEST_SUBMODULE(tagbased_polymorphic, m) {
|
|||||||
.def(py::init<std::string>())
|
.def(py::init<std::string>())
|
||||||
.def("purr", &Panther::purr);
|
.def("purr", &Panther::purr);
|
||||||
m.def("create_zoo", &create_zoo);
|
m.def("create_zoo", &create_zoo);
|
||||||
};
|
}
|
||||||
|
@ -589,4 +589,4 @@ void initialize_inherited_virtuals(py::module_ &m) {
|
|||||||
// Fix issue #1454 (crash when acquiring/releasing GIL on another thread in Python 2.7)
|
// Fix issue #1454 (crash when acquiring/releasing GIL on another thread in Python 2.7)
|
||||||
m.def("test_gil", &test_gil);
|
m.def("test_gil", &test_gil);
|
||||||
m.def("test_gil_from_thread", &test_gil_from_thread);
|
m.def("test_gil_from_thread", &test_gil_from_thread);
|
||||||
};
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user