From 91b42c81745e8a918f80167f5cd9c40ff8eb8a39 Mon Sep 17 00:00:00 2001 From: Dean Moldovan Date: Sat, 2 Sep 2017 14:46:32 +0200 Subject: [PATCH] Add upgrade guide entry about stricter compile-time checks Closes #1048, closes #1052. [skip ci] --- docs/upgrade.rst | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docs/upgrade.rst b/docs/upgrade.rst index 5ad7c2981..3f5697391 100644 --- a/docs/upgrade.rst +++ b/docs/upgrade.rst @@ -225,6 +225,33 @@ should be used directly instead: ``borrowed_t{}`` and ``stolen_t{}`` (`#771 `_). +Stricter compile-time error checking +------------------------------------ + +Some error checks have been moved from run time to compile time. Notably, +automatic conversion of ``std::shared_ptr`` is not possible when ``T`` is +not directly registered with ``py::class_`` (e.g. ``std::shared_ptr`` +or ``std::shared_ptr>`` are not automatically convertible). +Attempting to bind a function with such arguments now results in a compile-time +error instead of waiting to fail at run time. + +``py::init<...>()`` constructor definitions are also stricter and now prevent +bindings which could cause unexpected behavior: + +.. code-block:: cpp + + struct Example { + Example(int &); + }; + + py::class_(m, "Example") + .def(py::init()); // OK, exact match + // .def(py::init()); // compile-time error, mismatch + +A non-``const`` lvalue reference is not allowed to bind to an rvalue. However, +note that a constructor taking ``const T &`` can still be registered using +``py::init()`` because a ``const`` lvalue reference can bind to an rvalue. + v2.1 ====