Skip to content

Don't allow keep_alive or call_guard on properties #5533

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/pybind11/attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,12 @@ struct process_attributes {
}
};

template <typename T>
struct is_keep_alive : std::false_type {};

template <size_t Nurse, size_t Patient>
struct is_keep_alive<keep_alive<Nurse, Patient>> : std::true_type {};

template <typename T>
using is_call_guard = is_instantiation<call_guard, T>;

Expand Down
6 changes: 6 additions & 0 deletions include/pybind11/pybind11.h
Original file line number Diff line number Diff line change
Expand Up @@ -1849,6 +1849,12 @@ class class_ : public detail::generic_type {
const Extra &...extra) {
static_assert(0 == detail::constexpr_sum(std::is_base_of<arg, Extra>::value...),
"Argument annotations are not allowed for properties");
static_assert(0 == detail::constexpr_sum(detail::is_call_guard<Extra>::value...),
"def_property family does not currently support call_guard. Use a "
"py::cpp_function instead.");
static_assert(0 == detail::constexpr_sum(detail::is_keep_alive<Extra>::value...),
"def_property family does not currently support keep_alive. Use a "
"py::cpp_function instead.");
auto rec_fget = get_function_record(fget), rec_fset = get_function_record(fset);
auto *rec_active = rec_fget;
if (rec_fget) {
Expand Down
Loading