)]}'
{
  "commit": "55105fbeafe4f046414de92a6986f9a56ecfca71",
  "tree": "a2a9b28f36bf5c31e4b586685d1506a30b4214bb",
  "parents": [
    "e955753c1b34c64f39907b8459d6e0d383e1ca12"
  ],
  "author": {
    "name": "Ralf W. Grosse-Kunstleve",
    "email": "rwgk@google.com",
    "time": "Thu Nov 02 08:21:13 2023 -0700"
  },
  "committer": {
    "name": "GitHub",
    "email": "noreply@github.com",
    "time": "Thu Nov 02 08:21:13 2023 -0700"
  },
  "message": "[smart_holder] Bug fix: `std::unique_ptr` deleter needs to be copied. (#4850)\n\n* Store `std::function\u003cvoid (void *)\u003e` del_fun; in `guarded_delete`\r\n\r\n* Specialize the simple common case.\r\n\r\nUsing a `union` is complicated: https://en.cppreference.com/w/cpp/language/union\r\n\r\n\u003e If members of a union are classes with user-defined constructors and destructors, to switch the active member, explicit destructor and placement new are generally needed:\r\n\r\nUsing `std::variant` increases compile-time overhead.\r\n\r\nIt is currently unclear how much these effects matter in practice: optimization left for later.\r\n\r\n* Add one test case (more later).\r\n\r\n* Add `const` to resolve clang-tidy error.\r\n\r\n```\r\n-- The CXX compiler identification is Clang 15.0.7\r\n\r\n/usr/bin/cmake -E __run_co_compile --tidy\u003d\"/usr/bin/clang-tidy;--use-color;--warnings-as-errors\u003d*;--extra-arg-before\u003d--driver-mode\u003dg++\" --source\u003d/__w/pybind11/pybind11/tests/test_class_sh_inheritance.cpp -- /usr/bin/c++ -DPYBIND11_ENABLE_TYPE_CASTER_ODR_GUARD_IF_AVAILABLE -DPYBIND11_TEST_EIGEN -Dpybind11_tests_EXPORTS -I/__w/pybind11/pybind11/include -isystem /usr/include/python3.9 -isystem /__w/pybind11/pybind11/build/_deps/eigen-src -Os -DNDEBUG -fPIC -fvisibility\u003dhidden -Wall -Wextra -Wconversion -Wcast-qual -Wdeprecated -Wundef -Wnon-virtual-dtor -flto\u003dthin -std\u003dc++17 -o CMakeFiles/pybind11_tests.dir/test_class_sh_inheritance.cpp.o -c /__w/pybind11/pybind11/tests/test_class_sh_inheritance.cpp\r\n/__w/pybind11/pybind11/tests/pure_cpp/smart_holder_poc_test.cpp:264:30: error: pointer parameter \u0027raw_ptr\u0027 can be pointer to const [readability-non-const-parameter,-warnings-as-errors]\r\n        new int(19), [](int *raw_ptr) { delete raw_ptr; });\r\n                             ^\r\n                        const\r\n```\r\n\r\n* Introduce `struct custom_deleter` to ensure the deleter is moved as desired (the lambda function only captures a reference, which can become dangling).\r\n\r\n* Resolve helpful clang-tidy errors.\r\n\r\n```\r\n/usr/bin/cmake -E __run_co_compile --tidy\u003d\"/usr/bin/clang-tidy;--use-color;--warnings-as-errors\u003d*;--extra-arg-before\u003d--driver-mode\u003dg++\" --source\u003d/__w/pybind11/pybind11/tests/test_class.cpp -- /usr/bin/c++ -DPYBIND11_ENABLE_TYPE_CASTER_ODR_GUARD_IF_AVAILABLE -DPYBIND11_TEST_EIGEN -Dpybind11_tests_EXPORTS -I/__w/pybind11/pybind11/include -isystem /usr/include/python3.9 -isystem /__w/pybind11/pybind11/build/_deps/eigen-src -Os -DNDEBUG -fPIC -fvisibility\u003dhidden -Wall -Wextra -Wconversion -Wcast-qual -Wdeprecated -Wundef -Wnon-virtual-dtor -flto\u003dthin -std\u003dc++17 -o CMakeFiles/pybind11_tests.dir/test_class.cpp.o -c /__w/pybind11/pybind11/tests/test_class.cpp\r\n/__w/pybind11/pybind11/include/pybind11/detail/smart_holder_poc.h:114:5: error: single-argument constructors must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor,-warnings-as-errors]\r\n    custom_deleter(D \u0026\u0026deleter) : deleter{std::move(deleter)} {}\r\n    ^\r\n    explicit\r\n/__w/pybind11/pybind11/include/pybind11/detail/smart_holder_poc.h:120:76: error: forwarding reference passed to std::move(), which may unexpectedly cause lvalues to be moved; use std::forward() instead [bugprone-move-forwarding-reference,-warnings-as-errors]\r\n    return guarded_delete(std::function\u003cvoid(void *)\u003e(custom_deleter\u003cT, D\u003e(std::move(uqp_del))),\r\n                                                                           ^~~~~~~~~\r\n                                                                           std::forward\u003cD\u003e\r\n```\r\n\r\n* Workaround for gcc 4.8.5, clang 3.6\r\n\r\n* Transfer reduced test here.\r\n\r\nReduced from a PyCLIF use case in the wild by @wangxf123456 (internal change cl/565476030).\r\n\r\n* Add missing include (clangd Include Cleaner)\r\n\r\n* Change `std::move` to `std::forward` as suggested by @iwanders.\r\n\r\n* Add missing includes (clangd Include Cleaner)\r\n\r\n* Use new `PYBIND11_TESTS_PURE_CPP_SMART_HOLDER_POC_TEST_CPP` to exclude `smart_holder::as_unique_ptr` method from production code.\r\n\r\n* Systematically add `PYBIND11_TESTS_PURE_CPP_SMART_HOLDER_POC_TEST_CPP` to mark code that is not used from production code. Add comment to explain.\r\n\r\n* Very simple experiment related to https://github.com/pybind/pybind11/pull/4850#issuecomment-1789780676\r\n\r\nDoes the `PYBIND11_TESTS_PURE_CPP_SMART_HOLDER_POC_TEST_CPP` define have anything to do with it?\r\n\r\n* Revert \"Very simple experiment related to https://github.com/pybind/pybind11/pull/4850#issuecomment-1789780676\"\r\n\r\nThis reverts commit fe59369f408d354edef16e3d40e2f90d9c2a9ba8.",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "e169f2f26b27ba9b2fc0d85c4bab9f089547689b",
      "old_mode": 33188,
      "old_path": "include/pybind11/detail/smart_holder_poc.h",
      "new_id": "0f71586f7efd7062e6cc716c91fafbb33674e3af",
      "new_mode": 33188,
      "new_path": "include/pybind11/detail/smart_holder_poc.h"
    },
    {
      "type": "modify",
      "old_id": "4bdd669ee1fc9a7a5025fc98c6bb19d1a070b69d",
      "old_mode": 33188,
      "old_path": "tests/CMakeLists.txt",
      "new_id": "e8cff2ead5e5c626b93448644a9e6ae79cebf25b",
      "new_mode": 33188,
      "new_path": "tests/CMakeLists.txt"
    },
    {
      "type": "modify",
      "old_id": "b0823552f8fbf5fc4209f2c5084ff54d94b5954f",
      "old_mode": 33188,
      "old_path": "tests/pure_cpp/smart_holder_poc_test.cpp",
      "new_id": "f820b9bf68ace66afeffc032671104ac5f979845",
      "new_mode": 33188,
      "new_path": "tests/pure_cpp/smart_holder_poc_test.cpp"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "070a10e0fbb5ac9b703891857f6ab56d7794232b",
      "new_mode": 33188,
      "new_path": "tests/test_class_sh_unique_ptr_custom_deleter.cpp"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "d9cf1d4508ce8575aef767f3471bd888aba09b0c",
      "new_mode": 33188,
      "new_path": "tests/test_class_sh_unique_ptr_custom_deleter.py"
    }
  ]
}
