Skip to content

Commit 0d21cad

Browse files
committed
fix: allow -Wpedantic in C++20 mode (#5322)
* fix: allow -Wpedantic again Signed-off-by: Henry Schreiner <[email protected]> * tests: ignore pedantic warning for PYBIND11_DECLARE_HOLDER_TYPE Signed-off-by: Henry Schreiner <[email protected]> * tests: try just turning off pedantic for one file Signed-off-by: Henry Schreiner <[email protected]> * tests: only run pedantic in C++20 mode Signed-off-by: Henry Schreiner <[email protected]> * Update tests/local_bindings.h --------- Signed-off-by: Henry Schreiner <[email protected]>
1 parent ff3ca78 commit 0d21cad

13 files changed

+38
-29
lines changed

docs/advanced/cast/stl.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ the declaration
162162

163163
.. code-block:: cpp
164164
165-
PYBIND11_MAKE_OPAQUE(std::vector<int>);
165+
PYBIND11_MAKE_OPAQUE(std::vector<int>)
166166
167167
before any binding code (e.g. invocations to ``class_::def()``, etc.). This
168168
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`:
207207
// Don't forget this
208208
#include <pybind11/stl_bind.h>
209209
210-
PYBIND11_MAKE_OPAQUE(std::vector<int>);
211-
PYBIND11_MAKE_OPAQUE(std::map<std::string, double>);
210+
PYBIND11_MAKE_OPAQUE(std::vector<int>)
211+
PYBIND11_MAKE_OPAQUE(std::map<std::string, double>)
212212
213213
// ...
214214

docs/advanced/smart_ptrs.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ top namespace level before any binding code:
124124

125125
.. code-block:: cpp
126126
127-
PYBIND11_DECLARE_HOLDER_TYPE(T, SmartPtr<T>);
127+
PYBIND11_DECLARE_HOLDER_TYPE(T, SmartPtr<T>)
128128
129129
The first argument of :func:`PYBIND11_DECLARE_HOLDER_TYPE` should be a
130130
placeholder name that is used as a template parameter of the second argument.
@@ -136,7 +136,7 @@ by default. Specify
136136

137137
.. code-block:: cpp
138138
139-
PYBIND11_DECLARE_HOLDER_TYPE(T, SmartPtr<T>, true);
139+
PYBIND11_DECLARE_HOLDER_TYPE(T, SmartPtr<T>, true)
140140
141141
if ``SmartPtr<T>`` can always be initialized from a ``T*`` pointer without the
142142
risk of inconsistencies (such as multiple independent ``SmartPtr`` instances
@@ -154,7 +154,7 @@ specialized:
154154
.. code-block:: cpp
155155
156156
// Always needed for custom holder types
157-
PYBIND11_DECLARE_HOLDER_TYPE(T, SmartPtr<T>);
157+
PYBIND11_DECLARE_HOLDER_TYPE(T, SmartPtr<T>)
158158
159159
// Only needed if the type's `.get()` goes by another name
160160
namespace PYBIND11_NAMESPACE { namespace detail {

include/pybind11/detail/common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,8 @@ PYBIND11_WARNING_POP
479479
}
480480
481481
\endrst */
482+
PYBIND11_WARNING_PUSH
483+
PYBIND11_WARNING_DISABLE_CLANG("-Wgnu-zero-variadic-macro-arguments")
482484
#define PYBIND11_MODULE(name, variable, ...) \
483485
static ::pybind11::module_::module_def PYBIND11_CONCAT(pybind11_module_def_, name) \
484486
PYBIND11_MAYBE_UNUSED; \
@@ -499,6 +501,7 @@ PYBIND11_WARNING_POP
499501
PYBIND11_CATCH_INIT_EXCEPTIONS \
500502
} \
501503
void PYBIND11_CONCAT(pybind11_init_, name)(::pybind11::module_ & (variable))
504+
PYBIND11_WARNING_POP
502505

503506
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
504507

tests/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,9 @@ function(pybind11_enable_warnings target_name)
396396
-Wdeprecated
397397
-Wundef
398398
-Wnon-virtual-dtor)
399+
if(DEFINED CMAKE_CXX_STANDARD AND NOT CMAKE_CXX_STANDARD VERSION_LESS 20)
400+
target_compile_options(${target_name} PRIVATE -Wpedantic)
401+
endif()
399402
endif()
400403

401404
if(PYBIND11_WERROR)

tests/local_bindings.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,21 @@ class LocalSimpleException : public std::exception {
5656
std::string message = "";
5757
};
5858

59-
PYBIND11_MAKE_OPAQUE(LocalVec);
60-
PYBIND11_MAKE_OPAQUE(LocalVec2);
61-
PYBIND11_MAKE_OPAQUE(LocalMap);
62-
PYBIND11_MAKE_OPAQUE(NonLocalVec);
63-
// PYBIND11_MAKE_OPAQUE(NonLocalVec2); // same type as LocalVec2
64-
PYBIND11_MAKE_OPAQUE(NonLocalMap);
65-
PYBIND11_MAKE_OPAQUE(NonLocalMap2);
59+
PYBIND11_MAKE_OPAQUE(LocalVec)
60+
PYBIND11_MAKE_OPAQUE(LocalVec2)
61+
PYBIND11_MAKE_OPAQUE(LocalMap)
62+
PYBIND11_MAKE_OPAQUE(NonLocalVec)
63+
// PYBIND11_MAKE_OPAQUE(NonLocalVec2) // same type as LocalVec2
64+
PYBIND11_MAKE_OPAQUE(NonLocalMap)
65+
PYBIND11_MAKE_OPAQUE(NonLocalMap2)
6666

6767
// Simple bindings (used with the above):
6868
template <typename T, int Adjust = 0, typename... Args>
6969
py::class_<T> bind_local(Args &&...args) {
7070
return py::class_<T>(std::forward<Args>(args)...).def(py::init<int>()).def("get", [](T &i) {
7171
return i.i + Adjust;
7272
});
73-
};
73+
}
7474

7575
// Simulate a foreign library base class (to match the example in the docs):
7676
namespace pets {

tests/test_callbacks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ TEST_SUBMODULE(callbacks, m) {
148148
m.def("dummy_function2", [](int i, int j) { return i + j; });
149149
m.def(
150150
"roundtrip",
151-
[](std::function<int(int)> f, bool expect_none = false) {
151+
[](std::function<int(int)> f, bool expect_none) {
152152
if (expect_none && f) {
153153
throw std::runtime_error("Expected None to be converted to empty std::function");
154154
}

tests/test_eigen_matrix.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void reset_refs() {
5555
}
5656

5757
// Returns element 2,1 from a matrix (used to test copy/nocopy)
58-
double get_elem(const Eigen::Ref<const Eigen::MatrixXd> &m) { return m(2, 1); };
58+
double get_elem(const Eigen::Ref<const Eigen::MatrixXd> &m) { return m(2, 1); }
5959

6060
// Returns a matrix with 10*r + 100*c added to each matrix element (to help test that the matrix
6161
// reference is referencing rows/columns correctly).
@@ -76,7 +76,7 @@ struct CustomOperatorNew {
7676
Eigen::Matrix4d a = Eigen::Matrix4d::Zero();
7777
Eigen::Matrix4d b = Eigen::Matrix4d::Identity();
7878

79-
EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
79+
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
8080
};
8181

8282
TEST_SUBMODULE(eigen_matrix, m) {

tests/test_opaque_types.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
// This also deliberately doesn't use the below StringList type alias to test
1919
// that MAKE_OPAQUE can handle a type containing a `,`. (The `std::allocator`
2020
// bit is just the default `std::vector` allocator).
21-
PYBIND11_MAKE_OPAQUE(std::vector<std::string, std::allocator<std::string>>);
21+
PYBIND11_MAKE_OPAQUE(std::vector<std::string, std::allocator<std::string>>)
2222

2323
using StringList = std::vector<std::string, std::allocator<std::string>>;
2424

tests/test_sequences_and_iterators.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ class NonCopyableInt {
8686
};
8787
using NonCopyableIntPair = std::pair<NonCopyableInt, NonCopyableInt>;
8888

89-
PYBIND11_MAKE_OPAQUE(std::vector<NonCopyableInt>);
90-
PYBIND11_MAKE_OPAQUE(std::vector<NonCopyableIntPair>);
89+
PYBIND11_MAKE_OPAQUE(std::vector<NonCopyableInt>)
90+
PYBIND11_MAKE_OPAQUE(std::vector<NonCopyableIntPair>)
9191

9292
template <typename PythonType>
9393
py::list test_random_access_iterator(PythonType x) {

tests/test_smart_ptr.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#include "object.h"
1212
#include "pybind11_tests.h"
1313

14+
// This breaks on PYBIND11_DECLARE_HOLDER_TYPE
15+
PYBIND11_WARNING_DISABLE_GCC("-Wpedantic")
16+
1417
namespace {
1518

1619
// 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>> {
279282
} // namespace PYBIND11_NAMESPACE
280283

281284
// Make pybind aware of the ref-counted wrapper type (s):
282-
PYBIND11_DECLARE_HOLDER_TYPE(T, ref<T>, true);
285+
PYBIND11_DECLARE_HOLDER_TYPE(T, ref<T>, true)
283286
// The following is not required anymore for std::shared_ptr, but it should compile without error:
284-
PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>);
285-
PYBIND11_DECLARE_HOLDER_TYPE(T, huge_unique_ptr<T>);
286-
PYBIND11_DECLARE_HOLDER_TYPE(T, custom_unique_ptr<T>);
287-
PYBIND11_DECLARE_HOLDER_TYPE(T, shared_ptr_with_addressof_operator<T>);
288-
PYBIND11_DECLARE_HOLDER_TYPE(T, unique_ptr_with_addressof_operator<T>);
287+
PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>)
288+
PYBIND11_DECLARE_HOLDER_TYPE(T, huge_unique_ptr<T>)
289+
PYBIND11_DECLARE_HOLDER_TYPE(T, custom_unique_ptr<T>)
290+
PYBIND11_DECLARE_HOLDER_TYPE(T, shared_ptr_with_addressof_operator<T>)
291+
PYBIND11_DECLARE_HOLDER_TYPE(T, unique_ptr_with_addressof_operator<T>)
289292

290293
TEST_SUBMODULE(smart_ptr, m) {
291294
// Please do not interleave `struct` and `class` definitions with bindings code,

0 commit comments

Comments
 (0)