From 979d75de23a759e134639934a980231acf685448 Mon Sep 17 00:00:00 2001 From: Sergei Izmailov Date: Mon, 10 Jun 2019 22:03:17 +0300 Subject: [PATCH] doc: Add note about casting from `None` to `T*` (#1760) * doc: Add note about casting from `None` to `T*` * doc: reword 'none-to-pointer' note message * doc: mention opaque types in 'none-to-pointer' note message --- docs/advanced/functions.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/advanced/functions.rst b/docs/advanced/functions.rst index 4d28f06d2..3e1a3ff0e 100644 --- a/docs/advanced/functions.rst +++ b/docs/advanced/functions.rst @@ -467,6 +467,15 @@ dog)"``, while attempting to call ``meow(None)`` will raise a ``TypeError``: The default behaviour when the tag is unspecified is to allow ``None``. +.. note:: + + Even when ``.none(true)`` is specified for an argument, ``None`` will be converted to a + ``nullptr`` *only* for custom and :ref:`opaque ` types. Pointers to built-in types + (``double *``, ``int *``, ...) and STL types (``std::vector *``, ...; if ``pybind11/stl.h`` + is included) are copied when converted to C++ (see :doc:`/advanced/cast/overview`) and will + not allow ``None`` as argument. To pass optional argument of these copied types consider + using ``std::optional`` + Overload resolution order =========================