File tree 1 file changed +27
-0
lines changed 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -225,6 +225,33 @@ should be used directly instead: ``borrowed_t{}`` and ``stolen_t{}``
225
225
(`#771 <https://github.com/pybind/pybind11/pull/771 >`_).
226
226
227
227
228
+ Stricter compile-time error checking
229
+ ------------------------------------
230
+
231
+ Some error checks have been moved from run time to compile time. Notably,
232
+ automatic conversion of ``std::shared_ptr<T> `` is not possible when ``T `` is
233
+ not directly registered with ``py::class_<T> `` (e.g. ``std::shared_ptr<int> ``
234
+ or ``std::shared_ptr<std::vector<T>> `` are not automatically convertible).
235
+ Attempting to bind a function with such arguments now results in a compile-time
236
+ error instead of waiting to fail at run time.
237
+
238
+ ``py::init<...>() `` constructor definitions are also stricter and now prevent
239
+ bindings which could cause unexpected behavior:
240
+
241
+ .. code-block :: cpp
242
+
243
+ struct Example {
244
+ Example(int &);
245
+ };
246
+
247
+ py::class_<Example>(m, "Example")
248
+ .def(py::init<int &>()); // OK, exact match
249
+ // .def(py::init<int>()); // compile-time error, mismatch
250
+
251
+ A non-``const `` lvalue reference is not allowed to bind to an rvalue. However,
252
+ note that a constructor taking ``const T & `` can still be registered using
253
+ ``py::init<T>() `` because a ``const `` lvalue reference can bind to an rvalue.
254
+
228
255
v2.1
229
256
====
230
257
You can’t perform that action at this time.
0 commit comments