Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change array_caster in pybind11/stl.h to support value types that are not default-constructible. #30034

Merged
merged 15 commits into from
Jan 17, 2024

Commits on May 4, 2023

  1. Reproducer for `error: call to implicitly-deleted default constructor…

    …` triggered by stl.h `array_caster`:
    
    ```
    clang++ -o pybind11/tests/test_stl_no_default_ctor.os -c -std=c++17 -fPIC -fvisibility=hidden -O0 -g -Wall -Wextra -Wconversion -Wcast-qual -Wdeprecated -Wundef -Wnon-virtual-dtor -Wunused-result -Werror -isystem /usr/include/python3.10 -isystem /usr/include/eigen3 -DPYBIND11_STRICT_ASSERTS_CLASS_HOLDER_VS_TYPE_CASTER_MIX -DPYBIND11_ENABLE_TYPE_CASTER_ODR_GUARD_IF_AVAILABLE -DPYBIND11_TEST_BOOST -Ipybind11/include -I/usr/local/google/home/rwgk/forked/pybind11/include -I/usr/local/google/home/rwgk/clone/pybind11/include /usr/local/google/home/rwgk/forked/pybind11/tests/test_stl_no_default_ctor.cpp
    In file included from /usr/local/google/home/rwgk/forked/pybind11/tests/test_stl_no_default_ctor.cpp:1:
    In file included from /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/stl.h:12:
    In file included from /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/pybind11.h:13:
    In file included from /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/detail/class.h:12:
    In file included from /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/attr.h:14:
    In file included from /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/cast.h:18:
    /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/detail/type_caster_odr_guard.h:111:5: error: call to implicitly-deleted default constructor of 'pybind11::detail::type_caster<std::array<pybind11_tests::stl_no_default_ctor::Node, 2>>'
        type_caster_odr_guard() {
        ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/tuple:190:9: note: in instantiation of member function 'pybind11::detail::type_caster_odr_guard<std::array<pybind11_tests::stl_no_default_ctor::Node, 2>, pybind11::detail::type_caster<std::array<pybind11_tests::stl_no_default_ctor::Node, 2>>>::type_caster_odr_guard' requested here
          : _M_head_impl() { }
            ^
    /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/pybind11.h:104:9: note: in instantiation of function template specialization 'pybind11::cpp_function::initialize<(lambda at /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/pybind11.h:1583:29), void, pybind11_tests::stl_no_default_ctor::NodeArray &, const std::array<pybind11_tests::stl_no_default_ctor::Node, 2> &, pybind11::is_method>' requested here
            initialize(
            ^
    /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/pybind11.h:1583:16: note: in instantiation of function template specialization 'pybind11::cpp_function::cpp_function<(lambda at /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/pybind11.h:1583:29), pybind11::is_method, void>' requested here
            return cpp_function([pm](T &c, const D &value) { c.*pm = value; }, is_method(hdl));
                   ^
    /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/pybind11.h:1926:54: note: in instantiation of function template specialization 'pybind11::property_cpp_function<pybind11_tests::stl_no_default_ctor::NodeArray, std::array<pybind11_tests::stl_no_default_ctor::Node, 2>>::write<std::array<pybind11_tests::stl_no_default_ctor::Node, 2> pybind11_tests::stl_no_default_ctor::NodeArray::*, 0>' requested here
                         property_cpp_function<type, D>::write(pm, *this),
                                                         ^
    /usr/local/google/home/rwgk/forked/pybind11/tests/test_stl_no_default_ctor.cpp:32:10: note: in instantiation of function template specialization 'pybind11::class_<pybind11_tests::stl_no_default_ctor::NodeArray>::def_readwrite<pybind11_tests::stl_no_default_ctor::NodeArray, std::array<pybind11_tests::stl_no_default_ctor::Node, 2>>' requested here
            .def_readwrite("arr", &NodeArray::arr);
             ^
    /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/stl.h:288:7: note: default constructor of 'type_caster<std::array<pybind11_tests::stl_no_default_ctor::Node, 2>>' is implicitly deleted because base class 'array_caster<std::array<Node, 2UL>, pybind11_tests::stl_no_default_ctor::Node, false, 2UL>' has a deleted default constructor
        : array_caster<std::array<Type, Size>, Type, false, Size> {};
          ^
    /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/stl.h:278:5: note: default constructor of 'array_caster<std::array<pybind11_tests::stl_no_default_ctor::Node, 2>, pybind11_tests::stl_no_default_ctor::Node, false, 2>' is implicitly deleted because field 'value' has a deleted default constructor
        PYBIND11_TYPE_CASTER_RVPP(ArrayType,
        ^
    /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/cast.h:262:5: note: expanded from macro 'PYBIND11_TYPE_CASTER_RVPP'
        PYBIND11_TYPE_CASTER_IMPL(type, py_name, ::pybind11::return_value_policy_pack)
        ^
    /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/cast.h:232:10: note: expanded from macro 'PYBIND11_TYPE_CASTER_IMPL'
        type value;                                                                                   \
             ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/array:115:56: note: default constructor of 'array<pybind11_tests::stl_no_default_ctor::Node, 2>' is implicitly deleted because field '_M_elems' has no default constructor
          typename _AT_Type::_Type                         _M_elems;
                                                           ^
    1 error generated.
    ```
    Ralf W. Grosse-Kunstleve committed May 4, 2023
    Configuration menu
    Copy the full SHA
    827e167 View commit details
    Browse the repository at this point in the history

Commits on Jan 10, 2024

  1. Merge branch 'google_pywrapcc_main' into stl_h_no_default_ctor_pywrapcc

    Ralf W. Grosse-Kunstleve committed Jan 10, 2024
    Configuration menu
    Copy the full SHA
    85a6077 View commit details
    Browse the repository at this point in the history
  2. Expand PYBIND11_TYPE_CASTER_RVPP macro.

    Ralf W. Grosse-Kunstleve committed Jan 10, 2024
    Configuration menu
    Copy the full SHA
    cca21ee View commit details
    Browse the repository at this point in the history
  3. Resolve clang-tidy and clang <= 5 errors.

    Ralf W. Grosse-Kunstleve committed Jan 10, 2024
    Configuration menu
    Copy the full SHA
    3d61895 View commit details
    Browse the repository at this point in the history
  4. Second try: Resolve clang-tidy and clang <= 5 errors.

    Ralf W. Grosse-Kunstleve committed Jan 10, 2024
    Configuration menu
    Copy the full SHA
    aa82e3a View commit details
    Browse the repository at this point in the history

Commits on Jan 12, 2024

  1. First working version of array_caster that works for types without …

    …a default constructor.
    Ralf W. Grosse-Kunstleve committed Jan 12, 2024
    Configuration menu
    Copy the full SHA
    e26769a View commit details
    Browse the repository at this point in the history
  2. Try () instead of {} to see if that resolves clang 3.6 and gcc 4.…

    …8.5 compilation errors.
    Ralf W. Grosse-Kunstleve committed Jan 12, 2024
    Configuration menu
    Copy the full SHA
    080fa2b View commit details
    Browse the repository at this point in the history
  3. Add minor comment.

    Ralf W. Grosse-Kunstleve committed Jan 12, 2024
    Configuration menu
    Copy the full SHA
    6dd0c70 View commit details
    Browse the repository at this point in the history
  4. Avoid temp storage if Resizable is true.

    Ralf W. Grosse-Kunstleve committed Jan 12, 2024
    Configuration menu
    Copy the full SHA
    cb0021c View commit details
    Browse the repository at this point in the history
  5. Merge test_stl_no_default_ctor into test_stl

    Ralf W. Grosse-Kunstleve committed Jan 12, 2024
    Configuration menu
    Copy the full SHA
    d2e1222 View commit details
    Browse the repository at this point in the history
  6. Minor move of code blocks (no functional change).

    Ralf W. Grosse-Kunstleve committed Jan 12, 2024
    Configuration menu
    Copy the full SHA
    3f14ae3 View commit details
    Browse the repository at this point in the history
  7. Remove unused default value.

    Ralf W. Grosse-Kunstleve committed Jan 12, 2024
    Configuration menu
    Copy the full SHA
    64dcab7 View commit details
    Browse the repository at this point in the history

Commits on Jan 15, 2024

  1. IncludeCleaner (IWYU) fixes

    Ralf W. Grosse-Kunstleve committed Jan 15, 2024
    Configuration menu
    Copy the full SHA
    f90342a View commit details
    Browse the repository at this point in the history

Commits on Jan 16, 2024

  1. Add two comments: preserving existing behavior

    Ralf W. Grosse-Kunstleve committed Jan 16, 2024
    Configuration menu
    Copy the full SHA
    8486c9e View commit details
    Browse the repository at this point in the history

Commits on Jan 17, 2024

  1. Merge branch 'google_pywrapcc_main' into stl_h_no_default_ctor_pywrapcc

    Ralf W. Grosse-Kunstleve committed Jan 17, 2024
    Configuration menu
    Copy the full SHA
    7c45242 View commit details
    Browse the repository at this point in the history